Deferred Point Lights position error [SOLVED]

Started by
1 comment, last by csisy 9 years, 8 months ago

Hi,

Another topic from me smile.png

I've just discovered that the position reconstruction is not completely fine in my deferred renderer. Here is the steps I'm doing:

- render gbuffer -> albedo, normals, viewspace depth (32 bit float texture)

- for each point light

- render a sphere geometry (which is a littlebit larger than the radius of the light)

- the cull mode is always CW, so I'm drawing the backfaces only

- position reconstruction is done in the fragment shader by: eyePosition + eyeRay * depth

- eyeRay is computed in the vertex shader using an eye correction (described here)

The problem comes when the camera intersects the sphere geometry. The reconstructed position inside the sphere is okay, but at the edge, I get something wierd. This means the attenuation calculation is wrong, and the objects will be lit outside of the sphere.

Here is the shader:


// in the vertex shader

varying     vec3    EyeRay;

uniform     vec3    eyePosition;
uniform     float   farPlane;
uniform     vec3    cameraFront;

[...]

vec3 eyeRay = normalize(worldPos.xyz - eyePosition);
float eyeCorrection = farPlane / dot(eyeRay, cameraFront);
EyeRay = eyeRay * eyeCorrection;

// in the fragment shader

vec2 screenPos = ScreenPos.xy / ScreenPos.w;
vec2 Texcoord = 0.5 * (screenPos + 1.0);

float depthVal = texture2D(textDepth, Texcoord).r;

// get world position
vec3 wPosition = eyePosition + EyeRay * depthVal;

gl_FragData[0] = vec4(wPosition, 1.0);

The result is attached. You can see the green area at the edge of the sphere. I don't know if the stencil-optimization would resolve this problem, but it should work without it.

sorry for my bad english
Advertisement

Your eye ray is interpolated linearly, you need to move the calculation into the fragment shader, ie. send over the worldposition.xyz to the fragment shader.

Henning

Your eye ray is interpolated linearly, you need to move the calculation into the fragment shader, ie. send over the worldposition.xyz to the fragment shader.

Henning

Wow, and really... :) I don't know why I put it into the vertex shader at all. It was in the fragment shader at the first time, probably I wanted to optimize a littlebit, and I didn't test it. I know, these are just excuses. :D

Anyway, thank you! :)

sorry for my bad english

This topic is closed to new replies.

Advertisement