Skip to main content
1 of 2
Alayric
  • 291
  • 1
  • 2
  • 11

The normal color of a pixel in an SFML fragment shader is supposed to be:

gl_FragColor = gl_Color * texture2D(texture, gl_TexCoord[0].xy);

In your code you're mixing color from the texture (when it's dark) to the color of the sprite (when it's lit), that's why it shows the texture when it's dark and it shows white when it's lit (white is the default sprite color).

I think mixing from black (or whatever color you want the darkness to be) to gl_Color * texture2D(texture, pos) should do what you want:

 gl_FragColor = mix(vec4(0, 0, 0, 1),
        gl_Color * texture2D(texture, pos),
        1.0 - (distance/light.z));
Alayric
  • 291
  • 1
  • 2
  • 11