mirror of
https://github.com/TorqueGameEngines/Torque3D.git
synced 2026-07-15 08:34:40 +00:00
Merge pull request #740 from Azaezel/alpha40/spotCookieCorrection
crashfix and projection fix for spotlights with cookies
This commit is contained in:
commit
0fad36787f
2 changed files with 27 additions and 28 deletions
|
|
@ -96,6 +96,8 @@ void main()
|
||||||
if(dist < lightRange)
|
if(dist < lightRange)
|
||||||
{
|
{
|
||||||
SurfaceToLight surfaceToLight = createSurfaceToLight(surface, L);
|
SurfaceToLight surfaceToLight = createSurfaceToLight(surface, L);
|
||||||
|
vec3 lightCol = lightColor.rgb;
|
||||||
|
|
||||||
#ifdef NO_SHADOW
|
#ifdef NO_SHADOW
|
||||||
float shadowed = 1.0;
|
float shadowed = 1.0;
|
||||||
#else
|
#else
|
||||||
|
|
@ -107,20 +109,18 @@ void main()
|
||||||
//distance to light in shadow map space
|
//distance to light in shadow map space
|
||||||
float distToLight = pxlPosLightProj.z / lightRange;
|
float distToLight = pxlPosLightProj.z / lightRange;
|
||||||
float shadowed = softShadow_filter(shadowMap, ssPos.xy/ssPos.w, shadowCoord, shadowSoftness, distToLight, surfaceToLight.NdotL, lightParams.y);
|
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
|
#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
|
#ifdef DIFFUSE_LIGHT_VIZ
|
||||||
float attenuation = getDistanceAtt(surfaceToLight.Lu, radius);
|
float attenuation = getDistanceAtt(surfaceToLight.Lu, radius);
|
||||||
|
|
|
||||||
|
|
@ -43,7 +43,7 @@ TORQUE_UNIFORM_SAMPLER2D(shadowMap, 1);
|
||||||
#ifdef USE_COOKIE_TEX
|
#ifdef USE_COOKIE_TEX
|
||||||
|
|
||||||
/// The texture for cookie rendering.
|
/// The texture for cookie rendering.
|
||||||
TORQUE_UNIFORM_SAMPLER2D(cookieMap, 3);
|
TORQUE_UNIFORM_SAMPLER2D(cookieMap, 2);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
TORQUE_UNIFORM_SAMPLER2D(colorBuffer, 5);
|
TORQUE_UNIFORM_SAMPLER2D(colorBuffer, 5);
|
||||||
|
|
@ -101,6 +101,8 @@ float4 main( ConvexConnectP IN ) : SV_TARGET
|
||||||
if(dist < lightRange)
|
if(dist < lightRange)
|
||||||
{
|
{
|
||||||
SurfaceToLight surfaceToLight = createSurfaceToLight(surface, L);
|
SurfaceToLight surfaceToLight = createSurfaceToLight(surface, L);
|
||||||
|
float3 lightCol = lightColor.rgb;
|
||||||
|
|
||||||
#ifdef NO_SHADOW
|
#ifdef NO_SHADOW
|
||||||
float shadowed = 1.0;
|
float shadowed = 1.0;
|
||||||
#else
|
#else
|
||||||
|
|
@ -108,23 +110,20 @@ float4 main( ConvexConnectP IN ) : SV_TARGET
|
||||||
float4 pxlPosLightProj = mul( worldToLightProj, float4( surface.P, 1 ) );
|
float4 pxlPosLightProj = mul( worldToLightProj, float4( surface.P, 1 ) );
|
||||||
float2 shadowCoord = ( ( pxlPosLightProj.xy / pxlPosLightProj.w ) * 0.5 ) + float2( 0.5, 0.5 );
|
float2 shadowCoord = ( ( pxlPosLightProj.xy / pxlPosLightProj.w ) * 0.5 ) + float2( 0.5, 0.5 );
|
||||||
shadowCoord.y = 1.0f - shadowCoord.y;
|
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 distToLight = pxlPosLightProj.z / lightRange;
|
||||||
float shadowed = softShadow_filter(TORQUE_SAMPLER2D_MAKEARG(shadowMap), ssPos.xy, shadowCoord, shadowSoftness, distToLight, surfaceToLight.NdotL, lightParams.y);
|
float shadowed = softShadow_filter(TORQUE_SAMPLER2D_MAKEARG(shadowMap), ssPos.xy, shadowCoord, shadowSoftness, distToLight, surfaceToLight.NdotL, lightParams.y);
|
||||||
#endif
|
#ifdef USE_COOKIE_TEX
|
||||||
|
// Lookup the cookie sample.
|
||||||
float3 lightCol = lightColor.rgb;
|
float4 cookie = TORQUE_TEX2D(cookieMap, shadowCoord);
|
||||||
#ifdef USE_COOKIE_TEX
|
// Multiply the light with the cookie tex.
|
||||||
// Lookup the cookie sample.
|
lightCol *= cookie.rgb;
|
||||||
float4 cookie = TORQUE_TEXCUBE(cookieMap, mul(worldToLightProj, -surfaceToLight.L));
|
// Use a maximum channel luminance to attenuate
|
||||||
// Multiply the light with the cookie tex.
|
// the lighting else we get specular in the dark
|
||||||
lightCol *= cookie.rgb;
|
// regions of the cookie texture.
|
||||||
// Use a maximum channel luminance to attenuate
|
lightCol *= max(cookie.r, max(cookie.g, cookie.b));
|
||||||
// the lighting else we get specular in the dark
|
#endif
|
||||||
// regions of the cookie texture.
|
#endif
|
||||||
lightCol *= max(cookie.r, max(cookie.g, cookie.b));
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef DIFFUSE_LIGHT_VIZ
|
#ifdef DIFFUSE_LIGHT_VIZ
|
||||||
float attenuation = getDistanceAtt(surfaceToLight.Lu, radius);
|
float attenuation = getDistanceAtt(surfaceToLight.Lu, radius);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue