summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDennis Peeten <dpeeten@onsneteindhoven.nl>2008-05-28 08:22:19 (GMT)
committerDennis Peeten <dpeeten@onsneteindhoven.nl>2008-05-28 08:22:19 (GMT)
commitec069f23d73cea4ae3db177a62e83a3fc2179347 (patch)
tree89870cf293125ae90e09428fe914a85f71118633
parent77bd36a4977e64e2cdd53c04dfa5ca212d56b14e (diff)
download2iv55-ec069f23d73cea4ae3db177a62e83a3fc2179347.zip
2iv55-ec069f23d73cea4ae3db177a62e83a3fc2179347.tar.gz
2iv55-ec069f23d73cea4ae3db177a62e83a3fc2179347.tar.bz2
-rw-r--r--matchblox/shaders/grayscale.frag44
-rw-r--r--matchblox/shaders/grayscale.gdp55
-rw-r--r--matchblox/shaders/grayscale.vert19
3 files changed, 118 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
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 @@
+<?xml version="1.0" encoding="utf-8" standalone="yes"?>
+<GLSLang>
+ <Metadata>
+ <Author Author="" />
+ <Email Email="" />
+ <Company Company="" />
+ <Shader Shader="" />
+ <ShaderDescription ShaderDescription="" />
+ <License License="" />
+ <Version Version="" />
+ </Metadata>
+ <VPCount numero="1">
+ <Filenames>
+ <Filename0 VertexProgram=".\grayscale.vert" />
+ </Filenames>
+ </VPCount>
+ <FPCount numero="1">
+ <Filenames>
+ <Filename0 FragmentProgram=".\grayscale.frag" />
+ </Filenames>
+ </FPCount>
+ <TexturesPlugins NumberOfPlugins="0" />
+ <TexturedUsed NumberUsedTU="1">
+ <TextureUnit0 Filename="..\models\wood1.bmp" FilenameX="" Filename_X="" FilenameY="" Filename_Y="" FilenameZ="" Filename_Z="" MinFilter="9729" MagFilter="9729" Target="3553" WrapS="10497" WrapT="10497" WrapR="10497" Custom="False" Width="0" Height="0" Deep="0" />
+ </TexturedUsed>
+ <UniformVariables NumberOfVariables="2">
+ <Uniform0 Type="1" Name="g_TexSampler" ArraySize="1" Widget="0" Min="0" Max="1" Step="0.001">
+ <Values Value0="0" />
+ </Uniform0>
+ <Uniform1 Type="7" Name="g_ConversionWeights" ArraySize="1" Widget="0" Min="0" Max="1" Step="0.001">
+ <Values Value0="0" Value1="0.587" Value2="0" />
+ </Uniform1>
+ </UniformVariables>
+ <FogParameters FogColorR="0" FogColorG="0" FogColorB="0" FogColorA="1" Density="1" Start="0" End="1" />
+ <VertexProcessor CullFace="True" PolygonMode="DummieField" PolygonModeBack="6914" PolygonModeFront="6914" LocalValue="1" TwoSidedValue="0" ColorControlValue="33273" />
+ <FragmentProcessor Shade="7425" AlphaTest="False" AlphaFunc="516" AlphaClamp="0.5" Blending="False" BlendFuncSRC="770" BlendFuncDST="771" BlendEquation="32774" DepthTest="True" DepthFunc="515" ClampNear="0" ClampFar="1" ClearColorR="0.5019608" ClearColorG="0.5019608" ClearColorB="0.5019608" ClearColorA="1" />
+ <MotionData Speed="0.05" Distance="4" Rotation="False" />
+ <BuiltInStates>
+ <ModelAmbient AmbientR="0.2" AmbientG="0.2" AmbientB="0.2" AmbientA="1" />
+ <FrontMaterial AmbR="0.8784314" AmbG="0.8784314" AmbB="0.8784314" AmbA="1" DifR="0.8000001" DifG="0.8000001" DifB="0.8000001" DifA="1" SpecR="1" SpecG="1" SpecB="1" SpecA="1" EmiR="0" EmiG="0" EmiB="0" EmiA="1" Shininess="0" />
+ <BackMaterial AmbR="0.2" AmbG="0.2" AmbB="0.2" AmbA="1" DifR="0.8000001" DifG="0.8000001" DifB="0.8000001" DifA="1" SpecR="0" SpecG="0" SpecB="0" SpecA="1" EmiR="0" EmiG="0" EmiB="0" EmiA="1" Shininess="0" />
+ <PointParameters Size="1" MinSize="0" MaxSize="1" Threshold="1" ConstantAttenuation="1" LinearAttenuation="0" QuadraticAttenuation="0" />
+ <Light0 Enabled="True" PosX="0" PosY="0" PosZ="1" PosW="0" AmbR="0" AmbG="0" AmbB="0" AmbA="1" DifR="1" DifG="1" DifB="1" DifA="1" SpecR="1" SpecG="1" SpecB="1" SpecA="1" SpotDirX="0" SpotDirY="0" SpotDirZ="-1" SpotExp="0" SpotCutoff="180" SpotConstant="1" SpotLinear="0" SpotQuadratic="0" />
+ <Light1 Enabled="False" PosX="0" PosY="0" PosZ="1" PosW="0" AmbR="0" AmbG="0" AmbB="0" AmbA="1" DifR="0" DifG="0" DifB="0" DifA="1" SpecR="0" SpecG="0" SpecB="0" SpecA="1" SpotDirX="0" SpotDirY="0" SpotDirZ="-1" SpotExp="0" SpotCutoff="180" SpotConstant="1" SpotLinear="0" SpotQuadratic="0" />
+ <Light2 Enabled="False" PosX="0" PosY="0" PosZ="1" PosW="0" AmbR="0" AmbG="0" AmbB="0" AmbA="1" DifR="0" DifG="0" DifB="0" DifA="1" SpecR="0" SpecG="0" SpecB="0" SpecA="1" SpotDirX="0" SpotDirY="0" SpotDirZ="-1" SpotExp="0" SpotCutoff="180" SpotConstant="1" SpotLinear="0" SpotQuadratic="0" />
+ <Light3 Enabled="False" PosX="0" PosY="0" PosZ="1" PosW="0" AmbR="0" AmbG="0" AmbB="0" AmbA="1" DifR="0" DifG="0" DifB="0" DifA="1" SpecR="0" SpecG="0" SpecB="0" SpecA="1" SpotDirX="0" SpotDirY="0" SpotDirZ="-1" SpotExp="0" SpotCutoff="180" SpotConstant="1" SpotLinear="0" SpotQuadratic="0" />
+ <Light4 Enabled="False" PosX="0" PosY="0" PosZ="1" PosW="0" AmbR="0" AmbG="0" AmbB="0" AmbA="1" DifR="0" DifG="0" DifB="0" DifA="1" SpecR="0" SpecG="0" SpecB="0" SpecA="1" SpotDirX="0" SpotDirY="0" SpotDirZ="-1" SpotExp="0" SpotCutoff="180" SpotConstant="1" SpotLinear="0" SpotQuadratic="0" />
+ <Light5 Enabled="False" PosX="0" PosY="0" PosZ="1" PosW="0" AmbR="0" AmbG="0" AmbB="0" AmbA="1" DifR="0" DifG="0" DifB="0" DifA="1" SpecR="0" SpecG="0" SpecB="0" SpecA="1" SpotDirX="0" SpotDirY="0" SpotDirZ="-1" SpotExp="0" SpotCutoff="180" SpotConstant="1" SpotLinear="0" SpotQuadratic="0" />
+ <Light6 Enabled="False" PosX="0" PosY="0" PosZ="1" PosW="0" AmbR="0" AmbG="0" AmbB="0" AmbA="1" DifR="0" DifG="0" DifB="0" DifA="1" SpecR="0" SpecG="0" SpecB="0" SpecA="1" SpotDirX="0" SpotDirY="0" SpotDirZ="-1" SpotExp="0" SpotCutoff="180" SpotConstant="1" SpotLinear="0" SpotQuadratic="0" />
+ <Light7 Enabled="False" PosX="0" PosY="0" PosZ="1" PosW="0" AmbR="0" AmbG="0" AmbB="0" AmbA="1" DifR="0" DifG="0" DifB="0" DifA="1" SpecR="0" SpecG="0" SpecB="0" SpecA="1" SpotDirX="0" SpotDirY="0" SpotDirZ="-1" SpotExp="0" SpotCutoff="180" SpotConstant="1" SpotLinear="0" SpotQuadratic="0" />
+ </BuiltInStates>
+ <BackGround>
+ <BackGroundMode Mode="0" />
+ </BackGround>
+</GLSLang> \ 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;
+}