<story><title>Primer: Shaders</title><url>http://notes.underscorediscovery.com/shaders-a-primer/</url></story><parent_chain><item><author>sillysaurus3</author><text>Part of the confusion is the confusing terminology.  &amp;quot;Shader&amp;quot; is a bad name.  How do you &amp;quot;shade&amp;quot; a vertex? That implies color, when in fact vertex &amp;quot;shading&amp;quot; is really about deforming the position of vertices.  It has nothing to do with color!&lt;p&gt;&amp;quot;Vertex program&amp;quot; is a better term.&lt;p&gt;That brings us to &amp;quot;pixel shader.&amp;quot;  That&amp;#x27;s actually a good name in order for beginners to learn the concept, but it&amp;#x27;s imprecise.  OpenGL insists on calling it a &amp;quot;fragment program&amp;quot; because with certain forms of antialiasing, there are multiple &amp;quot;fragments&amp;quot; per pixel.  &amp;quot;Program&amp;quot; is also a better name than &amp;quot;shader&amp;quot; because there are things you can do per-pixel other than change the color.  For example you could change the depth written to the Z-buffer, or you could cause the pixel to be skipped based on some criteria, like whether the texture color is pink.&lt;p&gt;Anyway, it&amp;#x27;s just a tiny program that executes either per-vertex or per-pixel.  For example you could write a vertex program which moves each vertex in a sinewave pattern based on time.  Or you could write a fragment program to change the color of each pixel from red to green and back based on time.&lt;p&gt;Then there are more advanced&amp;#x2F;recent concepts like a &amp;quot;geometry program,&amp;quot; which lets you generate triangles based on vertices or edges.&lt;p&gt;Sometimes I wonder if it&amp;#x27;s overly complicated, or if the problem domain is just complicated.  It took me years as a kid to finally grok this, but once I learned it, it turned out to be very simple.  Honestly it wasn&amp;#x27;t until I got up enough courage to sit down with the OpenGL specs and read through them that everything clicked.  They&amp;#x27;re dry reading but not difficult.</text></item></parent_chain><comment><author>ANTSANTS</author><text>Traditionally, lighting was calculated per vertex, not per pixel, and the results of those calculations were simply interpolated across the surface of the triangle. A &amp;quot;shader&amp;quot; is not the most general term they could have used for a GPU program, but you very well can &amp;quot;shade&amp;quot; a vertex.&lt;p&gt;Edit: Is this seriously being downvoted? &amp;quot;How do you &amp;quot;shade&amp;quot; a vertex? That implies color, when in fact vertex &amp;quot;shading&amp;quot; is really about deforming the position of vertices. It has nothing to do with color!&amp;quot; is factually inaccurate because you can, and many games do, calculate color and lighting information per-vertex.</text></comment>
<story><title>Primer: Shaders</title><url>http://notes.underscorediscovery.com/shaders-a-primer/</url></story><parent_chain><item><author>sillysaurus3</author><text>Part of the confusion is the confusing terminology.  &amp;quot;Shader&amp;quot; is a bad name.  How do you &amp;quot;shade&amp;quot; a vertex? That implies color, when in fact vertex &amp;quot;shading&amp;quot; is really about deforming the position of vertices.  It has nothing to do with color!&lt;p&gt;&amp;quot;Vertex program&amp;quot; is a better term.&lt;p&gt;That brings us to &amp;quot;pixel shader.&amp;quot;  That&amp;#x27;s actually a good name in order for beginners to learn the concept, but it&amp;#x27;s imprecise.  OpenGL insists on calling it a &amp;quot;fragment program&amp;quot; because with certain forms of antialiasing, there are multiple &amp;quot;fragments&amp;quot; per pixel.  &amp;quot;Program&amp;quot; is also a better name than &amp;quot;shader&amp;quot; because there are things you can do per-pixel other than change the color.  For example you could change the depth written to the Z-buffer, or you could cause the pixel to be skipped based on some criteria, like whether the texture color is pink.&lt;p&gt;Anyway, it&amp;#x27;s just a tiny program that executes either per-vertex or per-pixel.  For example you could write a vertex program which moves each vertex in a sinewave pattern based on time.  Or you could write a fragment program to change the color of each pixel from red to green and back based on time.&lt;p&gt;Then there are more advanced&amp;#x2F;recent concepts like a &amp;quot;geometry program,&amp;quot; which lets you generate triangles based on vertices or edges.&lt;p&gt;Sometimes I wonder if it&amp;#x27;s overly complicated, or if the problem domain is just complicated.  It took me years as a kid to finally grok this, but once I learned it, it turned out to be very simple.  Honestly it wasn&amp;#x27;t until I got up enough courage to sit down with the OpenGL specs and read through them that everything clicked.  They&amp;#x27;re dry reading but not difficult.</text></item></parent_chain><comment><author>pyalot2</author><text>The reason it&amp;#x27;s not called vertex program is because the pipeline is defined in terms of stages (vertex -&amp;gt; tessellation control -&amp;gt; tessellation evaluation -&amp;gt; geometry -&amp;gt; rasterizer -&amp;gt; fragment). Together they are a program. When talking about this structure the choice that OpenGL made is:&lt;p&gt;&amp;quot;A shader program consists of a vertex shader (VS), tessellation control shader (TS control), tessellation evaluation shader (TS eval), geometry shader (GS) and fragment shader (FS).&amp;quot;&lt;p&gt;You could instead say this, but it would be confusing:&lt;p&gt;A shader program consists of a vertex program, tessellation control program, tessellation evaluation program, geometry program and fragment program.&lt;p&gt;And it would even get more confusing if you drop the first shader:&lt;p&gt;&amp;quot;A program consists of a vertex program, tessellation control program, tessellation evaluation program, geometry program and fragment program.&amp;quot;&lt;p&gt;So for the sake of it being easy to talk about, a (shader) program is the whole thing, whenever somebody talks about a &amp;quot;program&amp;quot; it&amp;#x27;s the whole assemblage. And when somebody talks about a shader, it means one of the programs tied to a stage.</text></comment>