'How to prevent OpenGL/GLSL textures from blending when overlapping?

Currently, I have some textures that will be overlapping one another, for example :

enter image description here

However, when I apply lighting attenuation to it, texture seems to be blending together: enter image description here

I'm not sure if I'm applying the formula correctly. Enabling/Disabling glBlendFunc doesnt seem to work either. Do I need to apply depth testing here, or is there a way to play with texture opacity properly? For now I only need overlapping to be rendered, while "ignoring" the underlapping portion. Thanks!

My fragment shader looks like this:


layout (location=0) in vec3 vInterpColor;
layout(location=1) in vec2 vTexCoord;

//Lighting
uniform int numLights;
uniform float pLightArrX[32];
uniform float pLightArrY[32];
uniform float pLightArrRad[32];


uniform sampler2D uTex2d;

layout (location=0) out vec4 fFragColor;

void main () {
    float attenuation = 0.0f;
    for(int i = 0; i < numLights; i++){
        float distToLight = distance(gl_FragCoord.xy, vec2(pLightArrX[i], pLightArrY[i]));

        // linear attenuation
        if(pLightArrRad[i] > 0.f){
            float linearAttenuation = 1.0f - (distToLight/pLightArrRad[i]);
            if (linearAttenuation < 0.0f) {
                linearAttenuation = 0.0f;
            }
            attenuation += linearAttenuation;
        }
        
    }
    
    if (attenuation > 1.0f) {
        attenuation = 1.0f;
    }

    fFragColor = texture(uTex2d, vTexCoord) * attenuation;

} ```


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source