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.

• normals seems to be not ok Aug 20 '13 at 18:14
• What are you expecting it to look like? Aug 20 '13 at 18:23
• i thought it should look like a continuous red Aug 20 '13 at 18:26
• @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. Aug 20 '13 at 18:48