PDA

View Full Version : Lighting don't work properly with deffered rendering



RobertBerg
05-14-2015, 10:35 AM
Hello, I have a problem I tried to solve but it have passed around 2 months and I still whasn't able to solve it, When I moved the lighting calculations in the final shader of the gbuffer it seems it does not work properly:
http://i.imgur.com/9eTSJp2.png

As you can see the problem is that the lighting creates something that looks like squares on the plane with strange relatively hard transition, another problem is that the lighting is the same even when I change the position of the objects, The only thing that affects it is the rotation and position of light, so it seems to me like the positions are wrong but not the rotation, I send the positions using a sampler2d xyz->rgb this is how they look if I visualize them:
http://i.imgur.com/OPcORIf.png

I am almost certain the positions are the problem, this is what the texture is:

postexture = vec4(M * vec4(position, 1.0));

And this is the calculation in the final shader:

vec3 fpos = texture(positiontex, pos).xyz;
...
vec3 surfaceToLight = light.position - fpos;
float brightness = dot(norm, surfaceToLight) / (length(surfaceToLight) * length(norm));
brightness = clamp(brightness, 0.2, 1);
...

Please help me pass through this problem :)

RobertBerg
05-15-2015, 12:15 PM
Can someone help me please ?

dorbie
05-15-2015, 12:40 PM
Based on your image I'd say your positions are clamping at 0.0-1.0, with a narrow transition area.

You also seem to be storing world positions not something light space position prior to your position buffer write.

So try float buffers or some other extended range and precision format and try performing a partial lighting position offset prior to writing tor position.

Of course the position thing depends heavily on your deferred shader work but it makes sense to calculate what you can at high precision prior to your intermediate buffer write that might for example use a HALF format.