<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://forums.xna.com/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>General</title><link>http://forums.xna.com/forums/32.aspx</link><description>Don't know where to post your question? Post it here!</description><dc:language>en</dc:language><generator>CommunityServer 2007.1 (Build: 0.0)</generator><item><title>Re: Help with fog</title><link>http://forums.xna.com/forums/thread/27273.aspx</link><pubDate>Sun, 07 Oct 2007 15:13:06 GMT</pubDate><guid isPermaLink="false">4aa5dbf6-357b-46b2-b5b2-1b660a6dc370:27273</guid><dc:creator>Melvil</dc:creator><slash:comments>0</slash:comments><comments>http://forums.xna.com/forums/thread/27273.aspx</comments><wfw:commentRss>http://forums.xna.com/forums/commentrss.aspx?SectionID=32&amp;PostID=27273</wfw:commentRss><description>Thanks, the performance boost ist pretty significant, almost back to 150fps again.&lt;br&gt;&lt;br&gt;Too bad it adds some extra work to change every single vertex shader - previously I only had to call my "calculateFog" function from every pixel shader.&lt;br&gt;&lt;br&gt;As for the shaders - I'm using a water shader, a terrain with 5 tex2D instructions, a skybox (again, 1 tex2D for each side) and an instancing shader for geometry. While 100fps are still fine I think I'm slowly reaching the limits of my card.&lt;br&gt;</description></item><item><title>Re: Help with fog</title><link>http://forums.xna.com/forums/thread/27264.aspx</link><pubDate>Sun, 07 Oct 2007 14:18:07 GMT</pubDate><guid isPermaLink="false">4aa5dbf6-357b-46b2-b5b2-1b660a6dc370:27264</guid><dc:creator>jwatte</dc:creator><slash:comments>0</slash:comments><comments>http://forums.xna.com/forums/thread/27264.aspx</comments><wfw:commentRss>http://forums.xna.com/forums/commentrss.aspx?SectionID=32&amp;PostID=27264</wfw:commentRss><description>Yes, it's likely the math. However, a 33% reduction in fill rate means that your pixel shader probably is pretty simple, so adding the fog adds noticably extra data. If your pixel shader were more complex (say, with normal maps and normal mapped environment maps), then the fog would be less noticeable.&lt;br&gt;&lt;br&gt;One thing you can do is to calculate the length and division in the vertex shader, and send the quotient in as an interpoland, and then only do the saturate() per-pixel. That's sure to reduce the impact of the fog calculation.&lt;br&gt;&lt;br&gt;</description></item><item><title>Re: Help with fog</title><link>http://forums.xna.com/forums/thread/27250.aspx</link><pubDate>Sun, 07 Oct 2007 10:46:25 GMT</pubDate><guid isPermaLink="false">4aa5dbf6-357b-46b2-b5b2-1b660a6dc370:27250</guid><dc:creator>Melvil</dc:creator><slash:comments>0</slash:comments><comments>http://forums.xna.com/forums/thread/27250.aspx</comments><wfw:commentRss>http://forums.xna.com/forums/commentrss.aspx?SectionID=32&amp;PostID=27250</wfw:commentRss><description>Sorry for the bump, but I just implemented this fog shader into my little engine, and apply the fog-function to my terrain, water, vegetation etc.&lt;br&gt;I noticed that this costs me 50fps, the framerate drops from 150fps to 100fps from the same position.&lt;br&gt;Here's the shader:&lt;br&gt;&lt;br&gt;&lt;div style="background-color:White;"&gt;&lt;div style="margin:0px;padding:2px 2px 2px 8px;background-color:White;overflow-x:scroll;overflow-y:hidden;width:505px;"&gt;&lt;pre&gt;&lt;span style="color:Black;background-color:transparent;font-family:Courier New;font-size:11px;font-weight:normal;"&gt;float4 calculateFog(float4 Color, float3 Position)&lt;br&gt;{&lt;br&gt;&amp;nbsp;&amp;nbsp;&lt;span style="color:Blue;background-color:transparent;font-family:Courier New;font-size:11px;font-weight:normal;"&gt;if&lt;/span&gt;(!FogEnable)&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color:Blue;background-color:transparent;font-family:Courier New;font-size:11px;font-weight:normal;"&gt;return&lt;/span&gt; Color;&lt;br&gt;&amp;nbsp;&amp;nbsp;&lt;span style="color:Blue;background-color:transparent;font-family:Courier New;font-size:11px;font-weight:normal;"&gt;else&lt;/span&gt;&lt;br&gt;&amp;nbsp;&amp;nbsp;{&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color:Blue;background-color:transparent;font-family:Courier New;font-size:11px;font-weight:normal;"&gt;float&lt;/span&gt; d &lt;span style="color:Red;background-color:transparent;font-family:Courier New;font-size:11px;font-weight:normal;"&gt;=&lt;/span&gt; length(Position &lt;span style="color:Red;background-color:transparent;font-family:Courier New;font-size:11px;font-weight:normal;"&gt;-&lt;/span&gt; CameraPos);&lt;br&gt;&lt;span style="color:Green;background-color:transparent;font-family:Courier New;font-size:11px;font-weight:normal;"&gt;//&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;float l = saturate((d - FogNear) / (FogFar - FogNear) / clamp(Position.y / FogAltitudeScale + 1, 1, FogThinning));&lt;/span&gt;&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color:Blue;background-color:transparent;font-family:Courier New;font-size:11px;font-weight:normal;"&gt;float&lt;/span&gt; l &lt;span style="color:Red;background-color:transparent;font-family:Courier New;font-size:11px;font-weight:normal;"&gt;=&lt;/span&gt; saturate((d &lt;span style="color:Red;background-color:transparent;font-family:Courier New;font-size:11px;font-weight:normal;"&gt;-&lt;/span&gt; FogNear) &lt;span style="color:Red;background-color:transparent;font-family:Courier New;font-size:11px;font-weight:normal;"&gt;/&lt;/span&gt; (FogFar &lt;span style="color:Red;background-color:transparent;font-family:Courier New;font-size:11px;font-weight:normal;"&gt;-&lt;/span&gt; FogNear));&lt;br&gt;    &lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color:Blue;background-color:transparent;font-family:Courier New;font-size:11px;font-weight:normal;"&gt;return&lt;/span&gt; lerp(Color, FogColor, l);&lt;br&gt;    }&lt;br&gt;}&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;&lt;br&gt;Removing the braching (FogEnable) doesn't make any difference, so I guess it's the math functions that have effect on my fillrate limitated graphics card? (GF6800gt)&lt;br&gt;</description></item><item><title>Re: Help with fog</title><link>http://forums.xna.com/forums/thread/17439.aspx</link><pubDate>Thu, 19 Jul 2007 04:05:03 GMT</pubDate><guid isPermaLink="false">4aa5dbf6-357b-46b2-b5b2-1b660a6dc370:17439</guid><dc:creator>Charles Humphrey</dc:creator><slash:comments>0</slash:comments><comments>http://forums.xna.com/forums/thread/17439.aspx</comments><wfw:commentRss>http://forums.xna.com/forums/commentrss.aspx?SectionID=32&amp;PostID=17439</wfw:commentRss><description>&lt;P&gt;Thanks :)&lt;/P&gt;
&lt;P&gt;I have updated my blog, would one of you guys be kind enough to pop along and make sure what I have put is correct (guess I should not be posting on stuff I dont fully know right!, but it is up now...) It is &lt;A href="http://randomchaosuk.blogspot.com/2007/07/shader-fog.html"&gt;here&lt;/A&gt; &lt;/P&gt;</description></item><item><title>Re: Help with fog</title><link>http://forums.xna.com/forums/thread/17398.aspx</link><pubDate>Wed, 18 Jul 2007 18:39:31 GMT</pubDate><guid isPermaLink="false">4aa5dbf6-357b-46b2-b5b2-1b660a6dc370:17398</guid><dc:creator>Leaf Garland</dc:creator><slash:comments>0</slash:comments><comments>http://forums.xna.com/forums/thread/17398.aspx</comments><wfw:commentRss>http://forums.xna.com/forums/commentrss.aspx?SectionID=32&amp;PostID=17398</wfw:commentRss><description>I knocked up a quick sample of fogging that includes Jon's height fogging code. You can get it &lt;a href="http://xna-uk.net/blogs/xnagoodies/archive/2007/07/18/fogging-sample.aspx"&gt;here&lt;/a&gt;.&lt;br&gt;&lt;br&gt;Cheers,&lt;br&gt;Leaf.&lt;br&gt;</description></item><item><title>Re: Help with fog</title><link>http://forums.xna.com/forums/thread/17397.aspx</link><pubDate>Wed, 18 Jul 2007 18:36:43 GMT</pubDate><guid isPermaLink="false">4aa5dbf6-357b-46b2-b5b2-1b660a6dc370:17397</guid><dc:creator>Charles Humphrey</dc:creator><slash:comments>0</slash:comments><comments>http://forums.xna.com/forums/thread/17397.aspx</comments><wfw:commentRss>http://forums.xna.com/forums/commentrss.aspx?SectionID=32&amp;PostID=17397</wfw:commentRss><description>&lt;P&gt;Brilliant!&lt;/P&gt;
&lt;P&gt;Thank you so much, you are now my HLSL guru :) I am not to bothered about the application of your shader, as I can just take the "Fog" code and now bolt it into my shaders. I will have a play with the SM2 one you put up as I am sure there is stuff in there that I can leanr from.&lt;/P&gt;
&lt;P&gt;Thanks guys, with out people like you contributing to these boards I think XNA and home brew games in general would be moving at a much slower pace.&lt;/P&gt;
&lt;P&gt;Thanks again.&lt;/P&gt;</description></item><item><title>Re: Help with fog</title><link>http://forums.xna.com/forums/thread/17395.aspx</link><pubDate>Wed, 18 Jul 2007 17:22:41 GMT</pubDate><guid isPermaLink="false">4aa5dbf6-357b-46b2-b5b2-1b660a6dc370:17395</guid><dc:creator>jwatte</dc:creator><slash:comments>0</slash:comments><comments>http://forums.xna.com/forums/thread/17395.aspx</comments><wfw:commentRss>http://forums.xna.com/forums/commentrss.aspx?SectionID=32&amp;PostID=17395</wfw:commentRss><description>The simple way to do it:&lt;br&gt;&lt;br&gt;1) Change the FOG output sematic to something like TEXCOORD5.&lt;br&gt;&lt;br&gt;2) Right before returning the color in the pixel shader, do a lerp() between the calculated color, and the fog color, based on the TEXCOORD5 input value. It really is a one-liner.&lt;br&gt;&lt;br&gt;That gives you per-vertex fog calculation instead of per-pixel, but unless you use really large triangles that are fogged when you're near them, you're unlikely to see any difference.&lt;br&gt;&lt;br&gt;In the shader I posted, you change the following lines (red old, green new):&lt;br&gt;&lt;br&gt;&lt;br&gt;&lt;br&gt;&lt;font color="#ff0000"&gt;float&amp;nbsp; Fog&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; : FOG;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; // vertex fog&lt;br&gt;&lt;/font&gt;&lt;font color="#9acd32"&gt;float&amp;nbsp; Fog&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; : TEXCOORD4;&amp;nbsp;&amp;nbsp;&amp;nbsp; // vertex fog&lt;br&gt;&lt;/font&gt;&lt;br&gt;&lt;font color="#ff0000"&gt;Output.RGBColor = color * ((In.Diffuse * g_MaterialDiffuseColor) * diffuse + g_MaterialAmbientColor);&lt;br&gt;&lt;/font&gt;&lt;font color="#9acd32"&gt;Output.RGBColor = lerp(g_FogColor, &lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; color * ((In.Diffuse * g_MaterialDiffuseColor) * diffuse + g_MaterialAmbientColor), &lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; In.Fog);&lt;/font&gt;&lt;br&gt;&lt;br&gt;That's the only change, and it'll work on SM 3 and other such targets. You should turn off the FOG render state in the technique/pass set-up, too.&lt;br&gt;&lt;br&gt;&lt;font color="#ff0000"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; FogEnable = TRUE;&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; FogVertexMode = LINEAR;&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; FogColor = (g_FogColor);&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; FogStart = (g_FogDistance / 5);&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; FogEnd = (g_FogDistance);&lt;/font&gt;&lt;br&gt;&lt;font color="#9acd32"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; FogEnable = FALSE;&lt;br&gt;&lt;/font&gt;
&lt;br&gt;Btw: As you probably see, the shader I posted uses two tangent-space normal maps; one for the 0..1 UV range, and one for tiling. The reason for this is that I use that shader for my height map implementation, where I use the large normal map instead of vertex normals. If you have another source of normals, you can remove all that complexity per-pixel.&lt;br&gt;&lt;br&gt;</description></item><item><title>Re: Help with fog</title><link>http://forums.xna.com/forums/thread/17386.aspx</link><pubDate>Wed, 18 Jul 2007 15:06:07 GMT</pubDate><guid isPermaLink="false">4aa5dbf6-357b-46b2-b5b2-1b660a6dc370:17386</guid><dc:creator>Charles Humphrey</dc:creator><slash:comments>0</slash:comments><comments>http://forums.xna.com/forums/thread/17386.aspx</comments><wfw:commentRss>http://forums.xna.com/forums/commentrss.aspx?SectionID=32&amp;PostID=17386</wfw:commentRss><description>&lt;P&gt;Awesome, thanks for the shader example.&lt;/P&gt;
&lt;P&gt;FXComposer is great to get started with, lots of good examples to leanr from and if the shader you have written is wrong, you know it's your shader and not your XNA code.&lt;/P&gt;
&lt;P&gt;As Leaf and others have pointed out this method will not work on the XBox 360 or on SM3, can anyone give us an example of this please? It&amp;nbsp; does not have to be as large as the one put up by jwatte, just one that will demonstrate how to do it under SM3. If I am missing something with the shader above and this too can be applied on the XBox 360, can you explain the diffrence between my attempt and the shader given above.&lt;/P&gt;
&lt;P&gt;Sorry for all the asks, but if you don't ask you wont get and I am hear to learn as much as I can and this seems the best place to ask :)&lt;/P&gt;
&lt;P&gt;Thanks.&lt;/P&gt;</description></item><item><title>Re: Help with fog</title><link>http://forums.xna.com/forums/thread/17367.aspx</link><pubDate>Wed, 18 Jul 2007 12:12:56 GMT</pubDate><guid isPermaLink="false">4aa5dbf6-357b-46b2-b5b2-1b660a6dc370:17367</guid><dc:creator>jwatte</dc:creator><slash:comments>0</slash:comments><comments>http://forums.xna.com/forums/thread/17367.aspx</comments><wfw:commentRss>http://forums.xna.com/forums/commentrss.aspx?SectionID=32&amp;PostID=17367</wfw:commentRss><description>Where to learn shaders? I don't know. I started learning about 3D using the POV-Ray program in the late 80s (text-based ray tracing app); then I took the Foley / van Dam graphics class in college, and then I've just kept up to date by following mailing lists and forums.&lt;br&gt;&lt;br&gt;I would imagine that starting by downloading RenderMonkey and/or FX Composer, and going through the tutorials and examples ought to be a good start. Following the easier HLSL examples in the DirectX SDK would also help. The DirectX SDK documentation is useful, too, because it documents everything about how the shader models actually fit in the pipeline, and all of the HLSL language.&lt;br&gt;&lt;br&gt;Here's a shader (2.0) that calculates its own fog factor, but which uses fixed-function fog application. If you want less fog for taller things, you could adjust that when calculating Output.Fog, based on the height of the vertex.&lt;br&gt;&lt;br&gt;[/source]&lt;br&gt;float4 g_MaterialAmbientColor&amp;lt;&lt;br&gt;&amp;nbsp; string UIName = "Ambient";&lt;br&gt;&amp;gt; = float4( 0.1, 0.1, 0.15, 1 );&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; // Material's ambient color&lt;br&gt;float4 g_MaterialDiffuseColor&amp;lt;&lt;br&gt;&amp;nbsp; string UIName = "Diffuse";&lt;br&gt;&amp;gt; = float4( 0.9, 0.85, 0.7, 0 );&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; // Material's diffuse color&lt;br&gt;float3 g_LightDir : Direction &amp;lt;&lt;br&gt;&amp;nbsp; string UIName = "Light Direction";&lt;br&gt;&amp;nbsp; string Object = "TargetLight";&lt;br&gt;&amp;gt; = float3( -0.3, 0.8124, -0.5 );&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; // Light's direction in world space&lt;br&gt;float4 g_LightDiffuse&amp;lt;&lt;br&gt;&amp;nbsp; string UIName = "Light Diffuse Color";&lt;br&gt;&amp;gt; = float4( 1, 1, 1, 0 );&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; // Light's diffuse color&lt;br&gt;&lt;br&gt;texture&amp;nbsp; g_MeshTexture : DiffuseMap&amp;lt;&lt;br&gt;&amp;nbsp; string UIName = "Diffuse Texture";&lt;br&gt;&amp;gt;;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; // Color texture for mesh&lt;br&gt;texture&amp;nbsp; g_NormalTexture : NormalMap&amp;lt;&lt;br&gt;&amp;nbsp; string UIName = "Normal Map";&lt;br&gt;&amp;gt;;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; // Large-scale normal map&lt;br&gt;texture&amp;nbsp; g_NormalDetail : NormalDetail&amp;lt;&lt;br&gt;&amp;nbsp; string UIName = "Normal Detail";&lt;br&gt;&amp;gt;;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; // Fins-scale normal map&lt;br&gt;float4x4 g_mWorldViewProjection : WORLDVIEWPROJ;&amp;nbsp;&amp;nbsp;&amp;nbsp; // World * View * Projection matrix&lt;br&gt;float4x4 g_mWorld : WORLD;&lt;br&gt;&lt;br&gt;float4 g_FogColor : FogColor&amp;lt;&lt;br&gt;&amp;nbsp; string UIName = "Fog Color";&lt;br&gt;&amp;gt; = float4(0.5, 0.5, 0.5, 1);&lt;br&gt;float g_FogDistance : FogDistance&amp;lt;&lt;br&gt;&amp;nbsp; string UIName = "Fog Distance";&lt;br&gt;&amp;gt; = 2000.0;&lt;br&gt;&lt;br&gt;float g_NormalUVScale = 256;&lt;br&gt;&lt;br&gt;sampler MeshTextureSampler = &lt;br&gt;sampler_state&lt;br&gt;{&lt;br&gt;&amp;nbsp; Texture = &amp;lt;g_MeshTexture&amp;gt;;&lt;br&gt;&amp;nbsp; MipFilter = LINEAR;&lt;br&gt;&amp;nbsp; MinFilter = ANISOTROPIC;&lt;br&gt;&amp;nbsp; MagFilter = LINEAR;&lt;br&gt;&amp;nbsp; MaxAnisotropy = 8;&lt;br&gt;};&lt;br&gt;&lt;br&gt;sampler NormalTextureSampler = &lt;br&gt;sampler_state&lt;br&gt;{&lt;br&gt;&amp;nbsp; Texture = &amp;lt;g_NormalTexture&amp;gt;;&lt;br&gt;&amp;nbsp; MipFilter = LINEAR;&lt;br&gt;&amp;nbsp; MinFilter = ANISOTROPIC;&lt;br&gt;&amp;nbsp; MagFilter = LINEAR;&lt;br&gt;&amp;nbsp; MaxAnisotropy = 8;&lt;br&gt;};&lt;br&gt;&lt;br&gt;sampler NormalDetailSampler = &lt;br&gt;sampler_state&lt;br&gt;{&lt;br&gt;&amp;nbsp; Texture = &amp;lt;g_NormalDetail&amp;gt;;&lt;br&gt;&amp;nbsp; MipFilter = LINEAR;&lt;br&gt;&amp;nbsp; MinFilter = ANISOTROPIC;&lt;br&gt;&amp;nbsp; MagFilter = LINEAR;&lt;br&gt;&amp;nbsp; MaxAnisotropy = 8;&lt;br&gt;};&lt;br&gt;&lt;br&gt;&lt;br&gt;struct VS_OUTPUT&lt;br&gt;{&lt;br&gt;&amp;nbsp; float4 Position&amp;nbsp;&amp;nbsp; : POSITION;&amp;nbsp;&amp;nbsp; // vertex position &lt;br&gt;&amp;nbsp; float4 Diffuse&amp;nbsp;&amp;nbsp;&amp;nbsp; : COLOR0;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; // vertex diffuse color (note that COLOR0 is clamped from 0..1)&lt;br&gt;&amp;nbsp; float2 TextureUV&amp;nbsp; : TEXCOORD0;&amp;nbsp; // vertex texture coords &lt;br&gt;&amp;nbsp; float3 PNormal&amp;nbsp;&amp;nbsp;&amp;nbsp; : TEXCOORD1;&amp;nbsp; // vertex normal&lt;br&gt;&amp;nbsp; float3 PTangent&amp;nbsp;&amp;nbsp; : TEXCOORD2;&amp;nbsp; // vertex U tangent&lt;br&gt;&amp;nbsp; float3 PBitangent : TEXCOORD3;&amp;nbsp; // vertex V tangent&lt;br&gt;&amp;nbsp; float&amp;nbsp; Fog&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; : FOG;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp; // vertex fog&lt;br&gt;};&lt;br&gt;&lt;br&gt;&lt;br&gt;VS_OUTPUT RenderSceneVS( float4 vPos : POSITION, &lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; float3 vNormal : NORMAL,&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; float2 vTexCoord0 : TEXCOORD0 )&lt;br&gt;{&lt;br&gt;&amp;nbsp; VS_OUTPUT Output;&lt;br&gt;&amp;nbsp; float4 oPos;&lt;br&gt;&amp;nbsp; &lt;br&gt;&amp;nbsp; // Transform the position from object space to homogeneous projection space&lt;br&gt;&amp;nbsp; oPos = mul(vPos, g_mWorldViewProjection);&lt;br&gt;&amp;nbsp; Output.Position = oPos;&lt;br&gt;&amp;nbsp; float3 mNormal = normalize(mul(vNormal, (float3x3)g_mWorld));&lt;br&gt;&amp;nbsp; Output.PNormal = mNormal;&lt;br&gt;&amp;nbsp; float3 mTangent = g_mWorld[0];&lt;br&gt;&amp;nbsp; mTangent -= mNormal * dot(mNormal, mTangent);&lt;br&gt;&amp;nbsp; Output.PTangent = normalize(mTangent);&lt;br&gt;&amp;nbsp; Output.PBitangent = cross(mTangent, mNormal);&lt;br&gt;&amp;nbsp; &lt;br&gt;&amp;nbsp; // Calc diffuse color&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;br&gt;&amp;nbsp; Output.Diffuse.rgb = g_MaterialDiffuseColor;&lt;br&gt;&amp;nbsp; Output.Diffuse.a = 1.0f;&lt;br&gt;&amp;nbsp; &lt;br&gt;&amp;nbsp; // Just copy the texture coordinate through&lt;br&gt;&amp;nbsp; Output.TextureUV = vTexCoord0;&lt;br&gt;&lt;br&gt;&amp;nbsp; Output.Fog = 1 - saturate((oPos.z - g_FogDistance * 0.2f) / (g_FogDistance * 0.8f));&lt;br&gt;&lt;br&gt;&amp;nbsp; return Output;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;br&gt;}&lt;br&gt;&lt;br&gt;&lt;br&gt;struct PS_OUTPUT&lt;br&gt;{&lt;br&gt;&amp;nbsp; float4 RGBColor : COLOR0;&amp;nbsp; // Pixel color&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;br&gt;};&lt;br&gt;&lt;br&gt;&lt;br&gt;PS_OUTPUT RenderScenePS( VS_OUTPUT In ) &lt;br&gt;{ &lt;br&gt;&amp;nbsp; PS_OUTPUT Output;&lt;br&gt;&lt;br&gt;&amp;nbsp; float3 mNormalDetail = tex2D(NormalDetailSampler, (In.TextureUV - float2(0.5, 0.5)) * g_NormalUVScale) * 2 - 1;&lt;br&gt;&amp;nbsp; float3 mNormal = tex2D(NormalTextureSampler, In.TextureUV) * 2 - 1;&lt;br&gt;&amp;nbsp; mNormal = mNormal + mNormalDetail;&lt;br&gt;&amp;nbsp; float4 color = tex2D(MeshTextureSampler, In.TextureUV);&lt;br&gt;&lt;br&gt;&amp;nbsp; mNormal = In.PTangent * mNormal.x + In.PBitangent * mNormal.y + In.PNormal * mNormal.z;&lt;br&gt;&amp;nbsp; mNormal = normalize(mNormal);&lt;br&gt;&amp;nbsp; float diffuse = max(0, dot(mNormal, g_LightDir));&lt;br&gt;&amp;nbsp; &lt;br&gt;&amp;nbsp; Output.RGBColor = color * ((In.Diffuse * g_MaterialDiffuseColor) * diffuse + g_MaterialAmbientColor);&lt;br&gt;&lt;br&gt;&amp;nbsp; return Output;&lt;br&gt;}&lt;br&gt;&lt;br&gt;&lt;br&gt;technique RenderScene&lt;br&gt;{&lt;br&gt;&amp;nbsp; pass P0&lt;br&gt;&amp;nbsp; {&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; AlphaBlendEnable = false;&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; ZEnable = true;&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; ZWriteEnable = true;&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; CullMode = CCW;&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; FogEnable = TRUE;&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; FogVertexMode = LINEAR;&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; FogColor = (g_FogColor);&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; FogStart = (g_FogDistance / 5);&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; FogEnd = (g_FogDistance);&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; VertexShader = compile vs_2_0 RenderSceneVS();&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; PixelShader&amp;nbsp; = compile ps_2_0 RenderScenePS(); &lt;br&gt;&amp;nbsp; }&lt;br&gt;}&lt;br&gt;[/source]&lt;br&gt;&lt;br&gt;&lt;br&gt;&lt;br&gt;</description></item><item><title>Re: Help with fog</title><link>http://forums.xna.com/forums/thread/17316.aspx</link><pubDate>Wed, 18 Jul 2007 07:10:59 GMT</pubDate><guid isPermaLink="false">4aa5dbf6-357b-46b2-b5b2-1b660a6dc370:17316</guid><dc:creator>Charles Humphrey</dc:creator><slash:comments>0</slash:comments><comments>http://forums.xna.com/forums/thread/17316.aspx</comments><wfw:commentRss>http://forums.xna.com/forums/commentrss.aspx?SectionID=32&amp;PostID=17316</wfw:commentRss><description>&lt;P&gt;On the thread of doing fog in the shader for SM3, can any of you guys give an example, it's just that I/most of us&amp;nbsp;are new too all this and just telling us how to go about doing something does not cut it every time (probably just me here), and an example would be great, even if it is just for a simple Texture shader with the SM3 fog logic in it.&lt;/P&gt;
&lt;P&gt;Thanks.&lt;/P&gt;</description></item><item><title>Re: Help with fog</title><link>http://forums.xna.com/forums/thread/17311.aspx</link><pubDate>Wed, 18 Jul 2007 05:32:43 GMT</pubDate><guid isPermaLink="false">4aa5dbf6-357b-46b2-b5b2-1b660a6dc370:17311</guid><dc:creator>Charles Humphrey</dc:creator><slash:comments>0</slash:comments><comments>http://forums.xna.com/forums/thread/17311.aspx</comments><wfw:commentRss>http://forums.xna.com/forums/commentrss.aspx?SectionID=32&amp;PostID=17311</wfw:commentRss><description>&lt;P&gt;Leaf,&lt;/P&gt;
&lt;P&gt;Ahh, of course it is silly me :) I really should read things properly...&lt;/P&gt;
&lt;P&gt;Have sent you a mail regarding this method, thanks for your help. Thanks for your comment on the blog too :)&lt;/P&gt;</description></item><item><title>Re: Help with fog</title><link>http://forums.xna.com/forums/thread/17307.aspx</link><pubDate>Wed, 18 Jul 2007 05:02:19 GMT</pubDate><guid isPermaLink="false">4aa5dbf6-357b-46b2-b5b2-1b660a6dc370:17307</guid><dc:creator>Kawe</dc:creator><slash:comments>0</slash:comments><comments>http://forums.xna.com/forums/thread/17307.aspx</comments><wfw:commentRss>http://forums.xna.com/forums/commentrss.aspx?SectionID=32&amp;PostID=17307</wfw:commentRss><description>jwatte, do you have any good link or recommendation of a book where I can learn these things?&lt;br&gt;it seems shaders just get deeper and deeper. lol.&lt;br&gt;</description></item><item><title>Re: Help with fog</title><link>http://forums.xna.com/forums/thread/17306.aspx</link><pubDate>Wed, 18 Jul 2007 04:37:01 GMT</pubDate><guid isPermaLink="false">4aa5dbf6-357b-46b2-b5b2-1b660a6dc370:17306</guid><dc:creator>Leaf Garland</dc:creator><slash:comments>0</slash:comments><comments>http://forums.xna.com/forums/thread/17306.aspx</comments><wfw:commentRss>http://forums.xna.com/forums/commentrss.aspx?SectionID=32&amp;PostID=17306</wfw:commentRss><description>You can calculate fog manually (which is what the example does) in any shader model as long as your calculations fit into the capabilities of the shader model. The semantic FOGALTITUDESCALE that Jon used in his example is just a way of identifying the shader parameter to his code - the parameters are being identified by semantic rather than by name. He could have called it JONSWKDFOGFACTOR or anything else. Unlike vertex component semantics (POSITION, TEXCOORD, etc.) which must be recognised by the graphics API, the semantics on shader parameters are entirely for your own use and don't mean anything to the graphics API.&lt;br&gt;&lt;br&gt;So, yes that example should work in SM2 :)&lt;br&gt;&lt;br&gt;Cheers,&lt;br&gt;Leaf.&lt;br&gt;</description></item><item><title>Re: Help with fog</title><link>http://forums.xna.com/forums/thread/17299.aspx</link><pubDate>Wed, 18 Jul 2007 04:17:14 GMT</pubDate><guid isPermaLink="false">4aa5dbf6-357b-46b2-b5b2-1b660a6dc370:17299</guid><dc:creator>Charles Humphrey</dc:creator><slash:comments>0</slash:comments><comments>http://forums.xna.com/forums/thread/17299.aspx</comments><wfw:commentRss>http://forums.xna.com/forums/commentrss.aspx?SectionID=32&amp;PostID=17299</wfw:commentRss><description>&lt;P&gt;Cool!&lt;/P&gt;
&lt;P&gt;Jwatte, Can you apply the FOGALTITUDESCALE to SM2 as well??&lt;/P&gt;</description></item><item><title>Re: Help with fog</title><link>http://forums.xna.com/forums/thread/17297.aspx</link><pubDate>Wed, 18 Jul 2007 04:01:28 GMT</pubDate><guid isPermaLink="false">4aa5dbf6-357b-46b2-b5b2-1b660a6dc370:17297</guid><dc:creator>jwatte</dc:creator><slash:comments>0</slash:comments><comments>http://forums.xna.com/forums/thread/17297.aspx</comments><wfw:commentRss>http://forums.xna.com/forums/commentrss.aspx?SectionID=32&amp;PostID=17297</wfw:commentRss><description>Output.Fog only works in shader model 2, in general.&lt;br&gt;&lt;br&gt;In shader model 3, you want to calculate the distance from the camera of the pixel, and then map that distance to a value between 0 and 1 using a fog function, and then lerp between the calculated pixel color (with texturing, lighting, etc), and the fog color, using that calculated value.&lt;br&gt;&lt;br&gt;[source]&lt;br&gt;// a simple linear-style fog function&lt;br&gt;float fogNear : FOGNEAR;&lt;br&gt;float fogFar : FOGFAR;&lt;br&gt;float4 fogColor : FOGCOLOR;&lt;br&gt;float3 cameraPos : CAMERAPOS;&lt;br&gt;&lt;br&gt;// fragmentPos can be forwarded as an interpoland from the vertex shader&lt;br&gt;float4 MyPixelShader(... float3 fragmentPos ...) {&lt;br&gt;&amp;nbsp; ...&lt;br&gt;&amp;nbsp; float d = length(fragmentPos - cameraPos);&lt;br&gt;&amp;nbsp; float l = saturate((d-fogNear)/(fogFar-fogNear));&lt;br&gt;&amp;nbsp; return lerp(outColor, fogColor, l);&lt;br&gt;}&lt;br&gt;[/source]&lt;br&gt;&lt;br&gt;&lt;br&gt;This will fog everything in an even manner, based on distance from camera. You can make altitude-based fog by adjusting the fog factor based on elevation above ground through this little tweak:&lt;br&gt;&lt;br&gt;[source]&lt;br&gt;&amp;nbsp; float fogAltitudeScale : FOGALTITUDESCALE = 20;&lt;br&gt;&amp;nbsp; ...&lt;br&gt;&amp;nbsp; // assuming fragmentPos.z is "altitude"&lt;br&gt;&amp;nbsp; float l = saturate((d - fogNear)/(fogFar - fogNear) / clamp(fragmentPos.z / FOGALTITUDESCALE + 1, 1, 10));&lt;br&gt;[/source]&lt;br&gt;&lt;br&gt;&lt;br&gt;You might want to change the "+1" and "10" values of that equation to tunable parameters, too; the former controls how high up the fog will start thinning out, and the 10 controls the maximum amount of thinning.&lt;br&gt;&lt;br&gt;</description></item></channel></rss>