Quote:Original post by RobMaddisonI thought you just got shading per-pixel by using pixel shaders.
No, it doesn't work this way, because the quality of the normal is what's ultimately important. Here you are just taking the per-vertex normal from the pixel shader and doingto dot product in the pixel shader.
What you need is a per-pixel normal, usually this involves a normal map which gives a much more detailed normal very cheaply, but you don't have to use one.
Here is what you generally do:
1) Make sure your mesh vertices have a precalculated tangent vector.
2) in the pixel shader create a tangent-binormal-normal matrix:
half3x3 worldToTangentSpace;
worldToTangentSpace[0] = mul(in.tangent, matWorld);
worldToTangentSpace[1] = mul(cross(in.normal,in.tangent), matWorld);
worldToTangentSpace[2] = mul(in.normal, matWorld);
3) transform your light and output
Out.light.xyz = mul(worldToTangentSpace, vecSunDir);
4) In the PIXEL SHADER normalize this light vector...the normalization is important:
float3 Sun=normalize(In.light);
5) then do your dot product...you can use a normal map like this:
float3 normalmap=tex2D(normalsamp,intex.xy)*2-1;
float diffuse=saturate(dot(normalmap,Sun));
If you dont want a normal map just use a flat normal like
float3 normalmap=float3(0.5,0.5,1)*2-1;
---------------------------------------------------------------------------
Note: for a much simpler method without a normal map, I THINK you can do this; dont bother with the tangent stuff; just renormalize the normal in the pixel shader and then do the dot product... you should get reasonable per-pixel lighting.