I'm currently trying to implement the lighting technique described in this article.
I've done pretty much exactly what is done in the article. My technique is the same, and my shader is the same. Here's my problem:
The lighting looks great when everything is kind of dark, but when it's not dark, the lights are far too bright.
This what it looks like when it's dark:
And here's what it looks like when it's light:
As you can probably tell, the light in the second image is far too bright. I'm looking for something about as intense as the first picture, but with the overall lighting like the second picture.
My fragment shader code is as follows: (Vertex shader is not relevant)
#define LOWP lowp
precision mediump float;
#else
#define LOWP
#endif
varying LOWP vec4 v_color;
varying vec2 v_texCoords;
uniform sampler2D u_texture;
uniform sampler2D u_lightmap;
uniform LOWP vec4 ambientColor;
uniform vec2 u_resolution;
void main()
{
vec4 diffuseColor = texture2D(u_texture, v_texCoords);
vec2 lightCoord = gl_FragCoord.xy / u_resolution.xy;
vec4 lightColor = texture2D(u_lightmap, lightCoord);
vec3 ambient = ambientColor.rgb * ambientColor.a;
vec3 intensity = ambient + lightColor.rgb;
vec3 finalColor = diffuseColor.rgb * intensity;
gl_FragColor = v_color * vec4(finalColor, diffuseColor.a);
}
ambientColor
is set to (1, 1, 1, alpha)
or (white, alpha)
, where the higher the alpha, the lighter it is. The dark image is 0.1f
, and light is 0.9f
.
I think the problem is with ambient + lightColor.rgb
, but I am not sure how else I could write it and maintain the same effect for when it is dark.
ambient + lightColor.rgb
toambient * lightColor.rgb
and I get something like this: i.stack.imgur.com/reG5c.png. Now the alpha value of ambient.a is completely ignored, so it is always totally dark everywhere. I have no way of controlling the global light now. \$\endgroup\$