aboutsummaryrefslogtreecommitdiff
path: root/data
diff options
context:
space:
mode:
authortaw27 <taw27@84d2e878-0bd5-11dd-ad15-13eda11d74c5>2008-07-26 23:19:32 +0000
committertaw27 <taw27@84d2e878-0bd5-11dd-ad15-13eda11d74c5>2008-07-26 23:19:32 +0000
commited5740b6f667628f344d9dd17686424ce9e2de82 (patch)
tree124d4fe3fd9d04e8f89550c82e5487491b35e889 /data
parent5f8d27519c76fd297eb61144ff38bd5d1afa51bb (diff)
Initial normal mapping stuff
git-svn-id: svn://cook.msm.cam.ac.uk:745/thrust3d/thrust3d@176 84d2e878-0bd5-11dd-ad15-13eda11d74c5
Diffstat (limited to 'data')
-rw-r--r--data/Makefile.am7
-rw-r--r--data/shaders/lighting.frag42
-rw-r--r--data/shaders/lighting.vert2
3 files changed, 37 insertions, 14 deletions
diff --git a/data/Makefile.am b/data/Makefile.am
index 28241e0..9ea8369 100644
--- a/data/Makefile.am
+++ b/data/Makefile.am
@@ -1,12 +1,13 @@
modelsdir = $(datadir)/thrust3d/models
-models_DATA = models/floor models/lander models/randombox models/walle models/walln models/wallw models/walls models/platform \
- models/ceiling models/tiledfloor
+models_DATA = models/floor models/lander models/randombox models/walle models/walln models/wallw models/walls \
+ models/platform models/ceiling models/tiledfloor
shadersdir = $(datadir)/thrust3d/shaders
shaders_DATA = shaders/lighting.vert shaders/lighting.frag shaders/swirlytron.vert shaders/swirlytron.frag
texturesdir = $(datadir)/thrust3d/textures
-textures_DATA = textures/floor1.png textures/tiledwall.png textures/radioactive.png textures/fuel.png textures/font.png textures/concrete.png
+textures_DATA = textures/floor1.png textures/tiledwall.png textures/radioactive.png textures/fuel.png \
+ textures/font.png textures/concrete.png textures/tiledwall-normals.png
roomsdir = $(datadir)/thrust3d/rooms
rooms_DATA = rooms/00-00-00 rooms/00-00-01 rooms/00-00-02 rooms/00-00-03 rooms/00-00-04 rooms/00-01-04 rooms/00-02-04
diff --git a/data/shaders/lighting.frag b/data/shaders/lighting.frag
index ef7ce18..0b11b36 100644
--- a/data/shaders/lighting.frag
+++ b/data/shaders/lighting.frag
@@ -12,11 +12,15 @@
varying vec3 normal;
varying vec3 light0vc;
+varying vec3 light0hvc;
varying vec3 light1vc;
varying vec3 light2vc;
varying vec3 light2hvc;
uniform sampler2D texture;
+uniform sampler2D normalmap;
+
+uniform bool has_normals;
uniform bool fill_light_enabled;
uniform bool texture_enabled;
uniform bool texture_emits;
@@ -31,9 +35,13 @@ void main() {
vec3 emit;
vec3 diff = vec3(0.0, 0.0, 0.0);
vec3 spec = vec3(0.0, 0.0, 0.0);
+ vec3 norm = normal;
+
+ if ( has_normals ) {
+ norm += (texture2D(normalmap, gl_TexCoord[0].st).rgb - vec3(0.5, 0.5, 0.5)) / 2.0;
+ }
- vec3 norm = normalize(normal);
- float ndothv = max(dot(norm, normalize(light2hvc)), 0.0);
+ norm = normalize(norm);
/* Ambient */
ambi = col_ambi_diff * gl_LightModel.ambient.rgb;
@@ -43,21 +51,33 @@ void main() {
/* Fill-in light (light 2) */
if ( fill_light_enabled ) {
-
+
+ float ndothv;
+
+ ndothv = max(dot(norm, normalize(light2hvc)), 0.0);
diff += col_ambi_diff * gl_LightSource[2].diffuse.rgb * max(dot(vec3(light1vc), norm), 0.0);
spec += gl_LightSource[2].specular.rgb * pow(ndothv, 80.0);
} else {
/* Spotlight (light 0) - positional, spotlight */
- float falloff = 1/ ( gl_LightSource[0].constantAttenuation
+ float falloff;
+ float spot;
+ float ndothv;
+
+ falloff = 1/ ( gl_LightSource[0].constantAttenuation
+ gl_LightSource[0].linearAttenuation * length(light0vc)
+ gl_LightSource[0].quadraticAttenuation * pow(length(light0vc), 2.0) );
- float spot = max(dot(normalize(-light0vc), gl_LightSource[0].spotDirection), 0.0);
+ spot = max(dot(normalize(-light0vc), gl_LightSource[0].spotDirection), 0.0);
spot = pow(spot, gl_LightSource[0].spotExponent);
- diff += col_ambi_diff * gl_LightSource[0].diffuse.rgb * spot * falloff * max(dot(normalize(light0vc).xyz, norm), 0.0);
- spec += vec3(1.0, 1.0, 1.0) * gl_LightSource[0].specular.rgb * pow(ndothv, 80.0);
-
+
+ ndothv = max(dot(norm, normalize(light0hvc)), 0.0);
+
+ diff += col_ambi_diff * gl_LightSource[0].diffuse.rgb * spot * falloff *
+ max(dot(normalize(light0vc).xyz, norm), 0.0);
+
+ spec += vec3(1.0, 1.0, 1.0) * gl_LightSource[0].specular.rgb * spot * falloff * pow(ndothv, 80.0);
+
/* Background glow (light 1) - diffuse only, directional */
diff += col_ambi_diff * gl_LightSource[1].diffuse.rgb * max(dot(vec3(light1vc), norm), 0.0);
@@ -73,9 +93,9 @@ void main() {
min(emit.b + ambi.b + diff.b + spec.b + tex.b, 1.0),
alpha);
} else {
- gl_FragColor = vec4(tex.r * min(emit.r + ambi.r + diff.r + spec.r, 1.0),
- tex.g * min(emit.g + ambi.g + diff.g + spec.g, 1.0),
- tex.b * min(emit.b + ambi.b + diff.b + spec.b, 1.0),
+ gl_FragColor = vec4(min(tex.r * (ambi.r + diff.r) + spec.r, 1.0),
+ min(tex.g * (ambi.g + diff.g) + spec.g, 1.0),
+ min(tex.b * (ambi.b + diff.b) + spec.b, 1.0),
alpha);
}
diff --git a/data/shaders/lighting.vert b/data/shaders/lighting.vert
index 294d5ba..ddbe8ab 100644
--- a/data/shaders/lighting.vert
+++ b/data/shaders/lighting.vert
@@ -12,6 +12,7 @@
varying vec3 normal;
varying vec3 light0vc;
+varying vec3 light0hvc;
varying vec3 light1vc;
varying vec3 light2vc;
varying vec3 light2hvc;
@@ -24,6 +25,7 @@ void main() {
/* Spotlight - positional light */
vec4 vert = gl_ModelViewMatrix * gl_Vertex;
light0vc = gl_LightSource[0].position.xyz - vert.xyz;
+ light0hvc = normalize(gl_LightSource[0].halfVector.xyz);
/* Diffuse "background glow" - this can be normalised only once, here, since 'position'
* is really 'direction' and is the same for all vertices. */