@@ -34,7 +34,7 @@ in vec3 vs_lightpos;
3434
3535void main() {
3636 vec2 uv = vec2 (gl_FragCoord .x / screensize.x, gl_FragCoord .y / screensize.y);
37- vec3 N = normalize (texture(g_normal, uv).rgb);
37+ vec3 normal = normalize (texture(g_normal, uv).rgb);
3838
3939 // View position reconstruct from depth
4040 float depth = texture(g_depth, uv).r;
@@ -48,15 +48,19 @@ void main() {
4848 discard ;
4949 }
5050
51- vec3 L = normalize (vs_lightpos - pos);
52- vec3 R = reflect (L, N);
53- float ndl = max (dot (N, L), 0.0 );
51+ vec3 lightDir = normalize (vs_lightpos - pos);
52+ vec3 viewDir = normalize (- pos);
53+ // vec3 halfwayDir = normalize(lightDir + viewDir);
54+ vec3 reflectDir = reflect (- lightDir, normal);
5455
55- // out_light = vec4(1.0 - (dist / radius));
56- out_light = vec4 (ndl);
57- // out_light = vec4(R, 1.0);
58- // out_light = vec4(N, 1.0);
59- // out_light = vec4(depth);
56+ float diffuse = max (dot (normal, lightDir), 0.0 );
57+ // float spec = pow(max(dot(normal, halfwayDir), 0.0), 32.8);
58+ float spec = pow (max (dot (viewDir, reflectDir), 0.0 ), 4.0 );
59+
60+ float l = diffuse * 0.5 + spec;
61+ // l *= (1.0 - dist / radius);
62+ l *= clamp (1.0 - dist* dist/ (radius* radius), 0.0 , 1.0 );
63+ out_light = vec4 (l);
6064}
6165
6266#endif
0 commit comments