Jump to content
  • Advertisement
Sign in to follow this  

[DX10] Deferred rendering incorrect lighting

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

If you intended to correct an error in the post then please contact us.

Recommended Posts

I'm more or less finished setting up render targets and stuff so I decided to add some lights. Well, here is the problem: some sides of the cube get shaded correctly but some not - the camera is not always in the same position in the following pictures: free image host Here is the normal texture from the G-buffer (the other 3 sides of the big cube are naturally black since its axis aligned): free image host This picture shows the distance between the world position and the camera eye (the_world_position_texture_in_the_g_buffer-camera_eye) (scaled so it can be represented in colors): free image host This one also shows THE world position free image host Here is the pixel shader code that does the lighting:
	// Get normal from normal texture in the G-buffer
	float3 normal=2.0f*texNormal.Sample(pointss,input.texcoord)-1.0f;

	// Get depth from depth texture
	float depth=texDepth.Sample(pointss,input.texcoord);

	// Get world position of this pixel by using the inverse of the ViewProj matrix and the depth
	float4 worldPosition;
	worldPosition.z= depth;
	// Test light position
	float3 lightPos=float3(0.0f,3.0f,0.0f);
	// Calculate lighting
	float power=saturate(dot(normalize(lightPos-worldPosition),normal));
	// Simple attenuation
	float att=1.0f / (length(lightPos-worldPosition)/2.8f);
	// Return powet*attenuation
	return float4(power,power,power,1.0f)*att;

Any ideas?

Share this post

Link to post
Share on other sites
I can't say for sure, but something about your normals doesn't look quite right. Are they in world space or object space?

Make sure you are transforming them into world space, because your lighting calculations are in world space....

Share this post

Link to post
Share on other sites
I've solved the problem :P I automatically write float3 normal=2*normalTexture-1.0f since it was read from a texture but I forgot it's alread in -1,1 range...

Thanks for your help anyway, the normals are fine, they just look like that since the box is axis aligned.

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!