{"id":2791,"date":"2013-10-05T15:22:52","date_gmt":"2013-10-05T14:22:52","guid":{"rendered":"http:\/\/t-machine.org\/?p=2791"},"modified":"2013-10-06T10:02:39","modified_gmt":"2013-10-06T09:02:39","slug":"why-is-a-fragment-shader-named-a-fragment-shader","status":"publish","type":"post","link":"http:\/\/new.t-machine.org\/index.php\/2013\/10\/05\/why-is-a-fragment-shader-named-a-fragment-shader\/","title":{"rendered":"Why is a Fragment Shader named a Fragment Shader?"},"content":{"rendered":"<p>I&#8217;m writing <a href=\"http:\/\/t-machine.org\/index.php\/2013\/08\/29\/glkit-to-the-max-opengl-es-2-0-for-ios-part-1-features\/\">some KISS tutorials on using OpenGL ES 2.0 in iOS\/mobile<\/a>, because I was frustrated that most of the tutorials on GL ES used incorrect or outdated approaches.<\/p>\n<p>(I&#8217;m using the OpenGL ES 2.0 Programming Guide as my baseline, along with my own experiences of game-programming, and checking it all against Khronos Group \/ OpenGL.org&#8217;s docs as I go)<\/p>\n<p>I use this stuff in iOS apps, but &#8230; I&#8217;m a relative novice with shader-pipelines. So I&#8217;ve been leaning on the guys at <a href=\"http:\/\/thechaosengine.com\">The Chaos Engine<\/a> for proofreading and to help me avoid spreading misinformation. Most stuff people broadly agree on, but there&#8217;s been some interesting debate over a seemingly trivial question:<\/p>\n<blockquote><p>\nWhy does OpenGL use the term &#8220;Fragment Shaders&#8221; to describe the shaders-that-generate-pixels? (where other API&#8217;s call the same thing &#8220;Pixel Shaders&#8221;, a much easier to understand\/remember name)\n<\/p><\/blockquote>\n<p><!--more--><br \/>\nTo try and answer this, I hit up a couple of go-to resources:<\/p>\n<ol>\n<li>Google &#8220;define Fragment Shader&#8221; (some Wikipedia hits, but they dodge the central question, and say &#8220;it&#8217;s the same as a Pixel Shader&#8221;)\n<li>My copy of <a href=\"http:\/\/www.amazon.com\/OpenGL-ES-2-0-Programming-Guide\/dp\/0321502795\/ref=sr_1_1?ie=UTF8&#038;s=books&#038;qid=1205015713&#038;sr=8-1\">&#8220;OpenGL ES 2.0 Programming Guide&#8221;<\/a> (one of the authors was an editor of the GL ES 2.0 Specification)\n<li>Khronos Group&#8217;s official OpenGL.org website, and it&#8217;s wiki (although the wiki is often wrong or misleading, sadly)\n<\/ol>\n<h2>Current theories<\/h2>\n<h3>Theory1: Original idea was to generate small &#8220;bits&#8221; of shader (or: &#8220;fragments&#8221;) and chain them together<\/h3>\n<p>Reference: (private posts on TCE)<\/p>\n<h3>Theory2: When you use sub-pixel rendering techniques, a Fragment Shader is run multiple times per-pixel (it&#8217;s run once per-sub-pixel), so PixelShader is a misleading name<\/h3>\n<p>Reference: (private posts on TCE)<\/p>\n<h3>Theory3: A Fragment is &#8220;the potential to create a Pixel&#8221;. Multiple Fragments come together (one from each 3D object that overlaps a pixel) to create a final value of a Pixel<\/h3>\n<p>Reference: <a href=\"http:\/\/http.developer.nvidia.com\/CgTutorial\/cg_tutorial_chapter01.html\">http:\/\/http.developer.nvidia.com\/CgTutorial\/cg_tutorial_chapter01.html<\/a><\/p>\n<blockquote><p>\n&#8220;A pixel represents the contents of the frame buffer at a specific location, such as the color, depth, and any other values associated with that location. A fragment is the state required potentially to update a particular pixel.\n<\/p><\/blockquote>\n<p>I&#8217;d not used this one before, but after writing the articles, it&#8217;s my current favourite. A &#8220;vertex&#8221; in OpenGL is <strong>definitely not<\/strong> a point-in-3D &#8211; it&#8217;s simply\u00a0a collection of metadata, one part of which might be (but doesn&#8217;t have to be!) a 3D position.<\/p>\n<p>Likewise, it makes sense that a &#8220;fragment&#8221; in OpenGL is <strong>definitely not<\/strong> a pixel-on-screen &#8211; it&#8217;s simply a collection of <strong>possibly incomplete<\/strong> metadata about the pixel we intend to (eventually) draw.<\/p>\n<h2>Any more?<\/h2>\n<p>Anyone else got a better explanation? An official definition? Or even &#8230; an unofficial one, but sourced with a link where someone from 3DFX \/ OpenGL \/ Khronos explains it in their own words? <\/p>\n","protected":false},"excerpt":{"rendered":"<p>I&#8217;m writing some KISS tutorials on using OpenGL ES 2.0 in iOS\/mobile, because I was frustrated that most of the tutorials on GL ES used incorrect or outdated approaches. (I&#8217;m using the OpenGL ES 2.0 Programming Guide as my baseline, along with my own experiences of game-programming, and checking it all against Khronos Group \/ [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[51,20],"tags":[],"_links":{"self":[{"href":"http:\/\/new.t-machine.org\/index.php\/wp-json\/wp\/v2\/posts\/2791"}],"collection":[{"href":"http:\/\/new.t-machine.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/new.t-machine.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/new.t-machine.org\/index.php\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"http:\/\/new.t-machine.org\/index.php\/wp-json\/wp\/v2\/comments?post=2791"}],"version-history":[{"count":4,"href":"http:\/\/new.t-machine.org\/index.php\/wp-json\/wp\/v2\/posts\/2791\/revisions"}],"predecessor-version":[{"id":2826,"href":"http:\/\/new.t-machine.org\/index.php\/wp-json\/wp\/v2\/posts\/2791\/revisions\/2826"}],"wp:attachment":[{"href":"http:\/\/new.t-machine.org\/index.php\/wp-json\/wp\/v2\/media?parent=2791"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/new.t-machine.org\/index.php\/wp-json\/wp\/v2\/categories?post=2791"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/new.t-machine.org\/index.php\/wp-json\/wp\/v2\/tags?post=2791"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}