Merge pull request #740 from Azaezel/alpha40/spotCookieCorrection

crashfix and projection fix for spotlights with cookies
This commit is contained in:
Brian Roberts 2022-03-16 03:30:55 -05:00 committed by GitHub
commit 0fad36787f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 27 additions and 28 deletions

View file

@ -96,6 +96,8 @@ void main()
if(dist < lightRange)
{
SurfaceToLight surfaceToLight = createSurfaceToLight(surface, L);
vec3 lightCol = lightColor.rgb;
#ifdef NO_SHADOW
float shadowed = 1.0;
#else
@ -107,20 +109,18 @@ void main()
//distance to light in shadow map space
float distToLight = pxlPosLightProj.z / lightRange;
float shadowed = softShadow_filter(shadowMap, ssPos.xy/ssPos.w, shadowCoord, shadowSoftness, distToLight, surfaceToLight.NdotL, lightParams.y);
#ifdef USE_COOKIE_TEX
// Lookup the cookie sample.
vec4 cookie = texture(cookieMap, shadowCoord);
// Multiply the light with the cookie tex.
lightCol *= cookie.rgb;
// Use a maximum channel luminance to attenuate
// the lighting else we get specular in the dark
// regions of the cookie texture.
lightCol *= max(cookie.r, max(cookie.g, cookie.b));
#endif
#endif
vec3 lightCol = lightColor.rgb;
#ifdef USE_COOKIE_TEX
// Lookup the cookie sample.
vec4 cookie = texture(cookieMap, tMul(worldToLightProj, -surfaceToLight.L));
// Multiply the light with the cookie tex.
lightCol *= cookie.rgb;
// Use a maximum channel luminance to attenuate
// the lighting else we get specular in the dark
// regions of the cookie texture.
lightCol *= max(cookie.r, max(cookie.g, cookie.b));
#endif
#ifdef DIFFUSE_LIGHT_VIZ
float attenuation = getDistanceAtt(surfaceToLight.Lu, radius);

View file

@ -43,7 +43,7 @@ TORQUE_UNIFORM_SAMPLER2D(shadowMap, 1);
#ifdef USE_COOKIE_TEX
/// The texture for cookie rendering.
TORQUE_UNIFORM_SAMPLER2D(cookieMap, 3);
TORQUE_UNIFORM_SAMPLER2D(cookieMap, 2);
#endif
TORQUE_UNIFORM_SAMPLER2D(colorBuffer, 5);
@ -101,6 +101,8 @@ float4 main( ConvexConnectP IN ) : SV_TARGET
if(dist < lightRange)
{
SurfaceToLight surfaceToLight = createSurfaceToLight(surface, L);
float3 lightCol = lightColor.rgb;
#ifdef NO_SHADOW
float shadowed = 1.0;
#else
@ -108,23 +110,20 @@ float4 main( ConvexConnectP IN ) : SV_TARGET
float4 pxlPosLightProj = mul( worldToLightProj, float4( surface.P, 1 ) );
float2 shadowCoord = ( ( pxlPosLightProj.xy / pxlPosLightProj.w ) * 0.5 ) + float2( 0.5, 0.5 );
shadowCoord.y = 1.0f - shadowCoord.y;
//distance to light in shadow map space
//distance to light in shadow map space
float distToLight = pxlPosLightProj.z / lightRange;
float shadowed = softShadow_filter(TORQUE_SAMPLER2D_MAKEARG(shadowMap), ssPos.xy, shadowCoord, shadowSoftness, distToLight, surfaceToLight.NdotL, lightParams.y);
#endif
float3 lightCol = lightColor.rgb;
#ifdef USE_COOKIE_TEX
// Lookup the cookie sample.
float4 cookie = TORQUE_TEXCUBE(cookieMap, mul(worldToLightProj, -surfaceToLight.L));
// Multiply the light with the cookie tex.
lightCol *= cookie.rgb;
// Use a maximum channel luminance to attenuate
// the lighting else we get specular in the dark
// regions of the cookie texture.
lightCol *= max(cookie.r, max(cookie.g, cookie.b));
#endif
#ifdef USE_COOKIE_TEX
// Lookup the cookie sample.
float4 cookie = TORQUE_TEX2D(cookieMap, shadowCoord);
// Multiply the light with the cookie tex.
lightCol *= cookie.rgb;
// Use a maximum channel luminance to attenuate
// the lighting else we get specular in the dark
// regions of the cookie texture.
lightCol *= max(cookie.r, max(cookie.g, cookie.b));
#endif
#endif
#ifdef DIFFUSE_LIGHT_VIZ
float attenuation = getDistanceAtt(surfaceToLight.Lu, radius);