   [HLSL] Trouble With Specular Lighting
  I'm trying to create a shader for a shiny car, so I figured I'd start with specular lighting. I'd never done this before; just diffuse lighting. The specular lighting seems to not be working correctly. The things that stick out is that most of the specular highlights appear towards the bottom of my teapot, though my light is at (100, 100, 100). Another problem is a whitewash that happens at certain angles. I'm using RenderMonkey to program this. Does anyone have any idea what's going on?Here are a couple screenshots of my problem:Here are the constants for the effect (except for the colors. the baseColor is purple, then specular is white, diffuse is light grey, and ambient is dark grey):float4x4 matViewProjection : VIEWPROJECTION;float4x4 matWorld : WORLD;float4 vViewPosition : VIEWPOSITION;float3 lightPosition = (100, 100, 100)float specularPower = 8;Here's the code for my vertex shader and pixel shader:float4x4 matViewProjection;float4x4 matWorld;float3 lightPosition;float4 vViewPosition;struct VS_INPUT {   float4 Position : POSITION0;   float3 Normal : NORMAL0;};struct VS_OUTPUT {   float4 Position : POSITION0;   float3 Light : TEXCOORD1;   float3 Normal : TEXCOORD2;   float3 View : TEXCOORD3;};VS_OUTPUT vs_main( VS_INPUT Input ){   VS_OUTPUT Output;   Output.Position = mul( matViewProjection, Input.Position );   Output.Normal = mul( matWorld, Input.Normal );   Output.Light = normalize( Output.Position - lightPosition ); float3 posWorld = normalize( mul( matWorld, Input.Position ) );   Output.View = vViewPosition - posWorld; return( Output );   }float4 baseColor;float4 lightAmbient;float4 lightDiffuse;float4 lightSpecular;float specularPower;struct PS_INPUT{   float3 Light : TEXCOORD1;   float3 Normal : TEXCOORD2;   float3 View : TEXCOORD3;};float4 ps_main( PS_INPUT Input ) : COLOR0{   float3 normal = normalize( Input.Normal );   float3 lightDir = normalize( Input.Light );   float3 viewDir = normalize( Input.View ); float4 NdotL = saturate( max( 0, dot( normal, lightDir ) ) );   float3 reflection = normalize( 2 * NdotL * normal - lightDir );   float4 RdotV = saturate( max( 0, dot( reflection, viewDir ) ) ); float4 ambient = baseColor * lightAmbient;   float4 diffuse = baseColor * lightDiffuse * NdotL;   float4 specular = pow( RdotV, specularPower ); return ambient + diffuse + specular;   }
  Its is treating all of your matrices as being in column major order, because it is doing Matrix * Vector.  So, you will need to transpose the matrices before feeding them into the shader, or change the shader to do mul(vector, matrix).That is just a typical Phong shading effect by the way.  It should work.  You can also play with the specular power variable to determine its effect.   ;  I was just wondering why you wrote this line "float3 posWorld = normalize( mul( matWorld, Input.Position ) );". I mean, why are you normalizing your world space position?   ;Quote:Original post by DXnutIts is treating all of your matrices as being in column major order, because it is doing Matrix * Vector.  So, you will need to transpose the matrices before feeding them into the shader, or change the shader to do mul(vector, matrix).That definitely just messed more things up. Now my teapot is all exploded all over the place. Isn't DirectX column-major anyway?   