[Solved] Fine tuning light shader mechanics

grimrader22 Asks: Fine tuning light shader mechanics
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;
#define LOWP  
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.

Ten-tools.com may not be responsible for the answers or solutions given to any question asked by the users. All Answers or responses are user generated answers and we do not have proof of its validity or correctness. Please vote for the answer that helped you in order to help others find out which is the most helpful answer. Questions labeled as solved may be solved or may not be solved depending on the type of question and the date posted for some posts may be scheduled to be deleted periodically. Do not hesitate to share your response here to help other visitors like you. Thank you, Ten-tools.