I was working on my engine and while implementing post processing a very weird bug appeared. It seems to come from the Z-Test but I can't firgure out what exactly it is hapening

First of all here's the bug. Weird bug that I talk about

Now I will detail how my engine render thing

  • First it compute shadow maps for dynamics lights
  • Next it renders the G-Buffer (deffered rendering)
    • Rendering scene in multiple textures
    • Assembling thsese textures and applying shadow & lights
    • (If there are) Render post processing effects, it takes the texture produced by the step above (Light pass)and pass it through one or more shaders to modify texture's content. If I disable post processing the bug doesn't disapears so it may not come from here
  • After that it renders GUI texture (if there are GUI)
  • And then it renders "Beauty" combining GUI texture and Post Processed/Light Pass

This is how the Light shader is made (I didn't put it all, because it was too long).

#version 410 core
layout (location = 5) out vec4 LightPass;

/* . . . */

void main() {
    vec3 diffSpec = vec3(0.0);

    float shadow = texture(ShadowPass, UVcoords).r;

    if(ftr_lighting) {
        for(int i = 0; i < nbrDirLight; i++) {
            diffSpec += CalcDirLight(i) * shadow;

        for(int i = 0; i < nbrPointLight; i++) {
            diffSpec += CalcPointLight(i);

    vec3 ambient = AmbientColor * AmbientStrength;
    vec3 result = (diffSpec + ambient);

    vec4 gamma = vec4(1.0 / 2.2);

    //vec4 gui = texture(GUIscreen, UVcoords);

    vec4 render = clamp(pow(vec4(Diffuse, 1.0) * vec4(result, 1.0), gamma), 0.0, 1.0);

    LightPass = render;

(Just in case of full shader is here https://github.com/Moi78/ExpansionGameEngine/blob/master/src/ExGame/Engine/Shaders/glsl/Light.frag)

Note that the bug only appears in the bottom left corner...

If you have any idea what's happening id'love to hear it.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.