diff options
author | Dennis Peeten <dpeeten@onsneteindhoven.nl> | 2008-04-02 22:23:56 (GMT) |
---|---|---|
committer | Dennis Peeten <dpeeten@onsneteindhoven.nl> | 2008-04-02 22:23:56 (GMT) |
commit | 50da3e6185fe776f7f18ff05348daa0f9cf1321d (patch) | |
tree | 3936cb89ef228c321c02cd743107d783ddb455f3 /headtrack_stereo_demo/shaders | |
parent | 3b5bbd6adfa88366ac290c6c3ae3cfce63729836 (diff) | |
download | 2iv55-50da3e6185fe776f7f18ff05348daa0f9cf1321d.zip 2iv55-50da3e6185fe776f7f18ff05348daa0f9cf1321d.tar.gz 2iv55-50da3e6185fe776f7f18ff05348daa0f9cf1321d.tar.bz2 |
Initial checkin headtrack_stereo_demo
Diffstat (limited to 'headtrack_stereo_demo/shaders')
-rw-r--r-- | headtrack_stereo_demo/shaders/greyscale.frag | 31 | ||||
-rw-r--r-- | headtrack_stereo_demo/shaders/greyscale.vert | 25 |
2 files changed, 56 insertions, 0 deletions
diff --git a/headtrack_stereo_demo/shaders/greyscale.frag b/headtrack_stereo_demo/shaders/greyscale.frag new file mode 100644 index 0000000..6ed03e3 --- /dev/null +++ b/headtrack_stereo_demo/shaders/greyscale.frag @@ -0,0 +1,31 @@ +varying vec4 diffuse,ambient;
+ varying vec3 normal,lightDir,halfVector;
+
+
+ void main()
+ {
+ vec3 n,halfV;
+ float NdotL,NdotHV;
+
+ /* The ambient term will always be present */
+ vec4 color = ambient;
+
+ /* a fragment shader can't write a varying variable, hence we need
+ a new variable to store the normalized interpolated normal */
+ n = normalize(normal);
+
+ /* compute the dot product between normal and ldir */
+ NdotL = max(dot(n,lightDir),0.0);
+ if (NdotL > 0.0) {
+ color += diffuse * NdotL;
+ halfV = normalize(halfVector);
+ NdotHV = max(dot(n,halfV),0.0);
+ color += gl_FrontMaterial.specular *
+ gl_LightSource[0].specular *
+ pow(NdotHV, gl_FrontMaterial.shininess);
+ }
+
+ float gray = dot(color, vec3(0.299, 0.587, 0.114));
+
+ gl_FragColor = vec4(gray, gray, gray, color[3]);;
+}
\ No newline at end of file diff --git a/headtrack_stereo_demo/shaders/greyscale.vert b/headtrack_stereo_demo/shaders/greyscale.vert new file mode 100644 index 0000000..59c9d80 --- /dev/null +++ b/headtrack_stereo_demo/shaders/greyscale.vert @@ -0,0 +1,25 @@ +varying vec4 diffuse,ambient;
+ varying vec3 normal,lightDir,halfVector;
+
+ void main()
+ {
+ /* first transform the normal into eye space and
+ normalize the result */
+ normal = normalize(gl_NormalMatrix * gl_Normal);
+
+ /* now normalize the light's direction. Note that
+ according to the OpenGL specification, the light
+ is stored in eye space. Also since we're talking about
+ a directional light, the position field is actually direction */
+ lightDir = normalize(vec3(gl_LightSource[0].position));
+
+ /* Normalize the halfVector to pass it to the fragment shader */
+ halfVector = normalize(gl_LightSource[0].halfVector.xyz);
+
+ /* Compute the diffuse, ambient and globalAmbient terms */
+ diffuse = gl_FrontMaterial.diffuse * gl_LightSource[0].diffuse;
+ ambient = gl_FrontMaterial.ambient * gl_LightSource[0].ambient;
+ ambient += gl_LightModel.ambient * gl_FrontMaterial.ambient;
+
+ gl_Position = ftransform();
+ }
\ No newline at end of file |