mirror of
https://github.com/ioquake/ioq3.git
synced 2024-11-10 07:11:46 +00:00
OpenGL2: reduce varying usage in lightall shader.
This commit is contained in:
parent
cbd05da5d1
commit
3ab895d1cd
2 changed files with 60 additions and 64 deletions
|
@ -24,45 +24,40 @@ uniform sampler2D u_ShadowMap;
|
|||
uniform samplerCube u_CubeMap;
|
||||
#endif
|
||||
|
||||
#if defined(USE_LIGHT_VECTOR)
|
||||
#if defined(USE_LIGHT_VECTOR) && !defined(USE_FAST_LIGHT)
|
||||
uniform vec3 u_DirectedLight;
|
||||
uniform vec3 u_AmbientLight;
|
||||
uniform float u_LightRadius;
|
||||
#endif
|
||||
|
||||
#if defined(USE_PRIMARY_LIGHT) || defined(USE_SHADOWMAP)
|
||||
uniform vec3 u_PrimaryLightColor;
|
||||
uniform vec3 u_PrimaryLightAmbient;
|
||||
uniform float u_PrimaryLightRadius;
|
||||
#endif
|
||||
|
||||
#if defined(USE_LIGHT)
|
||||
#if defined(USE_LIGHT) && !defined(USE_FAST_LIGHT)
|
||||
uniform vec2 u_MaterialInfo;
|
||||
#endif
|
||||
|
||||
varying vec2 var_DiffuseTex;
|
||||
#if defined(USE_LIGHTMAP)
|
||||
varying vec2 var_LightTex;
|
||||
#endif
|
||||
varying vec4 var_TexCoords;
|
||||
|
||||
varying vec4 var_Color;
|
||||
|
||||
#if (defined(USE_LIGHT) && !defined(USE_FAST_LIGHT)) || defined(USE_PARALLAXMAP)
|
||||
varying vec3 var_ViewDir;
|
||||
varying vec3 var_Normal;
|
||||
varying vec3 var_Tangent;
|
||||
varying vec3 var_Bitangent;
|
||||
varying vec4 var_Normal;
|
||||
varying vec4 var_Tangent;
|
||||
varying vec4 var_Bitangent;
|
||||
#endif
|
||||
|
||||
#if defined(USE_LIGHT_VERTEX) && !defined(USE_FAST_LIGHT)
|
||||
varying vec3 var_lightColor;
|
||||
varying vec3 var_LightColor;
|
||||
#endif
|
||||
|
||||
#if defined(USE_LIGHT) && !defined(USE_DELUXEMAP)
|
||||
#if defined(USE_LIGHT) && !defined(USE_DELUXEMAP) && !defined(USE_FAST_LIGHT)
|
||||
varying vec4 var_LightDir;
|
||||
#endif
|
||||
|
||||
#if defined(USE_PRIMARY_LIGHT) || defined(USE_SHADOWMAP)
|
||||
varying vec3 var_PrimaryLightDir;
|
||||
varying vec4 var_PrimaryLightDir;
|
||||
#endif
|
||||
|
||||
|
||||
|
@ -276,7 +271,7 @@ float CalcLightAttenuation(vec3 dir, float sqrRadius)
|
|||
|
||||
// clamp attenuation
|
||||
#if defined(NO_LIGHT_CLAMP)
|
||||
attenuation *= float(attenuation > 0.0);
|
||||
attenuation = max(attenuation, 0.0);
|
||||
#else
|
||||
attenuation = clamp(attenuation, 0.0, 1.0);
|
||||
#endif
|
||||
|
@ -291,36 +286,36 @@ void main()
|
|||
float NL, NH, NE, EH;
|
||||
|
||||
#if (defined(USE_LIGHT) && !defined(USE_FAST_LIGHT)) || defined(USE_PARALLAXMAP)
|
||||
mat3 tangentToWorld = mat3(var_Tangent, var_Bitangent, var_Normal);
|
||||
mat3 tangentToWorld = mat3(var_Tangent.xyz, var_Bitangent.xyz, var_Normal.xyz);
|
||||
#endif
|
||||
|
||||
#if defined(USE_DELUXEMAP)
|
||||
L = (2.0 * texture2D(u_DeluxeMap, var_LightTex).xyz - vec3(1.0));
|
||||
L = (2.0 * texture2D(u_DeluxeMap, var_TexCoords.zw).xyz - vec3(1.0));
|
||||
#if defined(USE_TANGENT_SPACE_LIGHT)
|
||||
L = L * tangentToWorld;
|
||||
L = L * tangentToWorld;
|
||||
#endif
|
||||
#elif defined(USE_LIGHT) && !defined(USE_FAST_LIGHT)
|
||||
L = var_LightDir.xyz;
|
||||
#endif
|
||||
|
||||
#if (defined(USE_LIGHT) && !defined(USE_FAST_LIGHT)) || defined(USE_PARALLAXMAP)
|
||||
E = normalize(var_ViewDir);
|
||||
E = normalize(vec3(var_Normal.w, var_Tangent.w, var_Bitangent.w));
|
||||
#endif
|
||||
|
||||
#if defined(USE_LIGHTMAP)
|
||||
vec4 lightSample = texture2D(u_LightMap, var_LightTex).rgba;
|
||||
vec4 lightSample = texture2D(u_LightMap, var_TexCoords.zw).rgba;
|
||||
#if defined(RGBM_LIGHTMAP)
|
||||
lightSample.rgb *= 32.0 * lightSample.a;
|
||||
#endif
|
||||
vec3 lightColor = lightSample.rgb;
|
||||
#elif defined(USE_LIGHT_VECTOR) && !defined(USE_FAST_LIGHT)
|
||||
vec3 lightColor = u_DirectedLight * CalcLightAttenuation(L, u_LightRadius * u_LightRadius);
|
||||
vec3 lightColor = u_DirectedLight * CalcLightAttenuation(L, var_LightDir.w);
|
||||
vec3 ambientColor = u_AmbientLight;
|
||||
#elif defined(USE_LIGHT_VERTEX) && !defined(USE_FAST_LIGHT)
|
||||
vec3 lightColor = var_lightColor;
|
||||
vec3 lightColor = var_LightColor;
|
||||
#endif
|
||||
|
||||
vec2 texCoords = var_DiffuseTex;
|
||||
vec2 texCoords = var_TexCoords.xy;
|
||||
|
||||
#if defined(USE_PARALLAXMAP)
|
||||
#if defined(USE_TANGENT_SPACE_LIGHT)
|
||||
|
@ -355,7 +350,7 @@ void main()
|
|||
#elif defined(USE_TANGENT_SPACE_LIGHT)
|
||||
N = vec3(0.0, 0.0, 1.0);
|
||||
#else
|
||||
N = normalize(var_Normal);
|
||||
N = normalize(var_Normal.xyz);
|
||||
#endif
|
||||
|
||||
L = normalize(L);
|
||||
|
@ -368,7 +363,7 @@ void main()
|
|||
#if defined(USE_TANGENT_SPACE_LIGHT)
|
||||
shadowValue *= float(var_PrimaryLightDir.z > 0.0);
|
||||
#else
|
||||
shadowValue *= float(dot(var_Normal, var_PrimaryLightDir) > 0.0);
|
||||
shadowValue *= float(dot(var_Normal.xyz, var_PrimaryLightDir.xyz) > 0.0);
|
||||
#endif
|
||||
|
||||
#if defined(SHADOWMAP_MODULATE)
|
||||
|
@ -377,7 +372,7 @@ void main()
|
|||
|
||||
#if 0
|
||||
// Only shadow when the world light is parallel to the primary light
|
||||
shadowValue = 1.0 + (shadowValue - 1.0) * clamp(dot(L, var_PrimaryLightDir), 0.0, 1.0);
|
||||
shadowValue = 1.0 + (shadowValue - 1.0) * clamp(dot(L, var_PrimaryLightDir.xyz), 0.0, 1.0);
|
||||
#endif
|
||||
lightColor = mix(shadowColor, lightColor, shadowValue);
|
||||
#endif
|
||||
|
@ -389,7 +384,7 @@ void main()
|
|||
#if defined(USE_TANGENT_SPACE_LIGHT)
|
||||
float surfNL = L.z;
|
||||
#else
|
||||
float surfNL = clamp(dot(var_Normal, L), 0.0, 1.0);
|
||||
float surfNL = clamp(dot(var_Normal.xyz, L), 0.0, 1.0);
|
||||
#endif
|
||||
|
||||
// Scale the incoming light to compensate for the baked-in light angle
|
||||
|
@ -474,7 +469,7 @@ void main()
|
|||
#if defined(USE_LIGHTMAP)
|
||||
cubeLightColor *= lightSample.rgb;
|
||||
#elif defined (USE_LIGHT_VERTEX)
|
||||
cubeLightColor *= var_lightColor;
|
||||
cubeLightColor *= var_LightColor;
|
||||
#else
|
||||
cubeLightColor *= lightColor * NL + ambientColor;
|
||||
#endif
|
||||
|
@ -484,7 +479,7 @@ void main()
|
|||
#endif
|
||||
|
||||
#if defined(USE_PRIMARY_LIGHT)
|
||||
L = normalize(var_PrimaryLightDir);
|
||||
L = normalize(var_PrimaryLightDir.xyz);
|
||||
NL = clamp(dot(N, L), 0.0, 1.0);
|
||||
|
||||
H = normalize(L + E);
|
||||
|
@ -494,7 +489,7 @@ void main()
|
|||
reflectance = CalcDiffuse(diffuse.rgb, N, L, E, NE, NL, shininess);
|
||||
reflectance += CalcSpecular(specular.rgb, NH, NL, NE, EH, shininess);
|
||||
|
||||
lightColor = u_PrimaryLightColor; // * CalcLightAttenuation(L, u_PrimaryLightRadius * u_PrimaryLightRadius);
|
||||
lightColor = u_PrimaryLightColor; // * CalcLightAttenuation(L, u_PrimaryLightDir.w);
|
||||
|
||||
#if defined(USE_SHADOWMAP)
|
||||
lightColor *= shadowValue;
|
||||
|
|
|
@ -49,37 +49,30 @@ uniform float u_VertexLerp;
|
|||
|
||||
#if defined(USE_LIGHT_VECTOR)
|
||||
uniform vec4 u_LightOrigin;
|
||||
#if defined(USE_FAST_LIGHT)
|
||||
uniform vec3 u_DirectedLight;
|
||||
uniform vec3 u_AmbientLight;
|
||||
uniform float u_LightRadius;
|
||||
uniform vec3 u_DirectedLight;
|
||||
#if defined(USE_FAST_LIGHT)
|
||||
uniform vec3 u_AmbientLight;
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if defined(USE_PRIMARY_LIGHT) || defined(USE_SHADOWMAP)
|
||||
uniform vec4 u_PrimaryLightOrigin;
|
||||
uniform float u_PrimaryLightRadius;
|
||||
#endif
|
||||
|
||||
varying vec2 var_DiffuseTex;
|
||||
|
||||
#if defined(USE_LIGHTMAP)
|
||||
varying vec2 var_LightTex;
|
||||
#endif
|
||||
|
||||
#if defined(USE_NORMALMAP) || (defined(USE_LIGHT) && !defined(USE_FAST_LIGHT))
|
||||
varying vec3 var_ViewDir;
|
||||
#endif
|
||||
varying vec4 var_TexCoords;
|
||||
|
||||
varying vec4 var_Color;
|
||||
|
||||
#if (defined(USE_LIGHT) && !defined(USE_FAST_LIGHT)) || defined(USE_PARALLAXMAP)
|
||||
varying vec3 var_Normal;
|
||||
varying vec3 var_Tangent;
|
||||
varying vec3 var_Bitangent;
|
||||
varying vec4 var_Normal;
|
||||
varying vec4 var_Tangent;
|
||||
varying vec4 var_Bitangent;
|
||||
#endif
|
||||
|
||||
#if defined(USE_LIGHT_VERTEX) && !defined(USE_FAST_LIGHT)
|
||||
varying vec3 var_lightColor;
|
||||
varying vec3 var_LightColor;
|
||||
#endif
|
||||
|
||||
#if defined(USE_LIGHT) && !defined(USE_DELUXEMAP) && !defined(USE_FAST_LIGHT)
|
||||
|
@ -87,7 +80,7 @@ varying vec4 var_LightDir;
|
|||
#endif
|
||||
|
||||
#if defined(USE_PRIMARY_LIGHT) || defined(USE_SHADOWMAP)
|
||||
varying vec3 var_PrimaryLightDir;
|
||||
varying vec4 var_PrimaryLightDir;
|
||||
#endif
|
||||
|
||||
#if defined(USE_TCGEN)
|
||||
|
@ -144,7 +137,7 @@ float CalcLightAttenuation(vec3 dir, float sqrRadius)
|
|||
|
||||
// clamp attenuation
|
||||
#if defined(NO_LIGHT_CLAMP)
|
||||
attenuation *= float(attenuation > 0.0);
|
||||
attenuation = max(attenuation, 0.0);
|
||||
#else
|
||||
attenuation = clamp(attenuation, 0.0, 1.0);
|
||||
#endif
|
||||
|
@ -174,9 +167,9 @@ void main()
|
|||
#endif
|
||||
|
||||
#if defined(USE_TCMOD)
|
||||
var_DiffuseTex = ModTexCoords(texCoords, position, u_DiffuseTexMatrix, u_DiffuseTexOffTurb);
|
||||
var_TexCoords.xy = ModTexCoords(texCoords, position, u_DiffuseTexMatrix, u_DiffuseTexOffTurb);
|
||||
#else
|
||||
var_DiffuseTex = texCoords;
|
||||
var_TexCoords.xy = texCoords;
|
||||
#endif
|
||||
|
||||
gl_Position = u_ModelViewProjectionMatrix * vec4(position, 1.0);
|
||||
|
@ -193,16 +186,16 @@ void main()
|
|||
#elif defined(USE_LIGHT) && !defined(USE_LIGHT_VECTOR)
|
||||
vec3 L = attr_LightDirection;
|
||||
#if defined(USE_MODELMATRIX)
|
||||
L = (u_ModelMatrix * vec4(L, 0.0)).xyz;
|
||||
L = (u_ModelMatrix * vec4(L, 0.0)).xyz;
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if defined(USE_LIGHTMAP)
|
||||
var_LightTex = attr_TexCoord1.st;
|
||||
var_TexCoords.zw = attr_TexCoord1.st;
|
||||
#endif
|
||||
|
||||
#if defined(USE_LIGHT_VERTEX) && !defined(USE_FAST_LIGHT)
|
||||
var_lightColor = u_VertColor.rgb * attr_Color.rgb;
|
||||
var_LightColor = u_VertColor.rgb * attr_Color.rgb;
|
||||
var_Color.rgb = vec3(1.0);
|
||||
var_Color.a = u_VertColor.a * attr_Color.a + u_BaseColor.a;
|
||||
#else
|
||||
|
@ -217,40 +210,48 @@ void main()
|
|||
#endif
|
||||
|
||||
#if (defined(USE_LIGHT) && !defined(USE_FAST_LIGHT)) || defined(USE_PARALLAXMAP)
|
||||
var_Normal = normal;
|
||||
var_Tangent = tangent;
|
||||
var_Bitangent = bitangent;
|
||||
var_Normal.xyz = normal;
|
||||
var_Tangent.xyz = tangent;
|
||||
var_Bitangent.xyz = bitangent;
|
||||
#endif
|
||||
|
||||
#if defined(USE_PRIMARY_LIGHT) || defined(USE_SHADOWMAP)
|
||||
var_PrimaryLightDir = (u_PrimaryLightOrigin.xyz - (position * u_PrimaryLightOrigin.w));
|
||||
var_PrimaryLightDir.xyz = (u_PrimaryLightOrigin.xyz - (position * u_PrimaryLightOrigin.w));
|
||||
var_PrimaryLightDir.w = u_PrimaryLightRadius * u_PrimaryLightRadius;
|
||||
#endif
|
||||
|
||||
#if defined(USE_LIGHT) && !defined(USE_DELUXEMAP) && !defined(USE_FAST_LIGHT)
|
||||
#if defined(USE_LIGHT_VECTOR)
|
||||
var_LightDir = vec4(L, u_LightOrigin.w);
|
||||
var_LightDir = vec4(L, u_LightRadius * u_LightRadius);
|
||||
#else
|
||||
var_LightDir = vec4(L, 0.0);
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if defined(USE_NORMALMAP) || (defined(USE_LIGHT) && !defined(USE_FAST_LIGHT))
|
||||
var_ViewDir = (u_ViewOrigin - position);
|
||||
#if (defined(USE_LIGHT) && !defined(USE_FAST_LIGHT)) || defined(USE_PARALLAXMAP)
|
||||
vec3 viewDir = (u_ViewOrigin - position);
|
||||
#endif
|
||||
|
||||
#if defined(USE_TANGENT_SPACE_LIGHT)
|
||||
mat3 tangentToWorld = mat3(tangent, bitangent, normal);
|
||||
|
||||
#if defined(USE_PRIMARY_LIGHT) || defined(USE_SHADOWMAP)
|
||||
var_PrimaryLightDir = var_PrimaryLightDir * tangentToWorld;
|
||||
var_PrimaryLightDir.xyz = var_PrimaryLightDir.xyz * tangentToWorld;
|
||||
#endif
|
||||
|
||||
#if defined(USE_LIGHT) && !defined(USE_DELUXEMAP) && !defined(USE_FAST_LIGHT)
|
||||
var_LightDir.xyz = var_LightDir.xyz * tangentToWorld;
|
||||
#endif
|
||||
|
||||
#if defined(USE_NORMALMAP) || (defined(USE_LIGHT) && !defined(USE_FAST_LIGHT))
|
||||
var_ViewDir = var_ViewDir * tangentToWorld;
|
||||
#if (defined(USE_LIGHT) && !defined(USE_FAST_LIGHT)) || defined(USE_PARALLAXMAP)
|
||||
viewDir = viewDir * tangentToWorld;
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if (defined(USE_LIGHT) && !defined(USE_FAST_LIGHT)) || defined(USE_PARALLAXMAP)
|
||||
// store view direction in tangent space to save on varyings
|
||||
var_Normal.w = viewDir.x;
|
||||
var_Tangent.w = viewDir.y;
|
||||
var_Bitangent.w = viewDir.z;
|
||||
#endif
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue