<?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: Fixed function lighting in vertex shader &#8211; how?</title>
	<atom:link href="http://aras-p.info/blog/2009/01/22/fixed-function-lighting-in-vertex-shader-how/feed/" rel="self" type="application/rss+xml" />
	<link>http://aras-p.info/blog/2009/01/22/fixed-function-lighting-in-vertex-shader-how/</link>
	<description>Random thoughts of a triangle pusher</description>
	<lastBuildDate>Thu, 04 Mar 2010 23:01:48 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: Pat Wilson</title>
		<link>http://aras-p.info/blog/2009/01/22/fixed-function-lighting-in-vertex-shader-how/comment-page-1/#comment-19417</link>
		<dc:creator>Pat Wilson</dc:creator>
		<pubDate>Tue, 09 Jun 2009 17:06:16 +0000</pubDate>
		<guid isPermaLink="false">http://aras-p.info/blog/?p=261#comment-19417</guid>
		<description>Instead of implementing an ubershader, I implemented 3 very simple and small shaders which cover most simple cases: VertexColor, Texture, VertexColorModTexture, VertexColorAddTexture. This covers debug rendering, UI elements, simple particle systems, and such. Everything else must use a proper Material to render, in which case the Material system will take care of generating a shader, or using fixed-function to render the object.

