Jump to content

  • Log In with Google      Sign In   
  • Create Account

FREE SOFTWARE GIVEAWAY

We have 4 x Pro Licences (valued at $59 each) for 2d modular animation software Spriter to give away in this Thursday's GDNet Direct email newsletter.


Read more in this forum topic or make sure you're signed up (from the right-hand sidebar on the homepage) and read Thursday's newsletter to get in the running!


Deferred Point Lights position error [SOLVED]


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
2 replies to this topic

#1 csisy   Members   -  Reputation: 256

Like
0Likes
Like

Posted 26 July 2014 - 04:21 PM

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.

Attached Thumbnails

  • point_light_error.jpg

sorry for my bad english :)

Sponsor:

#2 semler   Members   -  Reputation: 258

Like
1Likes
Like

Posted 26 July 2014 - 05:39 PM

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



#3 csisy   Members   -  Reputation: 256

Like
0Likes
Like

Posted 27 July 2014 - 04:42 AM

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




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS