diff options
-rwxr-xr-x | src/phong.frag | 13 | ||||
-rwxr-xr-x | src/phong.vert | 7 |
2 files changed, 11 insertions, 9 deletions
diff --git a/src/phong.frag b/src/phong.frag index 3385f68..f946cc7 100755 --- a/src/phong.frag +++ b/src/phong.frag @@ -1,7 +1,7 @@ varying vec4 normal_es; varying vec4 position_es; -varying vec2 texcoord; +const vec4 diffuse_color = vec4(1.0, 0.0, 0.0, 1.0); /* Specular exponent. */ uniform float s; @@ -12,9 +12,14 @@ const vec4 light_es = vec4(0.0, 3.0, 0.0, 1.0); void main(void) { - /* FINISHME: Calculate lighting. - */ + vec4 l = normalize(light_es - position_es); + vec4 v = normalize(-position_es); + vec4 h = normalize(l + v); + float n_dot_l = dot(normal_es, l); + vec4 diff = diffuse_color * n_dot_l; + float spec = pow(dot(normal_es, h), s); + vec4 color = vec4(1.0, 0.0, 0.0, 1.0); - gl_FragColor = color; + gl_FragColor = step(0.0, n_dot_l) * vec4(diff.xyz + vec3(spec), 1.0); } diff --git a/src/phong.vert b/src/phong.vert index 4e7ca2e..26f6b25 100755 --- a/src/phong.vert +++ b/src/phong.vert @@ -16,9 +16,6 @@ void main(void) { gl_Position = mvp * gl_Vertex; - /* FINISHME: Calculate normal_es. - */ - - /* FINISHME: Calculate position_es. - */ + normal_es = mv * normal; + position_es = mv * gl_Vertex; } |