Lambert -> phong shading

This commit is contained in:
KP 2024-07-29 17:30:32 -05:00
parent f649dd2189
commit 2f40dadf3e

View file

@ -45,7 +45,20 @@ vec4 MakeLight(vec3 norm, vec3 position, vec3 diffuse, float radius, float sharp
light.position = position; light.position = position;
light.diffuse = diffuse; light.diffuse = diffuse;
light.radius = radius; light.radius = radius;
vec4 res = vec4(light.diffuse * Lambert(norm, normalize(light.position)), 1.0); // vec4 res = vec4(light.diffuse * Lambert(norm, normalize(light.position)), 1.0);
vec3 light_dir = normalize(light.position - v_position);
vec3 view_dir = normalize(u_campos - v_position);
vec3 reflect_dir = reflect(-light_dir, norm);
float spec = max(dot(view_dir, reflect_dir), 0.0);
float diff = max(dot(norm, light_dir), 0.0);
power = 0.5;
vec3 ddiffuse = diff * light.diffuse;
vec3 specular = power * spec * light.diffuse;
vec4 res = vec4(ddiffuse + specular, 1.0);
//vec4 res = vec4(power * spec * light.diffuse, 1.0);
float alpha = kpc(distance(light.position, v_position), light.radius * sharpness, light.radius); float alpha = kpc(distance(light.position, v_position), light.radius * sharpness, light.radius);
res *= mix(vec4(light.diffuse, 1), vec4(0,0,0,1.0), alpha); res *= mix(vec4(light.diffuse, 1), vec4(0,0,0,1.0), alpha);
@ -64,7 +77,7 @@ void main()
vec4 ambient = vec4(0.1, 0.1, 0.1, 1.0) * 1.5, light = ambient; vec4 ambient = vec4(0.1, 0.1, 0.1, 1.0) * 1.5, light = ambient;
light += MakeLight(norm, u_campos, vec3(1.0, 1.0, 1.0), 5.0, 0.0, 1.0); light += MakeLight(norm, u_campos, vec3(0.7), 5.0, 0.0, 1.0);
light += MakeLight(norm, vec3(5.0, 2.0, -7.0 + cos(u_time/35.0) * 2.0), vec3(1.0, 0.6, 0.0), 5.0, 0.6, 1.0); light += MakeLight(norm, vec3(5.0, 2.0, -7.0 + cos(u_time/35.0) * 2.0), vec3(1.0, 0.6, 0.0), 5.0, 0.6, 1.0);
light += MakeLight(norm, vec3(7, 2.0, -7.0 + -cos(u_time / 30.0) * 1.0), vec3(0.6, 0.9, 1.0), 5.0, 0.6, 1.0); light += MakeLight(norm, vec3(7, 2.0, -7.0 + -cos(u_time / 30.0) * 1.0), vec3(0.6, 0.9, 1.0), 5.0, 0.6, 1.0);