From 843308f07547b969c97efc23848f4e81b50a5b24 Mon Sep 17 00:00:00 2001 From: Matt Strapp Date: Wed, 24 Nov 2021 09:18:24 -0600 Subject: Do a5 --- dev/a5-artrender/shaders/phong.frag | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) (limited to 'dev/a5-artrender/shaders/phong.frag') diff --git a/dev/a5-artrender/shaders/phong.frag b/dev/a5-artrender/shaders/phong.frag index 2f7c013..5c51159 100644 --- a/dev/a5-artrender/shaders/phong.frag +++ b/dev/a5-artrender/shaders/phong.frag @@ -13,5 +13,24 @@ uniform float s; void main() { - color = vec4(0,0,0,1); + // transoform the vertex position into "eye space" + vec3 v = position_in_eye_space; + + // unit vector from the vertex to the light + vec3 l = normalize(light_in_eye_space - v); + + // unit vector from the vertex to the eye point, which is at 0,0,0 in "eye space" + vec3 e = normalize(vec3(0,0,0) - v); + + // normal transformed into "eye space" + vec3 n = normalize(normalize(normal_in_eye_space)); + // halfway vector + vec3 h = normalize(e+l); + + // calculate color using the light intensity equation + vec4 ambient = ka * Ia; + vec4 diffuse = kd * Id * max(dot(n, l), 0); + vec4 specular = ks * Is * pow(max(dot(h, n), 0), s); + + color = ambient + diffuse + specular; } -- cgit v1.2.3