<?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>Direct3D</title><link>http://forums.xna.com/forums/27.aspx</link><description /><dc:language>en</dc:language><generator>CommunityServer 2007.1 (Build: 0.0)</generator><item><title>[SOLVED]Re: Odd HLSL Normal mapping issue</title><link>http://forums.xna.com/forums/thread/191594.aspx</link><pubDate>Fri, 19 Jun 2009 20:28:33 GMT</pubDate><guid isPermaLink="false">4aa5dbf6-357b-46b2-b5b2-1b660a6dc370:191594</guid><dc:creator>Zazu Yen</dc:creator><slash:comments>0</slash:comments><comments>http://forums.xna.com/forums/thread/191594.aspx</comments><wfw:commentRss>http://forums.xna.com/forums/commentrss.aspx?SectionID=27&amp;PostID=191594</wfw:commentRss><description>Well, the shader is fine. The meshes I was using had no TBN data so the normals were not getting translated into model space correctly. I don&amp;#39;t know why I didn&amp;#39;t recognize the default data in the tangent, normal, binormal input registers in PIX.&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;Let this be a hard lesson learned, always check the validity of your starting data when things appear to be going wrong for no reason! At least my shaders were, in fact, fine all along.&lt;/div&gt;</description></item><item><title>[SOLVED]Odd HLSL Normal mapping issue</title><link>http://forums.xna.com/forums/thread/191317.aspx</link><pubDate>Fri, 19 Jun 2009 00:22:17 GMT</pubDate><guid isPermaLink="false">4aa5dbf6-357b-46b2-b5b2-1b660a6dc370:191317</guid><dc:creator>Zazu Yen</dc:creator><slash:comments>0</slash:comments><comments>http://forums.xna.com/forums/thread/191317.aspx</comments><wfw:commentRss>http://forums.xna.com/forums/commentrss.aspx?SectionID=27&amp;PostID=191317</wfw:commentRss><description>&lt;span&gt;Maybe someone here can help me with this, it&amp;#39;s driving me nuts.&lt;/span&gt;&lt;div&gt;&lt;span&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style="font-family:verdana;"&gt;I&amp;#39;ve been working on a fairly simple HLSL shader and everything is working pretty well except for one problem, I&amp;#39;ve spent hours tinkering with the code and stepping through disassembly in PIX with no luck. The normal map looks fine from the &amp;#39;front&amp;#39; of the sample sphere, but it &lt;/span&gt;&lt;span style="font-family:verdana;"&gt;appears to slowly invert as it wraps around the sphere, so that in the &amp;#39;back&amp;#39; of the sphere what should be sticking out is stic&lt;/span&gt;&lt;span&gt;king in and &lt;span style="line-height:21px;font-size:12px;"&gt;vice-versa&lt;/span&gt;. Here is a sa&lt;/span&gt;&lt;span style="font-family:verdana;"&gt;mple image:&lt;br /&gt;&lt;br /&gt;On the left is the front of the sphere and is the way it&amp;#39;s supposed to look, on the right the sphere has been turned about 180 degrees. You can see that the grout on the right image is actually looking higher than the bricks.&lt;br /&gt;http://www.twilightfair.com/otherstuff/images/NormalExamples.jpg&lt;br /&gt;&lt;br /&gt;This would seem to be a simple problem, a missing transition or an out of order matrix multiplication, but I&amp;#39;ve had no luck finding it. I need some experienced eyes to take a look at the code and point out my fallacy. Here is the HLSL shader with all the extras pulled out (spectral mapping, spectral highlights, environment mapping, etc. etc.) It still has the same problem.&lt;/span&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;span&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span&gt;Relevant C# code:&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span&gt;&lt;div style="overflow-x:auto;overflow-y:auto;background-color:white;border-top-style:solid;border-right-style:solid;border-bottom-style:solid;border-left-style:solid;border-top-width:1px;border-right-width:1px;border-bottom-width:1px;border-left-width:1px;font-family:&amp;#39;courier new&amp;#39;;font-size:11px;"&gt;&lt;table cellpadding="0" cellspacing="0" style="width:99%;margin-top:2px;margin-right:0px;margin-bottom:2px;margin-left:0px;border-collapse:collapse;border-bottom-style:solid;border-top-width:0px;border-right-width:0px;border-bottom-width:0px;border-left-width:0px;"&gt;                &lt;tr&gt;            &lt;td&gt;&lt;span style="font-size:11px;"&gt;        Matrix marbleWorld = Matrix.CreateFromYawPitchRoll(ballRotation.Y, ballRotation.X, ballRotation.Z); &lt;/span&gt;&lt;/td&gt;        &lt;/tr&gt;        &lt;tr&gt;            &lt;td&gt;        effect.Parameters[&lt;span style="color:blue;"&gt;&amp;quot;WorldTransform&amp;quot;&lt;/span&gt;&lt;span style="font-size:11px;"&gt;].SetValue(marbleWorld); &lt;/span&gt;&lt;/td&gt;        &lt;/tr&gt;        &lt;tr&gt;            &lt;td&gt;        effect.Parameters[&lt;span style="color:blue;"&gt;&amp;quot;CameraTransform&amp;quot;&lt;/span&gt;&lt;span style="font-size:11px;"&gt;].SetValue(marbleWorld * camera.View * camera.Projection); &lt;/span&gt;&lt;/td&gt;        &lt;/tr&gt;        &lt;tr&gt;            &lt;td&gt;        effect.Parameters[&lt;span style="color:blue;"&gt;&amp;quot;DirectionalLightDirection&amp;quot;&lt;/span&gt;&lt;span style="font-size:11px;"&gt;].SetValue(&lt;/span&gt;&lt;span style="color:blue;"&gt;new&lt;/span&gt;&lt;span style="font-size:11px;"&gt; Vector3(1.0f, -1.0f, 0.5f)); &lt;/span&gt;&lt;/td&gt;        &lt;/tr&gt;        &lt;tr&gt;            &lt;td&gt;        effect.Parameters[&lt;span style="color:blue;"&gt;&amp;quot;DirectionalLightColor&amp;quot;&lt;/span&gt;&lt;span style="font-size:11px;"&gt;].SetValue(&lt;/span&gt;&lt;span style="color:blue;"&gt;new&lt;/span&gt;&lt;span style="font-size:11px;"&gt; Vector4(0.5f, 0.5f, 0.5f, 1.0f)); &lt;/span&gt;&lt;/td&gt;        &lt;/tr&gt;    &lt;/table&gt;&lt;/div&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span&gt;HLSL code:&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span&gt;&lt;div style="overflow-x:auto;overflow-y:auto;background-color:white;border-top-style:solid;border-right-style:solid;border-bottom-style:solid;border-left-style:solid;border-top-width:1px;border-right-width:1px;border-bottom-width:1px;border-left-width:1px;font-family:&amp;#39;courier new&amp;#39;;font-size:11px;"&gt;&lt;table cellpadding="0" cellspacing="0" style="width:99%;margin-top:2px;margin-right:0px;margin-bottom:2px;margin-left:0px;border-collapse:collapse;border-bottom-style:solid;border-top-width:0px;border-right-width:0px;border-bottom-width:0px;border-left-width:0px;"&gt;                &lt;tr&gt;            &lt;td&gt;&lt;span style="font-size:11px;"&gt;&lt;/span&gt;&lt;span style="color:green;"&gt;//////////////////////////////////////////////////&lt;/span&gt;&lt;span style="font-size:11px;"&gt; &lt;/span&gt;&lt;/td&gt;        &lt;/tr&gt;        &lt;tr&gt;            &lt;td&gt;&lt;span style="color:green;"&gt;//  Normal debugging shader&lt;/span&gt;&lt;span style="font-size:11px;"&gt; &lt;/span&gt;&lt;/td&gt;        &lt;/tr&gt;        &lt;tr&gt;            &lt;td&gt;&lt;span style="color:green;"&gt;//////////////////////////////////////////////////&lt;/span&gt;&lt;span style="font-size:11px;"&gt; &lt;/span&gt;&lt;/td&gt;        &lt;/tr&gt;        &lt;tr&gt;            &lt;td&gt; &lt;/td&gt;        &lt;/tr&gt;        &lt;tr&gt;            &lt;td&gt;&lt;span style="color:blue;"&gt;struct&lt;/span&gt;&lt;span style="font-size:11px;"&gt; VertexIn &lt;/span&gt;&lt;/td&gt;        &lt;/tr&gt;        &lt;tr&gt;            &lt;td&gt;{ &lt;/td&gt;        &lt;/tr&gt;        &lt;tr&gt;            &lt;td&gt;    float4 position  : POSITION0; &lt;/td&gt;        &lt;/tr&gt;        &lt;tr&gt;            &lt;td&gt;    float2 texCoords : TEXCOORD0; &lt;/td&gt;        &lt;/tr&gt;        &lt;tr&gt;            &lt;td&gt;    float3 normal    : NORMAL0;     &lt;/td&gt;        &lt;/tr&gt;        &lt;tr&gt;            &lt;td&gt;    float3 tangent   : TANGENT0; &lt;/td&gt;        &lt;/tr&gt;        &lt;tr&gt;            &lt;td&gt;    float3 binormal  : BINORMAL0; &lt;/td&gt;        &lt;/tr&gt;        &lt;tr&gt;            &lt;td&gt;}; &lt;/td&gt;        &lt;/tr&gt;        &lt;tr&gt;            &lt;td&gt; &lt;/td&gt;        &lt;/tr&gt;        &lt;tr&gt;            &lt;td&gt;&lt;span style="color:blue;"&gt;struct&lt;/span&gt;&lt;span style="font-size:11px;"&gt; VertexToPixelBuggedNormal &lt;/span&gt;&lt;/td&gt;        &lt;/tr&gt;        &lt;tr&gt;            &lt;td&gt;{ &lt;/td&gt;        &lt;/tr&gt;        &lt;tr&gt;            &lt;td&gt;    float4 position      : POSITION;     &lt;/td&gt;        &lt;/tr&gt;        &lt;tr&gt;            &lt;td&gt;    float2 texCoords     : TEXCOORD0; &lt;/td&gt;        &lt;/tr&gt;        &lt;tr&gt;            &lt;td&gt;    float3 viewVector    : TEXCOORD1; &lt;/td&gt;        &lt;/tr&gt;        &lt;tr&gt;            &lt;td&gt;    float3 normal        : TEXCOORD2; &lt;/td&gt;        &lt;/tr&gt;        &lt;tr&gt;            &lt;td&gt;     &lt;/td&gt;        &lt;/tr&gt;        &lt;tr&gt;            &lt;td&gt;    float3x3 tangentToWorld : TEXCOORD3; &lt;/td&gt;        &lt;/tr&gt;        &lt;tr&gt;            &lt;td&gt;}; &lt;/td&gt;        &lt;/tr&gt;        &lt;tr&gt;            &lt;td&gt; &lt;/td&gt;        &lt;/tr&gt;        &lt;tr&gt;            &lt;td&gt;VertexToPixelBuggedNormal BuggedNormalVertexShader(VertexIn input) &lt;/td&gt;        &lt;/tr&gt;        &lt;tr&gt;            &lt;td&gt;{ &lt;/td&gt;        &lt;/tr&gt;        &lt;tr&gt;            &lt;td&gt;    VertexToPixelBuggedNormal output = (VertexToPixelBuggedNormal)0; &lt;/td&gt;        &lt;/tr&gt;        &lt;tr&gt;            &lt;td&gt; &lt;/td&gt;        &lt;/tr&gt;        &lt;tr&gt;            &lt;td&gt;    output.position = mul(input.position, CameraTransform); &lt;/td&gt;        &lt;/tr&gt;        &lt;tr&gt;            &lt;td&gt;     &lt;/td&gt;        &lt;/tr&gt;        &lt;tr&gt;            &lt;td&gt;    output.texCoords = input.texCoords; &lt;/td&gt;        &lt;/tr&gt;        &lt;tr&gt;            &lt;td&gt;     &lt;/td&gt;        &lt;/tr&gt;        &lt;tr&gt;            &lt;td&gt;    output.normal = normalize(mul(float4(input.normal,1.0f), WorldTransform)); &lt;/td&gt;        &lt;/tr&gt;        &lt;tr&gt;            &lt;td&gt;     &lt;/td&gt;        &lt;/tr&gt;        &lt;tr&gt;            &lt;td&gt;    output.viewVector = -(DirectionalLightDirection.xyz*50) - mul(input.position, WorldTransform); &lt;/td&gt;        &lt;/tr&gt;        &lt;tr&gt;            &lt;td&gt;     &lt;/td&gt;        &lt;/tr&gt;        &lt;tr&gt;            &lt;td&gt;    output.tangentToWorld[0] = mul(float4(input.tangent,1.0f),WorldTransform).xyz; &lt;/td&gt;        &lt;/tr&gt;        &lt;tr&gt;            &lt;td&gt;    output.tangentToWorld[1] = mul(float4(input.binormal,1.0f),WorldTransform).xyz; &lt;/td&gt;        &lt;/tr&gt;        &lt;tr&gt;            &lt;td&gt;    output.tangentToWorld[2] = mul(float4(input.normal,1.0f), WorldTransform).xyz; &lt;/td&gt;        &lt;/tr&gt;        &lt;tr&gt;            &lt;td&gt;             &lt;/td&gt;        &lt;/tr&gt;        &lt;tr&gt;            &lt;td&gt;    &lt;span style="color:blue;"&gt;return&lt;/span&gt;&lt;span style="font-size:11px;"&gt; output; &lt;/span&gt;&lt;/td&gt;        &lt;/tr&gt;        &lt;tr&gt;            &lt;td&gt;} &lt;/td&gt;        &lt;/tr&gt;        &lt;tr&gt;            &lt;td&gt; &lt;/td&gt;        &lt;/tr&gt;        &lt;tr&gt;            &lt;td&gt;PixelToFrame BuggedNormalPixelShader(VertexToPixelBuggedNormal input) &lt;/td&gt;        &lt;/tr&gt;        &lt;tr&gt;            &lt;td&gt;{ &lt;/td&gt;        &lt;/tr&gt;        &lt;tr&gt;            &lt;td&gt;    PixelToFrame output = (PixelToFrame)0;         &lt;/td&gt;        &lt;/tr&gt;        &lt;tr&gt;            &lt;td&gt; &lt;/td&gt;        &lt;/tr&gt;        &lt;tr&gt;            &lt;td&gt;    &lt;span style="color:green;"&gt;// clean up our inputs a bit&lt;/span&gt;&lt;span style="font-size:11px;"&gt; &lt;/span&gt;&lt;/td&gt;        &lt;/tr&gt;        &lt;tr&gt;            &lt;td&gt;    input.viewVector = normalize(input.viewVector); &lt;/td&gt;        &lt;/tr&gt;        &lt;tr&gt;            &lt;td&gt; &lt;/td&gt;        &lt;/tr&gt;        &lt;tr&gt;            &lt;td&gt;    &lt;span style="color:green;"&gt;// bump map&lt;/span&gt;&lt;span style="font-size:11px;"&gt; &lt;/span&gt;&lt;/td&gt;        &lt;/tr&gt;        &lt;tr&gt;            &lt;td&gt;    float3 bumpNorm = (2 * (tex2D(BumpSampler, input.texCoords).rgb-0.5f)); &lt;/td&gt;        &lt;/tr&gt;        &lt;tr&gt;            &lt;td&gt;    bumpNorm = normalize(mul(bumpNorm,input.tangentToWorld)); &lt;/td&gt;        &lt;/tr&gt;        &lt;tr&gt;            &lt;td&gt;         &lt;/td&gt;        &lt;/tr&gt;        &lt;tr&gt;            &lt;td&gt;    &lt;span style="color:green;"&gt;// directional light&lt;/span&gt;&lt;span style="font-size:11px;"&gt; &lt;/span&gt;&lt;/td&gt;        &lt;/tr&gt;        &lt;tr&gt;            &lt;td&gt;    float4 DirectionalLighting = (dot(bumpNorm, input.viewVector)) * DirectionalLightColor; &lt;/td&gt;        &lt;/tr&gt;        &lt;tr&gt;            &lt;td&gt; &lt;/td&gt;        &lt;/tr&gt;        &lt;tr&gt;            &lt;td&gt;    &lt;span style="color:green;"&gt;// base color    &lt;/span&gt;&lt;span style="font-size:11px;"&gt; &lt;/span&gt;&lt;/td&gt;        &lt;/tr&gt;        &lt;tr&gt;            &lt;td&gt;    float4 baseColor = tex2D(TextureSampler, input.texCoords); &lt;/td&gt;        &lt;/tr&gt;        &lt;tr&gt;            &lt;td&gt; &lt;/td&gt;        &lt;/tr&gt;        &lt;tr&gt;            &lt;td&gt;    &lt;span style="color:green;"&gt;// adjust for lighting&lt;/span&gt;&lt;span style="font-size:11px;"&gt; &lt;/span&gt;&lt;/td&gt;        &lt;/tr&gt;        &lt;tr&gt;            &lt;td&gt;    baseColor.xyz *= saturate(DirectionalLighting + AmbientColor).xyz; &lt;/td&gt;        &lt;/tr&gt;        &lt;tr&gt;            &lt;td&gt;     &lt;/td&gt;        &lt;/tr&gt;        &lt;tr&gt;            &lt;td&gt;    output.Color = baseColor; &lt;/td&gt;        &lt;/tr&gt;        &lt;tr&gt;            &lt;td&gt; &lt;/td&gt;        &lt;/tr&gt;        &lt;tr&gt;            &lt;td&gt;    &lt;span style="color:blue;"&gt;return&lt;/span&gt;&lt;span style="font-size:11px;"&gt; output;  &lt;/span&gt;&lt;/td&gt;        &lt;/tr&gt;        &lt;tr&gt;            &lt;td&gt;} &lt;/td&gt;        &lt;/tr&gt;        &lt;tr&gt;            &lt;td&gt; &lt;/td&gt;        &lt;/tr&gt;        &lt;tr&gt;            &lt;td&gt;technique BuggedNormal &lt;/td&gt;        &lt;/tr&gt;        &lt;tr&gt;            &lt;td&gt;{ &lt;/td&gt;        &lt;/tr&gt;        &lt;tr&gt;            &lt;td&gt;    pass Pass0 &lt;/td&gt;        &lt;/tr&gt;        &lt;tr&gt;            &lt;td&gt;    { &lt;/td&gt;        &lt;/tr&gt;        &lt;tr&gt;            &lt;td&gt;         VertexShader = compile vs_2_0 BuggedNormalVertexShader(); &lt;/td&gt;        &lt;/tr&gt;        &lt;tr&gt;            &lt;td&gt;         PixelShader = compile ps_2_0 BuggedNormalPixelShader(); &lt;/td&gt;        &lt;/tr&gt;        &lt;tr&gt;            &lt;td&gt;    } &lt;/td&gt;        &lt;/tr&gt;        &lt;tr&gt;            &lt;td&gt;} &lt;/td&gt;        &lt;/tr&gt;        &lt;tr&gt;            &lt;td&gt; &lt;/td&gt;        &lt;/tr&gt;    &lt;/table&gt;&lt;/div&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span&gt;Thanks for any help you can offer!&lt;/span&gt;&lt;/div&gt;</description></item></channel></rss>