summaryrefslogtreecommitdiffstats
path: root/shader
diff options
context:
space:
mode:
authorMatthias Schiffer <matthias@gamezock.de>2009-12-18 13:31:07 +0100
committerMatthias Schiffer <matthias@gamezock.de>2009-12-18 13:31:07 +0100
commit4e3efa239c9bcb5dd26b4ad9a4d43d4d6a266e6f (patch)
treee39e9698513687a3213ecae7eab942bce88b12d6 /shader
parentb3b74dc2afe4c67a6b74c2a681aa7bbad7077511 (diff)
downloadzoom++-4e3efa239c9bcb5dd26b4ad9a4d43d4d6a266e6f.tar
zoom++-4e3efa239c9bcb5dd26b4ad9a4d43d4d6a266e6f.zip
Use multi-pass rendering with seperate ambient and light shaders
Diffstat (limited to 'shader')
-rw-r--r--shader/ambient.frag8
-rw-r--r--shader/ambient.vert8
-rw-r--r--shader/light.frag (renamed from shader/default.frag)12
-rw-r--r--shader/light.vert (renamed from shader/default.vert)3
4 files changed, 22 insertions, 9 deletions
diff --git a/shader/ambient.frag b/shader/ambient.frag
new file mode 100644
index 0000000..cef0a3b
--- /dev/null
+++ b/shader/ambient.frag
@@ -0,0 +1,8 @@
+uniform sampler2D tex;
+
+varying vec4 ambient;
+
+
+void main() {
+ gl_FragColor = ambient * texture2D(tex, gl_TexCoord[0].st);
+}
diff --git a/shader/ambient.vert b/shader/ambient.vert
new file mode 100644
index 0000000..41a36e7
--- /dev/null
+++ b/shader/ambient.vert
@@ -0,0 +1,8 @@
+varying vec4 ambient;
+
+void main() {
+ ambient = gl_LightModel.ambient * gl_FrontMaterial.ambient;
+
+ gl_TexCoord[0] = gl_MultiTexCoord0;
+ gl_Position = ftransform();
+}
diff --git a/shader/default.frag b/shader/light.frag
index e2acad0..c3cdbfb 100644
--- a/shader/default.frag
+++ b/shader/light.frag
@@ -1,6 +1,6 @@
uniform sampler2D tex;
-varying vec4 diffuse, ambientGlobal, ambient;
+varying vec4 diffuse, ambient;
varying vec3 normal, pos;
@@ -10,8 +10,6 @@ void main() {
vec4 color, specularColor;
float dist, att, specularFactor;
- color = ambientGlobal;
-
n = normalize(normal);
l = gl_LightSource[0].position.xyz - pos;
@@ -26,7 +24,7 @@ void main() {
att = 1.0 / (gl_LightSource[0].constantAttenuation +
gl_LightSource[0].linearAttenuation * dist +
gl_LightSource[0].quadraticAttenuation * dist * dist);
- color += att * (diffuse * NdotL + ambient);
+ color = att * (diffuse * NdotL + ambient);
refl = normalize(reflect(-l, n));
eye = normalize(-pos);
@@ -34,10 +32,10 @@ void main() {
RdotE = max(dot(refl, eye), 0.0);
specularFactor = att * pow(RdotE, gl_FrontMaterial.shininess);
specularColor = specularFactor * gl_FrontMaterial.specular * gl_LightSource[0].specular;
+
+ gl_FragColor = color * texture2D(tex, gl_TexCoord[0].st) + specularColor;
}
else {
- specularColor = vec4(0, 0, 0, 1);
+ gl_FragColor = vec4(0, 0, 0, 1);
}
-
- gl_FragColor = color * texture2D(tex, gl_TexCoord[0].st) + specularColor;
}
diff --git a/shader/default.vert b/shader/light.vert
index 00b8118..b97da78 100644
--- a/shader/default.vert
+++ b/shader/light.vert
@@ -1,4 +1,4 @@
-varying vec4 diffuse, ambientGlobal, ambient;
+varying vec4 diffuse, ambient;
varying vec3 normal, pos;
@@ -10,7 +10,6 @@ void main() {
diffuse = gl_FrontMaterial.diffuse * gl_LightSource[0].diffuse;
ambient = gl_FrontMaterial.ambient * gl_LightSource[0].ambient;
- ambientGlobal = gl_LightModel.ambient * gl_FrontMaterial.ambient;
gl_TexCoord[0] = gl_MultiTexCoord0;
gl_Position = ftransform();