OpenGL2: Remove per fragment tangent space calculation code.
This commit is contained in:
parent
4faf1008a0
commit
8749d62bbd
13 changed files with 5 additions and 130 deletions
|
@ -53,14 +53,9 @@ varying vec4 var_ColorAmbient;
|
|||
#endif
|
||||
|
||||
#if (defined(USE_LIGHT) && !defined(USE_FAST_LIGHT))
|
||||
#if defined(USE_VERT_TANGENT_SPACE)
|
||||
varying vec4 var_Normal;
|
||||
varying vec4 var_Tangent;
|
||||
varying vec4 var_Bitangent;
|
||||
#else
|
||||
varying vec3 var_Normal;
|
||||
varying vec3 var_ViewDir;
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if defined(USE_LIGHT) && !defined(USE_FAST_LIGHT)
|
||||
|
@ -196,25 +191,6 @@ float CalcLightAttenuation(float point, float normDist)
|
|||
return attenuation;
|
||||
}
|
||||
|
||||
// from http://www.thetenthplanet.de/archives/1180
|
||||
mat3 cotangent_frame( vec3 N, vec3 p, vec2 uv )
|
||||
{
|
||||
// get edge vectors of the pixel triangle
|
||||
vec3 dp1 = dFdx( p );
|
||||
vec3 dp2 = dFdy( p );
|
||||
vec2 duv1 = dFdx( uv );
|
||||
vec2 duv2 = dFdy( uv );
|
||||
|
||||
// solve the linear system
|
||||
vec3 dp2perp = cross( dp2, N );
|
||||
vec3 dp1perp = cross( N, dp1 );
|
||||
vec3 T = dp2perp * duv1.x + dp1perp * duv2.x;
|
||||
vec3 B = dp2perp * duv1.y + dp1perp * duv2.y;
|
||||
|
||||
// construct a scale-invariant frame
|
||||
float invmax = inversesqrt( max( dot(T,T), dot(B,B) ) );
|
||||
return mat3( T * invmax, B * invmax, N );
|
||||
}
|
||||
|
||||
void main()
|
||||
{
|
||||
|
@ -223,13 +199,8 @@ void main()
|
|||
float NL, NH, NE, EH, attenuation;
|
||||
|
||||
#if defined(USE_LIGHT) && !defined(USE_FAST_LIGHT)
|
||||
#if defined(USE_VERT_TANGENT_SPACE)
|
||||
mat3 tangentToWorld = mat3(var_Tangent.xyz, var_Bitangent.xyz, var_Normal.xyz);
|
||||
viewDir = vec3(var_Normal.w, var_Tangent.w, var_Bitangent.w);
|
||||
#else
|
||||
mat3 tangentToWorld = cotangent_frame(var_Normal, -var_ViewDir, var_TexCoords.xy);
|
||||
viewDir = var_ViewDir;
|
||||
#endif
|
||||
E = normalize(viewDir);
|
||||
#endif
|
||||
|
||||
|
|
|
@ -6,16 +6,12 @@ attribute vec4 attr_Color;
|
|||
|
||||
attribute vec3 attr_Position;
|
||||
attribute vec3 attr_Normal;
|
||||
#if defined(USE_VERT_TANGENT_SPACE)
|
||||
attribute vec4 attr_Tangent;
|
||||
#endif
|
||||
|
||||
#if defined(USE_VERTEX_ANIMATION)
|
||||
attribute vec3 attr_Position2;
|
||||
attribute vec3 attr_Normal2;
|
||||
#if defined(USE_VERT_TANGENT_SPACE)
|
||||
attribute vec4 attr_Tangent2;
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if defined(USE_LIGHT) && !defined(USE_LIGHT_VECTOR)
|
||||
|
@ -74,14 +70,9 @@ varying vec4 var_ColorAmbient;
|
|||
#endif
|
||||
|
||||
#if defined(USE_LIGHT) && !defined(USE_FAST_LIGHT)
|
||||
#if defined(USE_VERT_TANGENT_SPACE)
|
||||
varying vec4 var_Normal;
|
||||
varying vec4 var_Tangent;
|
||||
varying vec4 var_Bitangent;
|
||||
#else
|
||||
varying vec3 var_Normal;
|
||||
varying vec3 var_ViewDir;
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if defined(USE_LIGHT) && !defined(USE_FAST_LIGHT)
|
||||
|
@ -157,13 +148,13 @@ void main()
|
|||
#if defined(USE_VERTEX_ANIMATION)
|
||||
vec3 position = mix(attr_Position, attr_Position2, u_VertexLerp);
|
||||
vec3 normal = mix(attr_Normal, attr_Normal2, u_VertexLerp);
|
||||
#if defined(USE_VERT_TANGENT_SPACE) && defined(USE_LIGHT) && !defined(USE_FAST_LIGHT)
|
||||
#if defined(USE_LIGHT) && !defined(USE_FAST_LIGHT)
|
||||
vec3 tangent = mix(attr_Tangent.xyz, attr_Tangent2.xyz, u_VertexLerp);
|
||||
#endif
|
||||
#else
|
||||
vec3 position = attr_Position;
|
||||
vec3 normal = attr_Normal;
|
||||
#if defined(USE_VERT_TANGENT_SPACE) && defined(USE_LIGHT) && !defined(USE_FAST_LIGHT)
|
||||
#if defined(USE_LIGHT) && !defined(USE_FAST_LIGHT)
|
||||
vec3 tangent = attr_Tangent.xyz;
|
||||
#endif
|
||||
#endif
|
||||
|
@ -185,12 +176,12 @@ void main()
|
|||
#if defined(USE_MODELMATRIX)
|
||||
position = (u_ModelMatrix * vec4(position, 1.0)).xyz;
|
||||
normal = (u_ModelMatrix * vec4(normal, 0.0)).xyz;
|
||||
#if defined(USE_VERT_TANGENT_SPACE) && defined(USE_LIGHT) && !defined(USE_FAST_LIGHT)
|
||||
#if defined(USE_LIGHT) && !defined(USE_FAST_LIGHT)
|
||||
tangent = (u_ModelMatrix * vec4(tangent, 0.0)).xyz;
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if defined(USE_VERT_TANGENT_SPACE) && defined(USE_LIGHT) && !defined(USE_FAST_LIGHT)
|
||||
#if defined(USE_LIGHT) && !defined(USE_FAST_LIGHT)
|
||||
vec3 bitangent = cross(normal, tangent) * attr_Tangent.w;
|
||||
#endif
|
||||
|
||||
|
@ -247,14 +238,9 @@ void main()
|
|||
|
||||
#if defined(USE_LIGHT) && !defined(USE_FAST_LIGHT)
|
||||
vec3 viewDir = u_ViewOrigin - position;
|
||||
#if defined(USE_VERT_TANGENT_SPACE)
|
||||
// store view direction in tangent space to save on varyings
|
||||
var_Normal = vec4(normal, viewDir.x);
|
||||
var_Tangent = vec4(tangent, viewDir.y);
|
||||
var_Bitangent = vec4(bitangent, viewDir.z);
|
||||
#else
|
||||
var_Normal = normal;
|
||||
var_ViewDir = viewDir;
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue