Normal Map Light Map

Hey guys, i have strange lighting problem. I've written my own "deferred lighting" shader and this happend:

  1. Pic: Normal-Map
  2. Pic: Light-Map

As long as i only use one big mesh everything seems okay, but this look pretty wrong.

Here is how i calculate the point light map (http://www.packtpub.com/article/advanced-lighting-3d-graphics-xna-game-studio-40):

float4 PixelShaderFunction(VertexShaderOutput input) : COLOR0
  // Find the pixel coordinates of the input position in the depth
  // and normal textures
  float2 texCoord = postProjToScreen(input.LightPosition) + halfPixel();
  // Extract the depth for this pixel from the depth map
  float4 depth = tex2D(depthSampler, texCoord);

  // Recreate the position with the UV coordinates and depth value
  float4 position;
  position.x = texCoord.x * 2 - 1;
  position.y = (1 - texCoord.y) * 2 - 1;
  position.z = depth.r;
  position.w = 1.0f;

  // Transform position from screen space to world space
  position = mul(position, InvViewProjection);
  position.xyz /= position.w;
  position.w = 1;

  // Extract the normal from the normal map and move from
 // 0 to 1 range to -1 to 1 range
 float4 normal = (tex2D(normalSampler, texCoord) - .5) * 2;

 // Perform the lighting calculations for a point light
 float3 lightDirection = normalize(LightPosition - position);
 float lighting = clamp(dot(normal, lightDirection), 0, 1);

 // Attenuate the light to simulate a point light
 float d = distance(LightPosition, position);
 float att = 1 - pow(d / LightAttenuation, LightFalloff);

 // Calculate the specular Component
 float3 R = normalize(2 * max(0,dot(normal, lightDirection)) * normal - lightDirection);
 float4 specularComponent = pow(saturate(dot(R, normalize(CameraPosition - position.xyz))), LightShininess);

 return float4(LightColor * att * lighting  + LightColor * att * specularComponent, 1);

I don't really know why, but Blender is the root problem here; causing the exact same issue. I would appreciate any tip to solve that problem.

  • 1
    \$\begingroup\$ normals seems to be not ok \$\endgroup\$
    – Vodáček
    Aug 20 '13 at 18:14
  • \$\begingroup\$ What are you expecting it to look like? \$\endgroup\$
    – Steve H
    Aug 20 '13 at 18:23
  • 1
    \$\begingroup\$ i thought it should look like a continuous red \$\endgroup\$ Aug 20 '13 at 18:26
  • \$\begingroup\$ @PhilippSchladitz: As per the Vodáček's comment: if you have a flat plane, it should be obvious that it should have a uniform normal across that plane. Your normal map image indicates that your normal calculation is either entirely broken or that your input geometry is wrong. That's your primary problem, not the chunk of code you posted. \$\endgroup\$ Aug 20 '13 at 18:48
  • \$\begingroup\$ @PhilippSchladitz If you have an update to your question, edit the original question. The answers section is for answers only. \$\endgroup\$
    – House
    Aug 20 '13 at 21:23

It looks like your geometry may be made of unwelded boxes and you're using smoothed normals (soft edges). If my guess is correct, then the lighting looks off because the smoothed normals point outward from the corner of each box and therefore don't match the flat surface created when you place two boxes next to each other.

Try using unsmoothed normals (hard edges). You can look up in the Blender help files how to set this.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.