From ec069f23d73cea4ae3db177a62e83a3fc2179347 Mon Sep 17 00:00:00 2001 From: Dennis Peeten Date: Wed, 28 May 2008 08:22:19 +0000 Subject: --- matchblox/shaders/grayscale.frag | 44 ++++++++++++++++++++++++++++++++ matchblox/shaders/grayscale.gdp | 55 ++++++++++++++++++++++++++++++++++++++++ matchblox/shaders/grayscale.vert | 19 ++++++++++++++ 3 files changed, 118 insertions(+) create mode 100644 matchblox/shaders/grayscale.frag create mode 100644 matchblox/shaders/grayscale.gdp create mode 100644 matchblox/shaders/grayscale.vert 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 diff --git a/matchblox/shaders/grayscale.gdp b/matchblox/shaders/grayscale.gdp new file mode 100644 index 0000000..e913f9a --- /dev/null +++ b/matchblox/shaders/grayscale.gdp @@ -0,0 +1,55 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/matchblox/shaders/grayscale.vert b/matchblox/shaders/grayscale.vert new file mode 100644 index 0000000..af155c8 --- /dev/null +++ b/matchblox/shaders/grayscale.vert @@ -0,0 +1,19 @@ +varying vec4 ambient, diffuse; +varying vec3 normal, lightdir, halfvector; + +void main() +{ + //transform the normal + normal = gl_NormalMatrix * gl_Normal; + + //determine the light direction + lightdir = normalize(gl_LightSource[0].position.xyz); + halfvector = normalize(gl_LightSource[0].halfVector.xyz); + + //compute diffuse and ambient terms + diffuse = gl_FrontMaterial.diffuse * gl_LightSource[0].diffuse; + ambient = gl_FrontMaterial.ambient * (gl_LightSource[0].ambient + gl_LightModel.ambient); + + gl_Position = ftransform(); + gl_TexCoord[0] = gl_MultiTexCoord0; +} -- cgit v0.12