summaryrefslogtreecommitdiffstats
path: root/headtrack_stereo_demo/shaders/greyscale.frag
diff options
context:
space:
mode:
Diffstat (limited to 'headtrack_stereo_demo/shaders/greyscale.frag')
-rw-r--r--headtrack_stereo_demo/shaders/greyscale.frag71
1 files changed, 45 insertions, 26 deletions
diff --git a/headtrack_stereo_demo/shaders/greyscale.frag b/headtrack_stereo_demo/shaders/greyscale.frag
index 6ed03e3..d4b77cd 100644
--- a/headtrack_stereo_demo/shaders/greyscale.frag
+++ b/headtrack_stereo_demo/shaders/greyscale.frag
@@ -1,31 +1,50 @@
-varying vec4 diffuse,ambient;
- varying vec3 normal,lightDir,halfVector;
+uniform vec3 g_ConversionWeights;
+
+
+varying vec4 ambient, diffuse;
+varying vec3 normal, lightdir, halfvector;
+
+//uniform sampler2D tex, hello;
+
+void main()
+{
+ float NdotL, NdotHV, gray;
+ vec3 n = normalize(normal);
+ vec4 // texcolor = texture2D(tex, gl_TexCoord[0].st),
+ fragcolor = ambient,
+ color;
+ //compute the dot pruduct of the normalized normal and light direction
+ NdotL = max(dot(n, lightdir), 0.0);
- void main()
+ if (NdotL > 0.0)
{
- vec3 n,halfV;
- float NdotL,NdotHV;
+ //add diffuse light component
+ fragcolor += diffuse * NdotL;
- /* The ambient term will always be present */
- vec4 color = ambient;
+ //compute the dot product of the normal and half vector (of the lightdir and eye position)
+ NdotHV = max(dot(n, halfvector), 0.0);
- /* 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
+ fragcolor += gl_FrontMaterial.specular * gl_LightSource[0].specular *
+ pow(NdotHV, gl_FrontMaterial.shininess);
+ }
+
+
+
+ //modulate the fragment color with the texel color for the final color
+// color = texcolor * fragcolor;
+ color = fragcolor;
+
+ //smoothstep not available on ati motbility 8600
+ //color += smoothstep(1.0,0.2,NdotL) * texture2D(hello, gl_TexCoord[0].st);
+
+ //convert to grayscale using NTSC conversion weights
+ //gray = dot(color.rgb, vec3(0.299, 0.587, 0.114));
+ gray = dot(color.rgb, g_ConversionWeights);
+
+ //copy grayscale to rgb components and use the alpha from the final color
+ gl_FragColor = vec4(gray, gray, gray, color.a);
+
+ // convert grayscale to sepia
+ //gl_FragColor = vec4(gray * vec3(1.2, 1.0, 0.8), color.a);
+}