This topic is 2793 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

hello everyone,

I have a problem with a normal map, I have a heightmap:

http://img406.imageshack.us/img406/6180/heightmap01.th.png

and normalmap:

http://img833.imageshack.us/img833/1265/normalmap.th.png

So I use the RGB channels to define the normal at a pixel, but it doesn't work.

 Texture2D t:register(t0); Texture2D normalmap:register(t1); SamplerState s:register(s0); cbuffer ConstantBuffer{ Matrix mFull; float4 lightDirection; float4 ambientColor; float4 diffuseColor; float2 sizeMap; }; .... .... .... float4 PSmain( PSin Pin ) : SV_Target { float4 color; float4 nMap=normalmap.Sample(s,Pin.tex); float3 lightDir; float lightIntensity; // Set the default output color to the ambient light value for all pixels. color = ambientColor; // Invert the light direction for calculations. lightDir = -lightDirection; // Calculate the amount of light on this pixel. lightIntensity = saturate(dot(nMap.xyz, lightDir)); if(lightIntensity > 0.0f) { // Determine the final diffuse color based on the diffuse color and the amount of light intensity. color += (diffuseColor * lightIntensity); } // Saturate the final light color. color*=t.Sample(s,Pin.tex*8); color = saturate(color); return color; }; 

##### Share on other sites
Hi,

Can you elaborate on what your current result is? (What’s wrong with it? What happens / does not happen?)

Normal maps store the normals in tangent space. Usually you have to transform the normals by the TBN matrix from tangent space to object space and then via world matrix to world space before you can do any lighting calculations. The TBN (=tangent, binormal, normal) matrix defines a coordinate system at each vertex. You can precompute the tangent and include it (along with your normal) in the vertex buffer or you can compute it on-the-fly.

Besides, normal maps store the normals usually with a scale-bias.
So the tangent space normal would be:
float3 nMap=normalmap.Sample(s,Pin.tex).rgb * 2.0 – 1.0;

Cheers!

##### Share on other sites
In my opinion, In this particular case the tangent space and the world space are the same. For that reason you don't have to worry about the tangent space and you don't need the TBN matrix. If you had a detail normal map which would repeat over the terrain, you'd need to calculate the TBN matrix.

Just read the normal from the texture as suggested by Tsus and you should be fine.

Best regards!

##### Share on other sites
Thx, i resolve this problem i don't know how lol but i resolve it!

• ### Game Developer Survey

We are looking for qualified game developers to participate in a 10-minute online survey. Qualified participants will be offered a \$15 incentive for your time and insights. Click here to start!

• 11
• 15
• 21
• 26
• 11