summaryrefslogtreecommitdiff
path: root/src/renderergl2/glsl/lightall_fp.glsl
diff options
context:
space:
mode:
authorSmileTheory <SmileTheory@gmail.com>2013-09-17 23:52:40 -0700
committerTim Angus <tim@ngus.net>2014-06-17 17:43:34 +0100
commit7c5db0d00adcdf4c8c0db676d4fbc1070293ebb5 (patch)
treed541b7d0e9a0eca102fef2d03856f969e009f9f8 /src/renderergl2/glsl/lightall_fp.glsl
parentaf35556bd7d4eb936fc04f2a6a954ca5cf2f9354 (diff)
OpenGL2: reduce varying usage in lightall shader.
Diffstat (limited to 'src/renderergl2/glsl/lightall_fp.glsl')
-rw-r--r--src/renderergl2/glsl/lightall_fp.glsl57
1 files changed, 26 insertions, 31 deletions
diff --git a/src/renderergl2/glsl/lightall_fp.glsl b/src/renderergl2/glsl/lightall_fp.glsl
index 6dbfe963..5bc7b11a 100644
--- a/src/renderergl2/glsl/lightall_fp.glsl
+++ b/src/renderergl2/glsl/lightall_fp.glsl
@@ -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;