Another topic from me
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 = 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.