summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKenneth Graunke <kenneth@whitecape.org>2010-10-20 22:03:41 -0700
committerKenneth Graunke <kenneth@whitecape.org>2010-10-20 22:03:41 -0700
commit1d09c245ab5758e9db30553f206f72b9a55edf43 (patch)
tree02ab289d69d8e34fd9bdab09a85844302de5edc8
parentdf43818ff58074cfdcb2e196a2db9fa22a4f40b4 (diff)
Implement phong shading.
-rwxr-xr-xsrc/phong.frag13
-rwxr-xr-xsrc/phong.vert7
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;
}