aboutsummaryrefslogtreecommitdiff
path: root/data/shaders
diff options
context:
space:
mode:
authortaw27 <taw27@84d2e878-0bd5-11dd-ad15-13eda11d74c5>2008-04-16 16:57:56 +0000
committertaw27 <taw27@84d2e878-0bd5-11dd-ad15-13eda11d74c5>2008-04-16 16:57:56 +0000
commitf0a0118393a3d121bcb83047b5b9ac95eb0621ba (patch)
treecfc4f3f7955b4829317fa9b7865e328ccabfb129 /data/shaders
Initial import
git-svn-id: svn://cook.msm.cam.ac.uk:745/thrust3d/thrust3d@1 84d2e878-0bd5-11dd-ad15-13eda11d74c5
Diffstat (limited to 'data/shaders')
-rw-r--r--data/shaders/lighting.frag53
-rw-r--r--data/shaders/lighting.vert39
2 files changed, 92 insertions, 0 deletions
diff --git a/data/shaders/lighting.frag b/data/shaders/lighting.frag
new file mode 100644
index 0000000..ee1df5b
--- /dev/null
+++ b/data/shaders/lighting.frag
@@ -0,0 +1,53 @@
+/*
+ * lighting.frag
+ *
+ * Lighting calculations
+ *
+ * (c) 2007-2008 Thomas White <taw27@cam.ac.uk>
+ *
+ * thrust3d - a silly game
+ *
+ */
+
+varying vec4 col_ambi;
+varying vec4 col_diff;
+varying vec4 col_spec;
+varying vec4 col_emit;
+varying float shininess;
+
+varying vec3 normal;
+varying vec3 halfvc;
+
+uniform sampler2D texture;
+
+void main() {
+
+ vec4 ambi;
+ vec4 diff;
+ vec4 spec;
+ vec3 light;
+ vec3 norml;
+
+ /* Ambient contribution */
+ ambi = col_ambi * gl_LightModel.ambient;
+ ambi += col_ambi * gl_LightSource[0].ambient;
+ ambi = vec4(0.0, 0.0, 0.0, 1.0);
+
+ /* Diffuse contribution */
+ light = vec3(normalize(gl_LightSource[0].position));
+ norml = normalize(normal);
+ diff = col_diff * clamp(dot(light, normal), 0.0, 1.0);
+
+ /* Specular contribution */
+ spec = col_spec * clamp(pow(dot( vec3(normal), halfvc ), shininess), 0.0, 1.0);
+ spec = vec4(0.0, 0.0, 0.0, 1.0);
+
+ gl_FragColor = vec4(min(col_emit.r + ambi.r + diff.r + spec.r, 1.0),
+ min(col_emit.g + ambi.g + diff.g + spec.g, 1.0),
+ min(col_emit.b + ambi.b + diff.b + spec.b, 1.0),
+ min(col_emit.a + ambi.a + diff.a + spec.a, 1.0));
+
+ gl_FragColor *= texture2D(texture, gl_TexCoord[0].st);
+
+}
+
diff --git a/data/shaders/lighting.vert b/data/shaders/lighting.vert
new file mode 100644
index 0000000..eaa51c2
--- /dev/null
+++ b/data/shaders/lighting.vert
@@ -0,0 +1,39 @@
+/*
+ * lighting.vert
+ *
+ * Lighting calculations
+ *
+ * (c) 2007-2008 Thomas White <taw27@cam.ac.uk>
+ *
+ * thrust3d - a silly game
+ *
+ */
+
+varying vec4 col_ambi;
+varying vec4 col_diff;
+varying vec4 col_spec;
+varying vec4 col_emit;
+varying float shininess;
+
+varying vec3 normal;
+varying vec3 halfvc;
+
+void main() {
+
+ /* Directions */
+ normal = normalize(gl_NormalMatrix * gl_Normal);
+ halfvc = vec3(gl_LightSource[0].halfVector);
+
+ /* Material properties */
+ col_ambi = gl_FrontMaterial.ambient;
+ col_diff = gl_FrontMaterial.diffuse;
+ col_spec = gl_FrontMaterial.specular;
+ col_emit = gl_FrontMaterial.emission;
+ shininess = gl_FrontMaterial.shininess;
+
+ /* Coordinates */
+ gl_TexCoord[0] = gl_TextureMatrix[0] * gl_MultiTexCoord0;
+ gl_Position = ftransform();
+
+}
+