• Advertisement
Sign in to follow this  

Deferred Point Lights position error [SOLVED]

This topic is 1275 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

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.

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites

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! :)

Share this post


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

  • Advertisement