2020-06-02 16:18:44 -07:00
|
|
|
vec4 add_light(vec4 raw_color, vec3 point, vec3 unit_normal, vec3 light_coords, float gloss){
|
|
|
|
if(gloss == 0.0) return raw_color;
|
|
|
|
|
2020-06-05 11:12:52 -07:00
|
|
|
// TODO, do we actually want this? It effectively treats surfaces as two-sided
|
2020-06-03 17:10:33 -07:00
|
|
|
if(unit_normal.z < 0){
|
|
|
|
unit_normal *= -1;
|
|
|
|
}
|
|
|
|
|
2020-06-04 15:41:20 -07:00
|
|
|
float camera_distance = 6; // TODO, read this in as a uniform?
|
2020-06-02 16:18:44 -07:00
|
|
|
// Assume everything has already been rotated such that camera is in the z-direction
|
|
|
|
vec3 to_camera = vec3(0, 0, camera_distance) - point;
|
|
|
|
vec3 to_light = light_coords - point;
|
|
|
|
vec3 light_reflection = -to_light + 2 * unit_normal * dot(to_light, unit_normal);
|
|
|
|
float dot_prod = dot(normalize(light_reflection), normalize(to_camera));
|
2020-06-04 17:17:38 -07:00
|
|
|
float shine = gloss * exp(-3 * pow(1 - dot_prod, 2));
|
2020-06-04 15:41:20 -07:00
|
|
|
float dp2 = dot(normalize(to_light), unit_normal);
|
2020-06-06 09:26:18 -07:00
|
|
|
float shadow = ((dp2 + 2.0) / 3.0); // TODO, this should come from the mobject in some way
|
2020-06-02 16:18:44 -07:00
|
|
|
return vec4(
|
2020-06-06 09:26:18 -07:00
|
|
|
shadow * mix(raw_color.rgb, vec3(1.0), shine),
|
2020-06-02 16:18:44 -07:00
|
|
|
raw_color.a
|
|
|
|
);
|
|
|
|
}
|