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:


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:


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