diff options
author | SmileTheory <SmileTheory@gmail.com> | 2013-11-12 19:21:51 -0800 |
---|---|---|
committer | Tim Angus <tim@ngus.net> | 2014-06-17 17:43:36 +0100 |
commit | 38af27b32b1302fd5ddd83d992fc8ec73209b3ad (patch) | |
tree | 0af9a9e571ffd1120d4603bd8d09f092875786e3 /src/renderergl2/glsl/lightall_vp.glsl | |
parent | 1efea34f7dc0afa21c1ddaa62705c8f4e6b76d9e (diff) |
OpenGL2: Calculate bitangent in shader, and store normal/tangent as normalized byte arrays.
Diffstat (limited to 'src/renderergl2/glsl/lightall_vp.glsl')
-rw-r--r-- | src/renderergl2/glsl/lightall_vp.glsl | 24 |
1 files changed, 13 insertions, 11 deletions
diff --git a/src/renderergl2/glsl/lightall_vp.glsl b/src/renderergl2/glsl/lightall_vp.glsl index aa0fe25b..f6164957 100644 --- a/src/renderergl2/glsl/lightall_vp.glsl +++ b/src/renderergl2/glsl/lightall_vp.glsl @@ -7,8 +7,7 @@ attribute vec4 attr_Color; attribute vec3 attr_Position; attribute vec3 attr_Normal; #if defined(USE_VERT_TANGENT_SPACE) -attribute vec3 attr_Tangent; -attribute vec3 attr_Bitangent; +attribute vec4 attr_Tangent; #endif #if defined(USE_VERTEX_ANIMATION) @@ -163,21 +162,24 @@ float CalcLightAttenuation(vec3 dir, float sqrRadius) void main() { #if defined(USE_VERTEX_ANIMATION) - vec3 position = mix(attr_Position, attr_Position2, u_VertexLerp); - vec3 normal = normalize(mix(attr_Normal, attr_Normal2, u_VertexLerp)); - #if defined(USE_VERT_TANGENT_SPACE) - vec3 tangent = normalize(mix(attr_Tangent, attr_Tangent2, u_VertexLerp)); - vec3 bitangent = normalize(mix(attr_Bitangent, attr_Bitangent2, u_VertexLerp)); + vec3 position = mix(attr_Position, attr_Position2, u_VertexLerp); + vec3 normal = normalize(mix(attr_Normal, attr_Normal2, u_VertexLerp) * 2.0 - vec3(1.0)); + #if defined(USE_VERT_TANGENT_SPACE) && defined(USE_LIGHT) && !defined(USE_FAST_LIGHT) + vec3 tangent = normalize(mix(attr_Tangent.xyz, attr_Tangent2.xyz, u_VertexLerp) * 2.0 - vec3(1.0)); #endif #else vec3 position = attr_Position; - vec3 normal = attr_Normal; - #if defined(USE_VERT_TANGENT_SPACE) - vec3 tangent = attr_Tangent; - vec3 bitangent = attr_Bitangent; + vec3 normal = attr_Normal * 2.0 - vec3(1.0); + #if defined(USE_VERT_TANGENT_SPACE) && defined(USE_LIGHT) && !defined(USE_FAST_LIGHT) + vec3 tangent = attr_Tangent.xyz * 2.0 - vec3(1.0); #endif #endif +#if defined(USE_VERT_TANGENT_SPACE) && defined(USE_LIGHT) && !defined(USE_FAST_LIGHT) + vec3 bitangent = cross(normal, tangent); + bitangent *= attr_Tangent.w * 2.0 - 1.0; +#endif + #if defined(USE_TCGEN) vec2 texCoords = GenTexCoords(u_TCGen0, position, normal, u_TCGen0Vector0, u_TCGen0Vector1); #else |