I don&#039;t favor the ubershader-FF approach because, in my opinion, it continues to re-enforce the entire fixed-function concept. Providing developers with a way to interact with a device in a deprecated way (like fixed function) is convenient, but it&#039;s the reason OpenGL&#039;s API is the way it is now.</description>
		<content:encoded><![CDATA[<p>Instead of implementing an ubershader, I implemented 3 very simple and small shaders which cover most simple cases: VertexColor, Texture, VertexColorModTexture, VertexColorAddTexture. This covers debug rendering, UI elements, simple particle systems, and such. Everything else must use a proper Material to render, in which case the Material system will take care of generating a shader, or using fixed-function to render the object.</p>
<p>I don&#8217;t favor the ubershader-FF approach because, in my opinion, it continues to re-enforce the entire fixed-function concept. Providing developers with a way to interact with a device in a deprecated way (like fixed function) is convenient, but it&#8217;s the reason OpenGL&#8217;s API is the way it is now.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Sean Barrett</title>
		<link>http://aras-p.info/blog/2009/01/22/fixed-function-lighting-in-vertex-shader-how/comment-page-1/#comment-16846</link>
		<dc:creator>Sean Barrett</dc:creator>
		<pubDate>Wed, 04 Mar 2009 19:41:05 +0000</pubDate>
		<guid isPermaLink="false">http://aras-p.info/blog/?p=261#comment-16846</guid>
		<description>Aha, makes sense, thanks.</description>
		<content:encoded><![CDATA[<p>Aha, makes sense, thanks.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Aras Pranckevičius</title>
		<link>http://aras-p.info/blog/2009/01/22/fixed-function-lighting-in-vertex-shader-how/comment-page-1/#comment-16845</link>
		<dc:creator>Aras Pranckevičius</dc:creator>
		<pubDate>Wed, 04 Mar 2009 19:19:56 +0000</pubDate>
		<guid isPermaLink="false">http://aras-p.info/blog/?p=261#comment-16845</guid>
		<description>@Sean: HLSL compiler is in D3DX (not in core D3D runtime). Nowadays it&#039;s in a DLL, so that&#039;s 3MB or so (we can&#039;t rely on the right DLL being present on user&#039;s machine, hence we&#039;d need to include D3DX redist in our own installer). Back in the old days (SDKs from 2004), D3DX was a static library, so if you weren&#039;t using HLSL, the linker would strip it out.</description>
		<content:encoded><![CDATA[<p>@Sean: HLSL compiler is in D3DX (not in core D3D runtime). Nowadays it&#8217;s in a DLL, so that&#8217;s 3MB or so (we can&#8217;t rely on the right DLL being present on user&#8217;s machine, hence we&#8217;d need to include D3DX redist in our own installer). Back in the old days (SDKs from 2004), D3DX was a static library, so if you weren&#8217;t using HLSL, the linker would strip it out.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Sean Barrett</title>
		<link>http://aras-p.info/blog/2009/01/22/fixed-function-lighting-in-vertex-shader-how/comment-page-1/#comment-16842</link>
		<dc:creator>Sean Barrett</dc:creator>
		<pubDate>Wed, 04 Mar 2009 18:36:37 +0000</pubDate>
		<guid isPermaLink="false">http://aras-p.info/blog/?p=261#comment-16842</guid>
		<description>Using HLSL instead of assembly requires an extra megabyte? How so? Does that stuff live in a library that if you can link in separately? Or it gets trimmed out automatically if you don&#039;t call it? I&#039;d have assumed that was all DLLs at least.</description>
		<content:encoded><![CDATA[<p>Using HLSL instead of assembly requires an extra megabyte? How so? Does that stuff live in a library that if you can link in separately? Or it gets trimmed out automatically if you don&#8217;t call it? I&#8217;d have assumed that was all DLLs at least.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Aras Pranckevičius</title>
		<link>http://aras-p.info/blog/2009/01/22/fixed-function-lighting-in-vertex-shader-how/comment-page-1/#comment-16274</link>
		<dc:creator>Aras Pranckevičius</dc:creator>
		<pubDate>Fri, 23 Jan 2009 04:27:17 +0000</pubDate>
		<guid isPermaLink="false">http://aras-p.info/blog/?p=261#comment-16274</guid>
		<description>@Michael: thanks, but using GLSL does not really help under DX9 (why DX9? Because D3D is &lt;em&gt;way&lt;/em&gt; more stable than OpenGL on Windows). Also, ftransform() does not work as expected in some OpenGL implementations. E.g. on Apple platforms, ftransform() on some ATI cards does not work like it should - it produces different result than fixed function pipe.

@Simon: I know. But I still have quite a large chunk of XP installs to support that won&#039;t go away soon.

@Jack: thanks for the info. I guess I&#039;ll just work on this further and see what happens.</description>
		<content:encoded><![CDATA[<p>@Michael: thanks, but using GLSL does not really help under DX9 (why DX9? Because D3D is <em>way</em> more stable than OpenGL on Windows). Also, ftransform() does not work as expected in some OpenGL implementations. E.g. on Apple platforms, ftransform() on some ATI cards does not work like it should &#8211; it produces different result than fixed function pipe.</p>
<p>@Simon: I know. But I still have quite a large chunk of XP installs to support that won&#8217;t go away soon.</p>
<p>@Jack: thanks for the info. I guess I&#8217;ll just work on this further and see what happens.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jack Palevich</title>
		<link>http://aras-p.info/blog/2009/01/22/fixed-function-lighting-in-vertex-shader-how/comment-page-1/#comment-16273</link>
		<dc:creator>Jack Palevich</dc:creator>
		<pubDate>Fri, 23 Jan 2009 03:17:17 +0000</pubDate>
		<guid isPermaLink="false">http://aras-p.info/blog/?p=261#comment-16273</guid>
		<description>Oh, and as for&quot;why&quot; it happens, the answer is that floating point math operations are not associative or commutative, but the HLSL compiler (and sometimes the graphics drivers) pretend that they are.

So it&#039;s not really a fixed function vs HLSL issue, its a &quot;two shaders that do the same operations in a different order give slightly different results&quot; issue. You can sometimes run into it with two similar HLSL shaders that end up being optimized differently.

Skipping HLSL and using assembly fragments can help, but an aggressive driver can still decide to reorder the instructions in your shaders, leading to differences in results.</description>
		<content:encoded><![CDATA[<p>Oh, and as for&#8221;why&#8221; it happens, the answer is that floating point math operations are not associative or commutative, but the HLSL compiler (and sometimes the graphics drivers) pretend that they are.</p>
<p>So it&#8217;s not really a fixed function vs HLSL issue, its a &#8220;two shaders that do the same operations in a different order give slightly different results&#8221; issue. You can sometimes run into it with two similar HLSL shaders that end up being optimized differently.</p>
<p>Skipping HLSL and using assembly fragments can help, but an aggressive driver can still decide to reorder the instructions in your shaders, leading to differences in results.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jack Palevich</title>
		<link>http://aras-p.info/blog/2009/01/22/fixed-function-lighting-in-vertex-shader-how/comment-page-1/#comment-16272</link>
		<dc:creator>Jack Palevich</dc:creator>
		<pubDate>Fri, 23 Jan 2009 03:06:01 +0000</pubDate>
		<guid isPermaLink="false">http://aras-p.info/blog/?p=261#comment-16272</guid>
		<description>I&#039;ve done something like this for Xbox 360, and it worked out pretty well. I think most Windows graphics drivers try pretty hard to optimize the shaders that are handed to them, so you probably don&#039;t need to do much optimization on your own. In fact you optimizations might even be counterproductive, because they might prevent the driver from doing some of its own optimizations.

The Xbox 360, of course, does no run-time shader optimization. At least it didn&#039;t back when I was programming it.

One problem you may run into is that for DX9 99% of games use HLSL rather than hand-written assembly, which means that the graphics drivers are only being tested and optimized for the kind of assembly that HLSL puts out. If you start feeding in your own assembly, you may find that you get sub-optimal results or even expose bugs in the drivers. (For example, there are some opcodes which HLSL never generates. If you start using those opcodes you may find the driver doesn&#039;t handle them correctly.)

I highly recommend writing your shader generator to produce HLSL as well as assembly, so that you can compare the relative performance (and bugs). Also, you might find that the HLSL generation time isn&#039;t too slow.

You will probably learn a lot about the fixed function pipeline. I know I did. :-)</description>
		<content:encoded><![CDATA[<p>I&#8217;ve done something like this for Xbox 360, and it worked out pretty well. I think most Windows graphics drivers try pretty hard to optimize the shaders that are handed to them, so you probably don&#8217;t need to do much optimization on your own. In fact you optimizations might even be counterproductive, because they might prevent the driver from doing some of its own optimizations.</p>
<p>The Xbox 360, of course, does no run-time shader optimization. At least it didn&#8217;t back when I was programming it.</p>
<p>One problem you may run into is that for DX9 99% of games use HLSL rather than hand-written assembly, which means that the graphics drivers are only being tested and optimized for the kind of assembly that HLSL puts out. If you start feeding in your own assembly, you may find that you get sub-optimal results or even expose bugs in the drivers. (For example, there are some opcodes which HLSL never generates. If you start using those opcodes you may find the driver doesn&#8217;t handle them correctly.)</p>
<p>I highly recommend writing your shader generator to produce HLSL as well as assembly, so that you can compare the relative performance (and bugs). Also, you might find that the HLSL generation time isn&#8217;t too slow.</p>
<p>You will probably learn a lot about the fixed function pipeline. I know I did. :-)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Simon Kozlov</title>
		<link>http://aras-p.info/blog/2009/01/22/fixed-function-lighting-in-vertex-shader-how/comment-page-1/#comment-16271</link>
		<dc:creator>Simon Kozlov</dc:creator>
		<pubDate>Fri, 23 Jan 2009 02:51:05 +0000</pubDate>
		<guid isPermaLink="false">http://aras-p.info/blog/?p=261#comment-16271</guid>
		<description>I&#039;&#039;m not sure if it helps, but FYI - Vista doesn&#039;t use fixed function pipeline at all (for WDDM drivers, which is everywhere), it&#039;s all implemented via vertex/pixel shaders so you shouldn&#039;t see the difference.</description>
		<content:encoded><![CDATA[<p>I&#8221;m not sure if it helps, but FYI &#8211; Vista doesn&#8217;t use fixed function pipeline at all (for WDDM drivers, which is everywhere), it&#8217;s all implemented via vertex/pixel shaders so you shouldn&#8217;t see the difference.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Michael Daum</title>
		<link>http://aras-p.info/blog/2009/01/22/fixed-function-lighting-in-vertex-shader-how/comment-page-1/#comment-16270</link>
		<dc:creator>Michael Daum</dc:creator>
		<pubDate>Fri, 23 Jan 2009 01:32:47 +0000</pubDate>
		<guid isPermaLink="false">http://aras-p.info/blog/?p=261#comment-16270</guid>
		<description>Not sure if you&#039;re interested, but the ftransform() function in GLSL solves exactly this problem, providing the correct transform which will allow one to mix GLSL passes with GL fixed pipeline passes.  Plus, you&#039;ll have portable code as a bonus after you switch from D3D!!</description>
		<content:encoded><![CDATA[<p>Not sure if you&#8217;re interested, but the ftransform() function in GLSL solves exactly this problem, providing the correct transform which will allow one to mix GLSL passes with GL fixed pipeline passes.  Plus, you&#8217;ll have portable code as a bonus after you switch from D3D!!</p>
]]></content:encoded>
	</item>
</channel>
</rss>
