• Create Account

## HLSL Phong Lightning (/w normal map)

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

2 replies to this topic

### #1pulo  Members

272
Like
0Likes
Like

Posted 23 June 2012 - 06:21 AM

I am starting to learn some HLSL Shading with DirectX10 and I have tried to use a normal map to calculate my phong lightning.
First off here is an example of how far I have come:

http://i.stack.imgur.com/IFAo4.jpg

I am not quite sure if this is what im looking to accomplish with this normal map:
http://i.stack.imgur.com/moQvf.jpg

I dont know..shouldn't this look more 3Dish? Maybe I have just an false understanding of the usage of a normal map, but in my mindset a normal map is used to make a model more detailed by adding shadows based on the normal map, so its looks more 3D ish.
Here is a screenshot without using the normal map:

i.stack.imgur.com/eJ8OZ.jpg

And here is my shading code:

    T3dVertexPSIn MeshVS(T3dVertexVSIn Input) {
T3dVertexPSIn output = (T3dVertexPSIn) 0;
float4 tempVar;

output.Pos = mul(float4(Input.Pos.xyz, 1).xyzw, g_WorldViewProjection);

output.Tex = Input.Tex;

tempVar = mul(float4(Input.Pos.xyz, 1).xyzw, g_WorldView);
output.PosView = tempVar.xyz;

tempVar = mul(float4(Input.Nor.xyz, 0).xyzw, g_WorldViewNormals);
output.NorView = tempVar.xyz;
output.NorView = normalize(output.NorView);

tempVar = mul(float4(Input.Tan.xyz, 0).xyzw, g_WorldViewNormals);
output.TanView = tempVar.xyz;
output.TanView = normalize(output.TanView);

return output;
}

    float4 MeshPS(T3dVertexPSIn Input) : SV_Target0 {
float4 output = (float4)0; //output color

float3 N = normalize(Input.NorView);

float3 T = Input.TanView;

T = normalize(T - N * dot(N,T));
float3 B = cross(T,N);

column_major float3x3 mTBN= {T, B, N};
float4 matDiffuse = g_Diffuse.Sample(samAnisotropic, Input.Tex);
float4 matSpecular = g_Specular.Sample(samAnisotropic, Input.Tex);
float4 matGlow = g_Glow.Sample(samAnisotropic, Input.Tex);
float4 colLight = float4(1,1,1,1);
float4 colLightAmbient = float4(1,1,1,1);
float3 n = mul(g_Normal.Sample(samAnisotropic, Input.Tex).rgb * 2.0 - 1.0, mTBN);
//float3 n = mul(float3x3(T,B,N), nT);
//float3 n = normalize(Input.NorView);
float4 I = g_LightDirView;
float3 r = reflect(-I.xyz, n);
float3 v = normalize(-Input.PosView);

float cd = 0.5f, cs = 0.3f, ca = 0.1f, cg = 0.3f;

output = cd*matDiffuse*saturate(dot(n,I.xyz))*colLight
+cs*matSpecular*pow(saturate(dot(r.xyz,v)),10)*colLight
+ca*matDiffuse*colLightAmbient
+cg*matGlow;

return output;
}

I also have the feeling that the lightning is changing direction when im using the normal map.but I am not sure.
Maybe someone can explain this matter to me a little bit.
Thanks in advance for any help!

### #2Panter  Members

189
Like
0Likes
Like

Posted 24 June 2012 - 06:05 AM

I've accomplished to implement the normal mapping in my engine right this week, i suggest you to read this:
http://www.rastertek.com/dx10tut20.html
and this:
http://www.bencloward.com/tutorials_normal_maps1.shtml

### #3pulo  Members

272
Like
0Likes
Like

Posted 24 June 2012 - 07:10 AM

Thanks i will. I was already able to get this a little bit further done, but i will def. read your suggestion.

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.