Need help with HLSL bump mapping

Started by
13 comments, last by MJP 16 years ago
Nope, thats not the problem, I've tryed even with the normal map:
float3 normal = 2.0f * tex2D(Sampler1, IN.texture0).rgb - 1.0f;

But the problem remains the same, as it rotates the object gets brighter and then returns to normal, it must be somewhere else, it seems like a problem of vector normalization, but I'm 100% sure that everything is normalized. Maybe I'm building the matrices in the wrong way?
Advertisement
Try changing in your vertex shader, this:

//change thisOUT.light = normalize(mul(WTTS, lightDirection));//to thisOUT.light = mul(WTTS, lightDirection);//then in your fragment.normalize(IN.light);//you might need to do -IN.light for a directional, I'm not sure on that though.


Also, are you setting your mesh correctly in your code? It needs to have Bi/Tang etc.
-...-Squeeged third eye.
If you are not setting your mesh correctly with tangents then your lighting will look wrong. Try looking into D3DXComputeTangentFrameEx .

Also, you are going to want to change your normal equation to tex2D(normalMap, texcoord) * 2.0f - 1.0f. You want to do this because of the range of points. A normal goes from -1 to 1 and a texture coordinate only goes from 0 to 1. Multiplying by 2, then subtracting one (the difference) will give you the correct normal. If you do not do this it could also cause your lighting to be wrong.
Yep I started to think it was a problem with my mesh, now I'm at uni, as soon as I get home I'll control if my mesh has tangents correctlz computed.
If you need to see an example of computing binormals and tangents for a mesh at load time, check out the Parallax Occlusion Mapping sample in the SDK.

This topic is closed to new replies.

Advertisement