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:
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:
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:
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;
float depthVal = tex2D(depthS, texCoord).r;
//compute screen-space 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!
Edited by TJClifton, 13 September 2012 - 08:10 AM.