summaryrefslogtreecommitdiffstats
path: root/matchblox/shaders/grayscale.frag
diff options
context:
space:
mode:
Diffstat (limited to 'matchblox/shaders/grayscale.frag')
-rw-r--r--matchblox/shaders/grayscale.frag44
1 files changed, 44 insertions, 0 deletions
diff --git a/matchblox/shaders/grayscale.frag b/matchblox/shaders/grayscale.frag
new file mode 100644
index 0000000..0f4ddaf
--- /dev/null
+++ b/matchblox/shaders/grayscale.frag
@@ -0,0 +1,44 @@
+uniform vec3 g_ConversionWeights;
+uniform sampler2D g_TexSampler;
+
+
+varying vec4 ambient, diffuse;
+varying vec3 normal, lightdir, halfvector;
+
+void main()
+{
+ float NdotL, NdotHV, gray;
+ vec3 n = normalize(normal);
+ vec4 texcolor = texture2D(g_TexSampler, 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);
+
+ if (NdotL > 0.0)
+ {
+ //add diffuse light component
+ fragcolor += diffuse * NdotL;
+
+ //compute the dot product of the normal and half vector (of the lightdir and eye position)
+ NdotHV = max(dot(n, halfvector), 0.0);
+
+ 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;
+
+ //convert to grayscale using NTSC conversion weights
+ //gray = dot(color.rgb, vec3(0.299, 0.587, 0.114));
+ gray = dot(color.rgb, g_ConversionWeights);
+ //gray = color.r * 0.299 + color.g * 0.587 + color.b * 0.114;
+
+ //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);
+} \ No newline at end of file