Jump to content

  • Log In with Google      Sign In   
  • Create Account

We need your help!

We need 7 developers from Canada and 18 more from Australia to help us complete a research survey.

Support our site by taking a quick sponsored survey and win a chance at a $50 Amazon gift card. Click here to get started!


Member Since 13 Sep 2012
Offline Last Active Sep 18 2012 10:47 AM

Topics I've Started

Point Light Issue With Deferred Rendering

13 September 2012 - 07:04 AM

I've been working on a deferred rendering system (based on this excellent XNA tutorial) and all has been going largely well.

However I have hit a snag with point lights. I have followed the code almost exactly (except where I have had to use DX methods instead of the XNA ones in the tutorial) but I just can't seem to get it to work. I understand the theory and I am sure that I am doing something stupid but I just can't figure it out. It has been a couple of days now and nothing I try seems to work. To illustrate the problem here's a screen capture of the problem:

Posted Image

As you can see all the pixels in the sphere are being lit equally - it does not fade out at the edges. From my understanding, the attenuation should deal with this, making light weaker at the edges of the sphere and stronger at the origin of the point source.

However I am using the exact same equations as in the XNA tutorial and cannot see why it is not working for me.

Unfortunately I only have access to the computers at my university at the moment and cannot turn on some of the debug features as I don't have the administrator privileges, so I don't have the luxury of using some of the shader debugging features in PIX.

I have tried outputting the attenuation to the red channel in the pixel shader though and came up with this:

Posted Image

Does this look right? To me this looks like the attenuation is the same for every pixel in the sphere which should not be right. They all seem to be getting the maximum amount of light until it reaches the edge of the sphere where it cuts off suddenly because those pixels are not being lit.

If anyone has any insight on this problem it would be greatly appreciated! I can post my code if needed but as I say it's identical really to that in the tutorial I linked above.



I have outputted the screen position information that gets input into the pixel shader and I get this:

Posted Image

This looks right to me which makes me think that my problem may lie with calculating the world position from the screen position. The code I have for that at the moment is:

//obtain screen position
input.ScreenPosition.xy /= input.ScreenPosition.w;

//obtain textureCoordinates corresponding to the current pixel and align to pixels
float2 texCoord = 0.5f * (float2(input.ScreenPosition.x,-input.ScreenPosition.y) + 1);
texCoord -= gHalfPixel;

//get depth
float depthVal = tex2D(depthS, texCoord).r;

//compute screen-space position
float4 position;
position.xy = input.ScreenPosition.xy;
position.z = depthVal;
position.w = 1.0f;

//transform to world space
position = mul(position, gInvViewProjection);
position /= position.w;

Again any help would be greatly appreciated!