|
From: Lasse Kärkkäi. <tr...@us...> - 2011-03-13 00:49:17
|
Author: Lasse Karkkainen <tro...@tr...>
Date: Sun Feb 27 00:36:54 2011 +0100
Shader cleanup
* Do not use fixed func transformation matrices
* Removed the "bogus" hack (the bug was caused by fixedfunc matrices being used)
* ColorMatrix no longer passed thru vertex/geometry shaders (uniform in fragment shader instead)
* Quite possibly other minor changes
---
data/shaders/core.frag | 9 +++------
data/shaders/core.vert | 19 +++++++------------
data/shaders/dancenote.vert | 27 ++++++++++-----------------
data/shaders/stereo3d.geom | 3 ---
4 files changed, 20 insertions(+), 38 deletions(-)
diff --git a/data/shaders/core.frag b/data/shaders/core.frag
index 3d3353c..7a3f7a1 100644
--- a/data/shaders/core.frag
+++ b/data/shaders/core.frag
@@ -3,8 +3,8 @@
//DEFINES
-in float bogus; // Nvidia will overwrite the first in variable with bogus data, so as a workaround we put a bogus variable here
-in mat4 colorMat;
+uniform mat4 colorMatrix;
+
in vec3 normal;
in vec4 color;
@@ -38,9 +38,6 @@ void main() {
#ifdef ENABLE_VERTEX_COLOR
frag *= color;
#endif
- gl_FragColor = colorMat * frag;
-#ifdef ENABLE_BOGUS
- gl_FragColor += vec4(0,0,0,bogus * 1e-10)
-#endif
+ gl_FragColor = colorMatrix * frag;
}
diff --git a/data/shaders/core.vert b/data/shaders/core.vert
index f47515b..d3b5f4f 100644
--- a/data/shaders/core.vert
+++ b/data/shaders/core.vert
@@ -2,30 +2,25 @@
//DEFINES
-varying float bogus;
+uniform mat4 positionMatrix;
+uniform mat3 normalMatrix;
in vec4 vertPos;
-uniform mat4 colorMatrix;
-varying mat4 colorMat;
-
in vec4 vertTexCoord;
+in vec3 vertNormal;
+in vec4 vertColor;
+
varying vec4 texCoord;
varying vec4 vTexCoord;
-
-in vec3 vertNormal;
varying vec3 normal;
varying vec3 vNormal;
-
-in vec4 vertColor;
varying vec4 color;
varying vec4 vColor;
void main() {
- bogus = 0.0;
- colorMat = colorMatrix; // In case no geometry shader is used (otherwise it sets this)
- gl_Position = gl_ModelViewProjectionMatrix * vertPos;
+ gl_Position = positionMatrix * vertPos;
vTexCoord = texCoord = vertTexCoord;
- vNormal = normal = normalize(gl_NormalMatrix * vertNormal);
+ vNormal = normal = normalMatrix * vertNormal;
vColor = color = vertColor;
}
diff --git a/data/shaders/dancenote.vert b/data/shaders/dancenote.vert
index 4499620..6d7df82 100644
--- a/data/shaders/dancenote.vert
+++ b/data/shaders/dancenote.vert
@@ -1,15 +1,18 @@
#version 120
+uniform mat4 positionMatrix;
+uniform mat3 normalMatrix;
+uniform int noteType;
+uniform float hitAnim;
+uniform float clock;
+uniform float scale;
+uniform vec2 position;
+
in vec4 vertPos;
in vec4 vertTexCoord;
in vec3 vertNormal;
in vec4 vertColor;
-varying float bogus;
-
-uniform mat4 colorMatrix;
-varying mat4 colorMat;
-
// Per-vextex for fragment shader (if no geometry shader)
varying vec4 texCoord;
varying vec3 normal;
@@ -20,13 +23,6 @@ varying vec4 vTexCoord;
varying vec3 vNormal;
varying vec4 vColor;
-
-uniform int noteType;
-uniform float hitAnim;
-uniform float clock;
-uniform float scale;
-uniform vec2 position;
-
mat4 scaleMat(in float sc) {
return mat4(sc, 0, 0, 0,
0, sc, 0, 0,
@@ -44,10 +40,8 @@ mat4 rotMat(in float ang) {
}
void main() {
- bogus = 0.0;
- colorMat = colorMatrix; // In case no geometry shader is used (otherwise it sets this)
vTexCoord = texCoord = vertTexCoord;
- vNormal = normal = normalize(gl_NormalMatrix * vertNormal);
+ vNormal = normal = normalMatrix * vertNormal;
vColor = color = vertColor;
mat4 trans = scaleMat(scale);
@@ -81,7 +75,6 @@ void main() {
);
}
- gl_Position = gl_ModelViewProjectionMatrix * trans * vertPos;
- gl_Position += gl_ModelViewProjectionMatrix * vec4(position.xy, 0, 0);
+ gl_Position = positionMatrix * (vec4(position, 0, 0) + trans * vertPos);
}
diff --git a/data/shaders/stereo3d.geom b/data/shaders/stereo3d.geom
index 5831be2..b19f19b 100644
--- a/data/shaders/stereo3d.geom
+++ b/data/shaders/stereo3d.geom
@@ -8,12 +8,10 @@ in vec4 vTexCoord[];
in vec3 vNormal[];
in vec4 vColor[];
-out mat4 colorMat;
out vec4 texCoord;
out vec3 normal;
out vec4 color;
-uniform mat4 colorMatrix;
uniform float sepFactor;
uniform float z0;
@@ -25,7 +23,6 @@ void passthru(in int i) {
}
void main() {
- colorMat = colorMatrix; // Supply color matrix for fragment shader
// Fix Nvidia compile warnings ("might be used uninitialized")
gl_Position = vec4(0);
texCoord = vec4(0);
|