aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/GLSLShaderTest/dimple.frag57
-rw-r--r--src/GLSLShaderTest/dimple.vert41
-rw-r--r--src/GLSLShaderTest/polkadot3d.frag48
-rw-r--r--src/GLSLShaderTest/polkadot3d.vert58
-rw-r--r--src/GLSLShaderTest/wood.frag66
-rw-r--r--src/GLSLShaderTest/wood.vert25
6 files changed, 295 insertions, 0 deletions
diff --git a/src/GLSLShaderTest/dimple.frag b/src/GLSLShaderTest/dimple.frag
new file mode 100644
index 0000000..70d2982
--- /dev/null
+++ b/src/GLSLShaderTest/dimple.frag
@@ -0,0 +1,57 @@
+
+//
+// dimple.frag: Fragment shader for bump mapping dimples (bumps)
+//
+// author: John Kessenich
+//
+// Copyright (c) 2002: 3Dlabs, Inc.
+//
+//
+varying vec3 LightDir;
+varying vec3 EyeDir;
+varying vec3 Normal;
+
+const vec3 color = vec3(0.7, 0.6, 0.18);
+
+//const float Density = 16.0;
+//const float Size = 0.25;
+
+//uniform float Density;
+//uniform float Size;
+float Density = 27.6;
+float Size = 0.13025;
+
+
+//uniform float Scale;
+
+const float SpecularFactor = 0.5;
+
+void main (void)
+{
+ vec3 litColor;
+
+ vec2 c = Density * (gl_TexCoord[0].xy);
+ vec2 p = fract(c) - vec2(0.5);
+ float d = (p.x * p.x) + (p.y * p.y);
+ if (d >= Size)
+ p = vec2(0.0);
+
+ vec3 normDelta = vec3(-p.x, -p.y, 1.0);
+
+ litColor = color * max(0.0, dot(normDelta, LightDir));
+
+ float t = 2.0 * dot(LightDir, normDelta);
+ vec3 reflectDir = t * normDelta;
+ reflectDir = LightDir - reflectDir;
+
+// vec3 reflectDir = LightDir - 2.0 * dot(LightDir, normDelta) * normDelta;
+
+ float spec = max(dot(EyeDir, reflectDir), 0.0);
+ spec = spec * spec;
+ spec = spec * spec;
+ spec *= SpecularFactor;
+
+ litColor = min(litColor + spec, vec3(1.0));
+ gl_FragColor = vec4(litColor, 1.0);
+// gl_FragColor = vec4(Scale);
+}
diff --git a/src/GLSLShaderTest/dimple.vert b/src/GLSLShaderTest/dimple.vert
new file mode 100644
index 0000000..0707d71
--- /dev/null
+++ b/src/GLSLShaderTest/dimple.vert
@@ -0,0 +1,41 @@
+
+//
+// dimple.vert: Vertex shader for bump mapping dimples (bumps)
+//
+// author: John Kessenich
+//
+// Copyright (c) 2002: 3Dlabs, Inc.
+//
+
+varying vec3 LightDir;
+varying vec3 EyeDir;
+varying vec3 Normal;
+
+//uniform vec3 LightPosition;
+//uniform float Scale;
+vec3 LightPosition = vec3(0.0, 0.0, 5.0);
+float Scale = 1.0;
+
+void main(void)
+{
+ vec4 pos = gl_ModelViewMatrix * gl_Vertex;
+ gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;
+ vec3 eyeDir = vec3(pos);
+// gl_TexCoord[0] = gl_MultiTexCoord0;
+ gl_TexCoord[0] = gl_Vertex;
+
+ vec3 n = normalize(gl_NormalMatrix * gl_Normal);
+ vec3 t = normalize(cross(vec3(1.141, 2.78, 3.14), n));
+ vec3 b = cross(n, t);
+
+ vec3 v;
+ v.x = dot(LightPosition, t);
+ v.y = dot(LightPosition, b);
+ v.z = dot(LightPosition, n);
+ LightDir = normalize(v);
+
+ v.x = dot(eyeDir, t);
+ v.y = dot(eyeDir, b);
+ v.z = dot(eyeDir, n);
+ EyeDir = normalize(v);
+}
diff --git a/src/GLSLShaderTest/polkadot3d.frag b/src/GLSLShaderTest/polkadot3d.frag
new file mode 100644
index 0000000..b341454
--- /dev/null
+++ b/src/GLSLShaderTest/polkadot3d.frag
@@ -0,0 +1,48 @@
+//
+// Fragment shader for 3 dimensional polka dot shader.
+//
+// Author: Joshua Doss
+//
+// Copyright (C) 2002-2004 3Dlabs Inc. Ltd.
+//
+// See 3Dlabs-License.txt for license information
+//
+varying float LightIntensity;
+varying vec3 MCPosition;
+
+//Create uniform variables so dots can be spaced and scaled by user
+//uniform vec3 Spacing;
+//uniform float DotSize;
+const vec3 Spacing = vec3 (0.314, 0.36, 0.261);
+const float DotSize = 0.123;
+
+//Create colors as uniform variables so they can be easily changed
+//uniform vec3 ModelColor, PolkaDotColor;
+const vec3 ModelColor = vec3 (0.75, 0.2, 0.1);
+const vec3 PolkaDotColor = vec3 (1, 1, 1);
+
+void main(void)
+{
+ float insidesphere, sphereradius, scaledpointlength;
+ vec3 scaledpoint, finalcolor;
+
+ // Scale the coordinate system
+ // The following line of code is not yet implemented in current drivers:
+ // mcpos = mod(Spacing, MCposition);
+ // We will use a workaround found below for now
+ scaledpoint = MCPosition - (Spacing * floor(MCPosition/Spacing));
+
+ // Bring the scaledpoint vector into the center of the scaled coordinate system
+ scaledpoint = scaledpoint - Spacing/2.0;
+
+ // Find the length of the scaledpoint vector and compare it to the dotsize
+ scaledpointlength = length(scaledpoint);
+ insidesphere = step(scaledpointlength,DotSize);
+
+ // Determine final output color before lighting
+ finalcolor = vec3(mix(ModelColor, PolkaDotColor, insidesphere));
+
+ // Output final color and factor in lighting
+ gl_FragColor = clamp((vec4( finalcolor, 1.0 ) * LightIntensity), vec4(0.0), vec4(1.0));
+}
+
diff --git a/src/GLSLShaderTest/polkadot3d.vert b/src/GLSLShaderTest/polkadot3d.vert
new file mode 100644
index 0000000..86f432f
--- /dev/null
+++ b/src/GLSLShaderTest/polkadot3d.vert
@@ -0,0 +1,58 @@
+// This is the Vertex Shader for three dimensional polka dots.
+//
+// author(s): Joshua Doss
+//
+// Copyright (C) 2002-2004 3Dlabs Inc. Ltd.
+
+//Create uniform variables for lighting to allow user interaction
+//uniform float SpecularContribution;
+//uniform vec3 LightPosition;
+
+const float SpecularContribution = 0.36;
+const vec3 LightPosition = vec3 (0, 4, 5);
+
+varying vec3 MCPosition;
+varying float LightIntensity;
+
+void main(void)
+{
+ float diffusecontribution = 1.0 - SpecularContribution;
+
+ // compute the vertex position in eye coordinates
+ vec3 ecPosition = vec3(gl_ModelViewMatrix * gl_Vertex);
+
+ // compute the transformed normal
+ vec3 tnorm = normalize(gl_NormalMatrix * gl_Normal);
+
+ // compute a vector from the model to the light position
+ vec3 lightVec = normalize(LightPosition - ecPosition);
+
+ // compute the reflection vector
+ vec3 reflectVec = reflect(-lightVec, tnorm);
+
+ // compute a unit vector in direction of viewing position
+ vec3 viewVec = normalize(-ecPosition);
+
+ // calculate amount of diffuse light based on normal and light angle
+ float diffuse = max(dot(lightVec, tnorm), 0.0);
+ float spec = 0.0;
+
+ // if there is diffuse lighting, calculate specular
+ if(diffuse > 0.0)
+ {
+ spec = max(dot(reflectVec, viewVec), 0.0);
+ spec = pow(spec, 16.0);
+ }
+
+ // add up the light sources, since this is a varying (global) it will pass to frag shader
+ LightIntensity = diffusecontribution * diffuse * 1.5 +
+ SpecularContribution * spec;
+
+ // the varying variable MCPosition will be used by the fragment shader to determine where
+ // in model space the current pixel is
+ MCPosition = vec3 (gl_Vertex);
+
+ // send vertex information
+ gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;
+}
+
diff --git a/src/GLSLShaderTest/wood.frag b/src/GLSLShaderTest/wood.frag
new file mode 100644
index 0000000..50ff2d5
--- /dev/null
+++ b/src/GLSLShaderTest/wood.frag
@@ -0,0 +1,66 @@
+//
+// Simple fragment shader for wood
+//
+// Author: John Kessenich
+//
+// Copyright (c) 2002-2004 3Dlabs Inc. Ltd.
+//
+// See 3Dlabs-License.txt for license information
+//
+
+//uniform float GrainSizeRecip;
+//uniform vec3 DarkColor;
+//uniform vec3 spread;
+const float GrainSizeRecip = 1;
+const vec3 DarkColor = vec3 (0.6, 0.3, 0.1);
+const vec3 spread = vec3 (0.15, 0.075, 0.0);
+
+varying float lightIntensity;
+varying vec3 Position;
+
+void main (void)
+{
+ //
+ // cheap noise
+ //
+ vec3 location = Position;
+ vec3 floorvec = vec3(floor(10.0 * Position.x), 0.0, floor(10.0 * Position.z));
+ vec3 noise = Position * 10.0 - floorvec - 0.5;
+ noise *= noise;
+ location += noise * 0.12;
+
+ //
+ // distance from axis
+ //
+ float dist = location.x * location.x + location.z * location.z;
+ float grain = dist * GrainSizeRecip;
+
+ //
+ // grain effects as function of distance
+ //
+ float brightness = fract(grain);
+ if (brightness > 0.5)
+ brightness = (1.0 - brightness);
+ vec3 color = DarkColor + brightness * spread;
+
+ brightness = fract(grain * 7.0);
+ if (brightness > 0.5)
+ brightness = 1.0 - brightness;
+ color -= brightness * spread;
+
+ //
+ // also as a function of lines parallel to the axis
+ //
+ brightness = fract(grain * 47.0) * 0.60;
+ float line = fract(Position.z + Position.x);
+ float snap = floor(line * 20.0) * (1.0/20.0);
+ if (line < snap + 0.006)
+ color -= brightness * spread;
+
+ //
+ // apply lighting effects from vertex processor
+ //
+ color = clamp(color * lightIntensity, 0.0, 1.0);
+
+ gl_FragColor = vec4(color, 1.0);
+}
diff --git a/src/GLSLShaderTest/wood.vert b/src/GLSLShaderTest/wood.vert
new file mode 100644
index 0000000..b107bad
--- /dev/null
+++ b/src/GLSLShaderTest/wood.vert
@@ -0,0 +1,25 @@
+//
+// Simple vertex shader for wood
+//
+// Author: John Kessenich
+//
+// Copyright (c) 2002-2004 3Dlabs Inc. Ltd.
+//
+// See 3Dlabs-License.txt for license information
+//
+
+varying float lightIntensity;
+varying vec3 Position;
+//uniform vec3 LightPosition;
+//uniform float Scale;
+const vec3 LightPosition = vec3 (0.0,0.0,0.4);
+const float Scale = 1;
+
+void main(void)
+{
+ vec4 pos = gl_ModelViewMatrix * gl_Vertex;
+ Position = vec3(gl_Vertex) * Scale;
+ vec3 tnorm = normalize(gl_NormalMatrix * gl_Normal);
+ lightIntensity = max(dot(normalize(LightPosition - vec3(pos)), tnorm), 0.0) * 1.5;
+ gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;
+}