<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: 5. GLSL Per Pixel Lighting</title>
	<atom:link href="http://www.swiftless.com/tutorials/glsl/5_lighting_perpixel.html/feed" rel="self" type="application/rss+xml" />
	<link>http://www.swiftless.com/tutorials/glsl/5_lighting_perpixel.html</link>
	<description>Game Programming and Computer Graphics Tutorials</description>
	<lastBuildDate>Wed, 01 Feb 2012 09:19:36 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
	<item>
		<title>By: Nick</title>
		<link>http://www.swiftless.com/tutorials/glsl/5_lighting_perpixel.html/comment-page-1#comment-2923</link>
		<dc:creator>Nick</dc:creator>
		<pubDate>Wed, 09 Nov 2011 23:34:18 +0000</pubDate>
		<guid isPermaLink="false">http://swiftless.com/wordpress/?p=228#comment-2923</guid>
		<description>I can&#039;t figure out how to add specular light to the pixel shader.
When I do, it comes out per-vertex, not per-pixel...</description>
		<content:encoded><![CDATA[<p>I can&#8217;t figure out how to add specular light to the pixel shader.<br />
When I do, it comes out per-vertex, not per-pixel&#8230;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: DUdeson</title>
		<link>http://www.swiftless.com/tutorials/glsl/5_lighting_perpixel.html/comment-page-1#comment-2610</link>
		<dc:creator>DUdeson</dc:creator>
		<pubDate>Tue, 25 Oct 2011 20:03:41 +0000</pubDate>
		<guid isPermaLink="false">http://swiftless.com/wordpress/?p=228#comment-2610</guid>
		<description>Wtf?!
Using the light position is like 10x easier than the direction!!!!</description>
		<content:encoded><![CDATA[<p>Wtf?!<br />
Using the light position is like 10x easier than the direction!!!!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Swiftless</title>
		<link>http://www.swiftless.com/tutorials/glsl/5_lighting_perpixel.html/comment-page-1#comment-1671</link>
		<dc:creator>Swiftless</dc:creator>
		<pubDate>Fri, 20 May 2011 02:30:51 +0000</pubDate>
		<guid isPermaLink="false">http://swiftless.com/wordpress/?p=228#comment-1671</guid>
		<description>Hi Paras,

If you would like to do something like that, the vertex shader allows you to read the z-values of vertices. You can then set up a variable which is sent from the vertex shader to the fragment shader, and the fragment shader can use this variable to decide on whether or not to change the colour of the current pixels.

It might be important to note that pixel values are interpolated between vertices. So if one vertex has a z-value of -10 and we tell the pixels for that vertex to be red, and the next vertex has a z-value of -20 (both for the same geometry), and we tell the pixels for that vertex to be green, then we will see a smoothing between red and green.

While we have full control over our pixels, we can&#039;t access them straight on an x,y basis and say, I want this pixel at this location, to be this. The pixel shader is applied to geometry, and the pixels created by the geometry are what are manipulated.

Cheers,
Swiftless</description>
		<content:encoded><![CDATA[<p>Hi Paras,</p>
<p>If you would like to do something like that, the vertex shader allows you to read the z-values of vertices. You can then set up a variable which is sent from the vertex shader to the fragment shader, and the fragment shader can use this variable to decide on whether or not to change the colour of the current pixels.</p>
<p>It might be important to note that pixel values are interpolated between vertices. So if one vertex has a z-value of -10 and we tell the pixels for that vertex to be red, and the next vertex has a z-value of -20 (both for the same geometry), and we tell the pixels for that vertex to be green, then we will see a smoothing between red and green.</p>
<p>While we have full control over our pixels, we can&#8217;t access them straight on an x,y basis and say, I want this pixel at this location, to be this. The pixel shader is applied to geometry, and the pixels created by the geometry are what are manipulated.</p>
<p>Cheers,<br />
Swiftless</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Paras</title>
		<link>http://www.swiftless.com/tutorials/glsl/5_lighting_perpixel.html/comment-page-1#comment-1659</link>
		<dc:creator>Paras</dc:creator>
		<pubDate>Thu, 19 May 2011 11:33:34 +0000</pubDate>
		<guid isPermaLink="false">http://swiftless.com/wordpress/?p=228#comment-1659</guid>
		<description>Might be this is a real noob question,

I have followed the 5 GLSL tutes uptill now, but I am unable to understand that, how have we achieved per pixel/ vertex effects, I mean we have called our shader program inside the &#039;display&#039; function and this will update per frame. Thus the code in shader program will affect each and every pixel/vertex in same way. How have we achieved control on each vertex/pixel? 
How can we in same run, say change color of few pixels to red and few white depending on their z values?</description>
		<content:encoded><![CDATA[<p>Might be this is a real noob question,</p>
<p>I have followed the 5 GLSL tutes uptill now, but I am unable to understand that, how have we achieved per pixel/ vertex effects, I mean we have called our shader program inside the &#8216;display&#8217; function and this will update per frame. Thus the code in shader program will affect each and every pixel/vertex in same way. How have we achieved control on each vertex/pixel?<br />
How can we in same run, say change color of few pixels to red and few white depending on their z values?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Swiftless</title>
		<link>http://www.swiftless.com/tutorials/glsl/5_lighting_perpixel.html/comment-page-1#comment-1554</link>
		<dc:creator>Swiftless</dc:creator>
		<pubDate>Sun, 06 Mar 2011 03:11:43 +0000</pubDate>
		<guid isPermaLink="false">http://swiftless.com/wordpress/?p=228#comment-1554</guid>
		<description>Hi Alfonse, 

I see what you mean, but I stick by my position it call it position to keep the transition simple from the fixed function mode. But I should explain this better when I do a rewrite of the tutorial eventually. I&#039;m pretty sure I explain it on the OpenGL Tips page, but that is a bit of a round-about trip. Also, it&#039;s not the fact that it&#039;s dotted and normalized that makes it a direction. You do the same calculations for a position light (It shoots out in all directions). It&#039;s just a minor change in the rest of your code to switch from positional to directional in appearance.

I&#039;m not sure you understand what I meant in regard to the number of variable fetches.

&quot;As for varying variables, it is not always optimal to do all your lighting calculations in the fragment shader this lets us offload some parts to the vertex shader.&quot;

For example, you do the dot product calculation. If you do it per-vertex, you may have 1000 vertices and this means 1000 dot product calculations, as opposed to possibly 1000x1000 calculations if you do it on a per-pixel basis. Yes, there is a difference in quality, this is per-vertex lighting compared to per-pixel lighting, but it&#039;s a valid example of the speed difference. 

&quot;This also saves us reading the variable every pixel from OpenGL, we can read it per vertex which can save quite a few fetches. &quot;

Take bump mapping vs displacement mapping. Either way you have a texture read. But in the vertex shader, you only have one texture fetch per vertex, as opposed to a texture fetch every pixel.

These examples are more on the extreme differences side, but it shows the point I am trying to make clearly.

Just a note on what you mentioned. Uniforms vs Varyings in regard to speed. Uniforms are passed from system memory to GPU memory, this has a MUCH higher cost associated with it compared to a varying variable which is created on the GPU and requires no passing around in memory.

I&#039;d like to know where the information is coming from that the more varying variables you have, the less vertices you can have. Vertex output relies on the hardware capability, not the amount of varying variables you have. Imagine the kind of trouble geometry shaders and tesselation engines would run into if that was the case, where you can effectively output several times the number of incoming vertices.

Cheers,
Swiftless</description>
		<content:encoded><![CDATA[<p>Hi Alfonse, </p>
<p>I see what you mean, but I stick by my position it call it position to keep the transition simple from the fixed function mode. But I should explain this better when I do a rewrite of the tutorial eventually. I&#8217;m pretty sure I explain it on the OpenGL Tips page, but that is a bit of a round-about trip. Also, it&#8217;s not the fact that it&#8217;s dotted and normalized that makes it a direction. You do the same calculations for a position light (It shoots out in all directions). It&#8217;s just a minor change in the rest of your code to switch from positional to directional in appearance.</p>
<p>I&#8217;m not sure you understand what I meant in regard to the number of variable fetches.</p>
<p>&#8220;As for varying variables, it is not always optimal to do all your lighting calculations in the fragment shader this lets us offload some parts to the vertex shader.&#8221;</p>
<p>For example, you do the dot product calculation. If you do it per-vertex, you may have 1000 vertices and this means 1000 dot product calculations, as opposed to possibly 1000&#215;1000 calculations if you do it on a per-pixel basis. Yes, there is a difference in quality, this is per-vertex lighting compared to per-pixel lighting, but it&#8217;s a valid example of the speed difference. </p>
<p>&#8220;This also saves us reading the variable every pixel from OpenGL, we can read it per vertex which can save quite a few fetches. &#8221;</p>
<p>Take bump mapping vs displacement mapping. Either way you have a texture read. But in the vertex shader, you only have one texture fetch per vertex, as opposed to a texture fetch every pixel.</p>
<p>These examples are more on the extreme differences side, but it shows the point I am trying to make clearly.</p>
<p>Just a note on what you mentioned. Uniforms vs Varyings in regard to speed. Uniforms are passed from system memory to GPU memory, this has a MUCH higher cost associated with it compared to a varying variable which is created on the GPU and requires no passing around in memory.</p>
<p>I&#8217;d like to know where the information is coming from that the more varying variables you have, the less vertices you can have. Vertex output relies on the hardware capability, not the amount of varying variables you have. Imagine the kind of trouble geometry shaders and tesselation engines would run into if that was the case, where you can effectively output several times the number of incoming vertices.</p>
<p>Cheers,<br />
Swiftless</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Alfonse</title>
		<link>http://www.swiftless.com/tutorials/glsl/5_lighting_perpixel.html/comment-page-1#comment-1553</link>
		<dc:creator>Alfonse</dc:creator>
		<pubDate>Sat, 05 Mar 2011 05:01:15 +0000</pubDate>
		<guid isPermaLink="false">http://swiftless.com/wordpress/?p=228#comment-1553</guid>
		<description>Yes, OpenGL&#039;s default lighting variables do call it a &quot;position&quot; even for directional lights. But that doesn&#039;t mean that you need to do so. This is, after all, a tutorial; a way to make things clearer to the user. Treating a position like a direction does not help make things clearer.

As for the cost of reading uniforms in a fragment shader, that simply doesn&#039;t exist. Reading uniforms costs just as much as reading varyings.

Also, passing varyings has a very real cost associated with it. It makes the per-output vertex data bigger, which means that per-output vertex data takes up more room in the post-T&amp;L cache. Which means you can have fewer vertices in the post T&amp;L cache. Which slows things down.

The cost of reading a uniform doesn&#039;t compare to the cost of an additional varying.</description>
		<content:encoded><![CDATA[<p>Yes, OpenGL&#8217;s default lighting variables do call it a &#8220;position&#8221; even for directional lights. But that doesn&#8217;t mean that you need to do so. This is, after all, a tutorial; a way to make things clearer to the user. Treating a position like a direction does not help make things clearer.</p>
<p>As for the cost of reading uniforms in a fragment shader, that simply doesn&#8217;t exist. Reading uniforms costs just as much as reading varyings.</p>
<p>Also, passing varyings has a very real cost associated with it. It makes the per-output vertex data bigger, which means that per-output vertex data takes up more room in the post-T&amp;L cache. Which means you can have fewer vertices in the post T&amp;L cache. Which slows things down.</p>
<p>The cost of reading a uniform doesn&#8217;t compare to the cost of an additional varying.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Swiftless</title>
		<link>http://www.swiftless.com/tutorials/glsl/5_lighting_perpixel.html/comment-page-1#comment-1064</link>
		<dc:creator>Swiftless</dc:creator>
		<pubDate>Sun, 05 Dec 2010 23:16:57 +0000</pubDate>
		<guid isPermaLink="false">http://swiftless.com/wordpress/?p=228#comment-1064</guid>
		<description>Hey Alfonse,

While your comments have a point, I call it vertex_light_position because OpenGL refers to it as light position. Also, it depends on the type of light, if you have a point light, it has a position and no direction while a directional light is opposite and has a direction but no position. 

As for varying variables, it is not always optimal to do all your lighting calculations in the fragment shader this lets us offload some parts to the vertex shader. This also saves us reading the variable every pixel from OpenGL, we can read it per vertex which can save quite a few fetches. 

Thanks,
Swiftless</description>
		<content:encoded><![CDATA[<p>Hey Alfonse,</p>
<p>While your comments have a point, I call it vertex_light_position because OpenGL refers to it as light position. Also, it depends on the type of light, if you have a point light, it has a position and no direction while a directional light is opposite and has a direction but no position. </p>
<p>As for varying variables, it is not always optimal to do all your lighting calculations in the fragment shader this lets us offload some parts to the vertex shader. This also saves us reading the variable every pixel from OpenGL, we can read it per vertex which can save quite a few fetches. </p>
<p>Thanks,<br />
Swiftless</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Alfonse</title>
		<link>http://www.swiftless.com/tutorials/glsl/5_lighting_perpixel.html/comment-page-1#comment-1059</link>
		<dc:creator>Alfonse</dc:creator>
		<pubDate>Sun, 28 Nov 2010 19:09:16 +0000</pubDate>
		<guid isPermaLink="false">http://swiftless.com/wordpress/?p=228#comment-1059</guid>
		<description>Why do you call it &quot;vertex_light_position&quot;, when it is very clearly a light *direction*? You normalize it, you dot it with the surface normal. It&#039;s a direction, not a position.

Also, there&#039;s no reason to pass it as a varying, since it doesn&#039;t change. It&#039;s just the light direction accessed from the OpenGL variables. Which the fragment shader can access just as well as the vertex shader.</description>
		<content:encoded><![CDATA[<p>Why do you call it &#8220;vertex_light_position&#8221;, when it is very clearly a light *direction*? You normalize it, you dot it with the surface normal. It&#8217;s a direction, not a position.</p>
<p>Also, there&#8217;s no reason to pass it as a varying, since it doesn&#8217;t change. It&#8217;s just the light direction accessed from the OpenGL variables. Which the fragment shader can access just as well as the vertex shader.</p>
]]></content:encoded>
	</item>
</channel>
</rss>

