diff options
Diffstat (limited to 'src/renderergl2')
| -rw-r--r-- | src/renderergl2/glsl/lightall_fp.glsl | 56 | ||||
| -rw-r--r-- | src/renderergl2/glsl/lightall_vp.glsl | 42 | ||||
| -rw-r--r-- | src/renderergl2/tr_shade.c | 2 | 
3 files changed, 57 insertions, 43 deletions
diff --git a/src/renderergl2/glsl/lightall_fp.glsl b/src/renderergl2/glsl/lightall_fp.glsl index 6aec2b4a..6dbfe963 100644 --- a/src/renderergl2/glsl/lightall_fp.glsl +++ b/src/renderergl2/glsl/lightall_fp.glsl @@ -261,6 +261,30 @@ vec3 CalcSpecular(vec3 specular, float NH, float NL, float NE, float EH, float s  	return vec3(0.0);  } + +float CalcLightAttenuation(vec3 dir, float sqrRadius) +{ +	// point light at >0 radius, directional otherwise +	float point = float(sqrRadius > 0.0); + +	// inverse square light +	float attenuation = sqrRadius / dot(dir, dir); + +	// zero light at radius, approximating q3 style +	// also don't attenuate directional light +	attenuation = (0.5 * attenuation - 1.5) * point + 1.0; +	 +	// clamp attenuation +	#if defined(NO_LIGHT_CLAMP) +	attenuation *= float(attenuation > 0.0); +	#else +	attenuation = clamp(attenuation, 0.0, 1.0); +	#endif +	 +	return attenuation; +} + +  void main()  {  	vec3 L, N, E, H; @@ -290,30 +314,12 @@ void main()    #endif  	vec3 lightColor = lightSample.rgb;  #elif defined(USE_LIGHT_VECTOR) && !defined(USE_FAST_LIGHT) -	// inverse square light -	float attenuation = u_LightRadius * u_LightRadius / dot(L, L); -	 -	// zero light at radius, approximating q3 style -	attenuation = 0.5 * attenuation - 0.5; -	//attenuation = 0.0697168 * attenuation; -	//attenuation *= step(0.294117, attenuation); -	 -	// clamp attenuation -	#if defined(NO_LIGHT_CLAMP) -	attenuation *= step(0.0, attenuation); -	#else -	attenuation = clamp(attenuation, 0.0, 1.0); -	#endif -	 -	// don't attenuate directional light -	attenuation = (attenuation - 1.0) * var_LightDir.w + 1.0; - -	vec3 lightColor   = u_DirectedLight * attenuation; +	vec3 lightColor   = u_DirectedLight * CalcLightAttenuation(L, u_LightRadius * u_LightRadius);  	vec3 ambientColor = u_AmbientLight;  #elif defined(USE_LIGHT_VERTEX) && !defined(USE_FAST_LIGHT)  	vec3 lightColor = var_lightColor;  #endif -	 +  	vec2 texCoords = var_DiffuseTex;  #if defined(USE_PARALLAXMAP) @@ -360,9 +366,9 @@ void main()  	// surfaces not facing the light are always shadowed  	#if defined(USE_TANGENT_SPACE_LIGHT) -	shadowValue *= step(0.0, var_PrimaryLightDir.z); +	shadowValue *= float(var_PrimaryLightDir.z > 0.0);  	#else -	shadowValue *= step(0.0, dot(var_Normal, var_PrimaryLightDir)); +	shadowValue *= float(dot(var_Normal, var_PrimaryLightDir) > 0.0);  	#endif      #if defined(SHADOWMAP_MODULATE) @@ -488,11 +494,13 @@ 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); +	      #if defined(USE_SHADOWMAP) -	reflectance *= shadowValue; +	lightColor *= shadowValue;      #endif -	gl_FragColor.rgb += u_PrimaryLightColor * reflectance * NL; +	gl_FragColor.rgb += lightColor * reflectance * NL;    #endif    #if defined(USE_LINEAR_LIGHT) diff --git a/src/renderergl2/glsl/lightall_vp.glsl b/src/renderergl2/glsl/lightall_vp.glsl index d2bfb395..3ea822a4 100644 --- a/src/renderergl2/glsl/lightall_vp.glsl +++ b/src/renderergl2/glsl/lightall_vp.glsl @@ -130,6 +130,29 @@ vec2 ModTexCoords(vec2 st, vec3 position, vec4 texMatrix, vec4 offTurb)  #endif +float CalcLightAttenuation(vec3 dir, float sqrRadius) +{ +	// point light at >0 radius, directional otherwise +	float point = float(sqrRadius > 0.0); + +	// inverse square light +	float attenuation = sqrRadius / dot(dir, dir); + +	// zero light at radius, approximating q3 style +	// also don't attenuate directional light +	attenuation = (0.5 * attenuation - 1.5) * point + 1.0; +	 +	// clamp attenuation +	#if defined(NO_LIGHT_CLAMP) +	attenuation *= float(attenuation > 0.0); +	#else +	attenuation = clamp(attenuation, 0.0, 1.0); +	#endif +	 +	return attenuation; +} + +  void main()  {  #if defined(USE_VERTEX_ANIMATION) @@ -187,24 +210,7 @@ void main()  #endif  #if defined(USE_LIGHT_VECTOR) && defined(USE_FAST_LIGHT) -	// inverse square light -	float attenuation = u_LightRadius * u_LightRadius / dot(L, L); -	 -	// zero light at radius, approximating q3 style -	attenuation = 0.5 * attenuation - 0.5; -	//attenuation = 0.0697168 * attenuation; -	//attenuation *= step(0.294117, attenuation); -	 -	// clamp attenuation -	#if defined(NO_LIGHT_CLAMP) -	attenuation *= step(0.0, attenuation); -	#else -	attenuation = clamp(attenuation, 0.0, 1.0); -	#endif -	 -	// don't attenuate directional light -	attenuation = (attenuation - 1.0) * u_LightOrigin.w + 1.0; -	 +	float attenuation = CalcLightAttenuation(L, u_LightRadius * u_LightRadius);  	float NL = clamp(dot(normal, normalize(L)), 0.0, 1.0);  	var_Color.rgb *= u_DirectedLight * attenuation * NL + u_AmbientLight; diff --git a/src/renderergl2/tr_shade.c b/src/renderergl2/tr_shade.c index 18ecbc9b..f679ddee 100644 --- a/src/renderergl2/tr_shade.c +++ b/src/renderergl2/tr_shade.c @@ -1212,7 +1212,7 @@ static void RB_IterateStagesGeneric( shaderCommands_t *input )  			vec[3] = 0.0f;  			GLSL_SetUniformVec4(sp, UNIFORM_LIGHTORIGIN, vec); -			GLSL_SetUniformFloat(sp, UNIFORM_LIGHTRADIUS, 999999.0f); +			GLSL_SetUniformFloat(sp, UNIFORM_LIGHTRADIUS, 0.0f);  		}  		if (pStage->alphaGen == AGEN_PORTAL)  | 
