Browse Source

Move the calculation of bitangent to the vert shader

Panagiotis Christopoulos Charitos 9 years ago
parent
commit
271f34d4a1
3 changed files with 31 additions and 12 deletions
  1. 10 9
      shaders/MsCommonFrag.glsl
  2. 19 3
      shaders/MsCommonVert.glsl
  3. 2 0
      shaders/MsFsCommon.glsl

+ 10 - 9
shaders/MsCommonFrag.glsl

@@ -3,12 +3,6 @@
 // Code licensed under the BSD License.
 // http://www.anki3d.org/LICENSE
 
-#include "shaders/Common.glsl"
-
-#if !GL_ES && __VERSION__ > 400
-layout(early_fragment_tests) in;
-#endif
-
 #include "shaders/Pack.glsl"
 #include "shaders/MsFsCommon.glsl"
 
@@ -24,9 +18,12 @@ layout(location = 0) in highp vec2 in_uv;
 #if PASS == COLOR
 layout(location = 1) in mediump vec3 in_normal;
 layout(location = 2) in mediump vec4 in_tangent;
-layout(location = 3) in mediump vec3 in_vertPosViewSpace;
-layout(location = 4) in mediump vec3 in_eyeTangentSpace; // Parallax
-layout(location = 5) in mediump vec3 in_normalTangentSpace; // Parallax
+#if CALC_BITANGENT_IN_VERT
+layout(location = 3) in mediump vec3 in_bitangent;
+#endif
+layout(location = 4) in mediump vec3 in_vertPosViewSpace;
+layout(location = 5) in mediump vec3 in_eyeTangentSpace; // Parallax
+layout(location = 6) in mediump vec3 in_normalTangentSpace; // Parallax
 #endif
 
 //
@@ -96,7 +93,11 @@ vec3 readNormalFromTexture(in vec3 normal, in vec4 tangent, in sampler2D map, in
 
 	vec3 n = normal; // Assume that getNormal() is called
 	vec3 t = normalize(tangent.xyz);
+#if CALC_BITANGENT_IN_VERT
+	vec3 b = normalize(in_bitangent.xyz);
+#else
 	vec3 b = cross(n, t) * tangent.w;
+#endif
 
 	mat3 tbnMat = mat3(t, b, n);
 

+ 19 - 3
shaders/MsCommonVert.glsl

@@ -42,9 +42,14 @@ layout(location = 1) out mediump vec3 out_normal;
 
 #if PASS == COLOR
 layout(location = 2) out mediump vec4 out_tangent;
-layout(location = 3) out mediump vec3 out_vertPosViewSpace;
-layout(location = 4) out mediump vec3 out_eyeTangentSpace; // Parallax
-layout(location = 5) out mediump vec3 out_normalTangentSpace; // Parallax
+#if CALC_BITANGENT_IN_VERT
+layout(location = 3) out mediump vec3 out_bitangent;
+#endif
+
+layout(location = 4) out mediump vec3 out_vertPosViewSpace;
+layout(location = 5) out mediump vec3 out_eyeTangentSpace; // Parallax
+layout(location = 6) out mediump vec3 out_normalTangentSpace; // Parallax
+
 #endif
 
 #define writePositionAndUv_DEFINED
@@ -80,6 +85,11 @@ void writeNormalAndTangent(in mat3 normalMat)
 	out_normal = in_normal.xyz;
 #if PASS == COLOR
 	out_tangent = in_tangent;
+
+#if CALC_BITANGENT_IN_VERT
+#error TODO
+#endif
+
 #endif
 
 #else
@@ -88,8 +98,14 @@ void writeNormalAndTangent(in mat3 normalMat)
 	out_normal = normalMat * in_normal.xyz;
 	out_tangent.xyz = normalMat * in_tangent.xyz;
 	out_tangent.w = in_tangent.w;
+
+#if CALC_BITANGENT_IN_VERT
+	out_bitangent = cross(out_normal, out_tangent.xyz) * in_tangent.w;
+#endif
+
 #endif
 
+// #if TESSELLATION
 #endif
 }
 #endif

+ 2 - 0
shaders/MsFsCommon.glsl

@@ -12,6 +12,8 @@
 #define COLOR 0
 #define DEPTH 1
 
+#define CALC_BITANGENT_IN_VERT 1
+
 // Generic functions because materials cannot use operators
 #define add_DEFINED
 #define add(a, b) ((a) + (b))