Original Post
Hi everyone.
I'm working on a simple shader to make a normal mapping effect to use with the graphics engine I'm currently on.
This shader computes lighting that comes from a single point light (with att and a single diffuse color). The material is composed of a diffuse texture, a specular map and a normal map (the famous "blue map").
The shader seems top work, but only approximately.
I got an issue with the specular lighting that behaves in a verry weired way.
So I wish to know if my theory of the normal mapping is correct :
- In VShader, send as output the transformed position, the local position, the tangent, binormal and normal values, and the texture coordinates
- In PShader, create a vector from local pos to local light pos, transform it using TBN (from values we get of the VShader) and normalize it. Idem for the vector from local pos to camera pos. Then, compute Halfway vector by adding the two first vectors and then normalize. Sample normal map using texture coordinate off from the rasterizer (normalizing is not necessaray?). Compute lighting using sampled normal and transformed/normalized vectors (with lit function).
Compute color using diffuse and specular map, and draw pixel.
To get the normal from the normal map, we have to do like this :
(Tex2D(map_normal, In.uv) - 0.5f) * 2.0f
Is that all right? I send you the shader when I come back home this evening (I'm GMT+1 here, so in the afternoon for US people)
Thanks in advance.
@xi@g@me
I'm working on a simple shader to make a normal mapping effect to use with the graphics engine I'm currently on.
This shader computes lighting that comes from a single point light (with att and a single diffuse color). The material is composed of a diffuse texture, a specular map and a normal map (the famous "blue map").
The shader seems top work, but only approximately.
I got an issue with the specular lighting that behaves in a verry weired way.
So I wish to know if my theory of the normal mapping is correct :
- In VShader, send as output the transformed position, the local position, the tangent, binormal and normal values, and the texture coordinates
- In PShader, create a vector from local pos to local light pos, transform it using TBN (from values we get of the VShader) and normalize it. Idem for the vector from local pos to camera pos. Then, compute Halfway vector by adding the two first vectors and then normalize. Sample normal map using texture coordinate off from the rasterizer (normalizing is not necessaray?). Compute lighting using sampled normal and transformed/normalized vectors (with lit function).
Compute color using diffuse and specular map, and draw pixel.
To get the normal from the normal map, we have to do like this :
(Tex2D(map_normal, In.uv) - 0.5f) * 2.0f
Is that all right? I send you the shader when I come back home this evening (I'm GMT+1 here, so in the afternoon for US people)
Thanks in advance.
@xi@g@me