Add support for both ies and cookie

Both ies and cookies can now exist on a light

We are still not using all the capabilities of an IES profile, such as candela and luminance values we are just using them as a mask for the moment

Issues compiling on mac and linux, will need to update the ies-loader to use torque methods instead of std::
This commit is contained in:
marauder2k7 2024-02-21 07:40:57 +00:00
parent a12d915180
commit 4417462499
10 changed files with 142 additions and 27 deletions

View file

@ -107,10 +107,13 @@ TORQUE_UNIFORM_SAMPLER2D(shadowMap, 1);
#include "softShadow.hlsl"
TORQUE_UNIFORM_SAMPLER2D(colorBuffer, 3);
TORQUE_UNIFORM_SAMPLER2D(matInfoBuffer, 4);
#ifdef USE_COOKIE_TEX
/// The texture for cookie rendering.
#ifdef SHADOW_CUBE
TORQUE_UNIFORM_SAMPLERCUBE(cookieMap, 5);
#else
TORQUE_UNIFORM_SAMPLER2D(cookieMap, 5);
#endif
TORQUE_UNIFORM_SAMPLER2D(iesProfile, 6);
uniform float4 rtParams0;
uniform float4 lightColor;
@ -159,8 +162,8 @@ float4 main( ConvexConnectP IN ) : SV_TARGET
{
float distToLight = dist / lightRange;
SurfaceToLight surfaceToLight = createSurfaceToLight(surface, L);
float shadow = 1.0;
float3 lightCol = lightColor.rgb;
float shadow = 1.0;
#ifndef NO_SHADOW
if (getFlag(surface.matFlag, 0)) //also skip if we don't recieve shadows
{
@ -176,8 +179,21 @@ float4 main( ConvexConnectP IN ) : SV_TARGET
#endif
}
#endif // !NO_SHADOW
float3 lightCol = lightColor.rgb;
#ifdef USE_COOKIE_TEX
// Lookup the cookie sample.
#ifdef SHADOW_CUBE
float4 cookie = TORQUE_TEXCUBE(cookieMap, mul(worldToLightProj, -surfaceToLight.L));
#else
float2 cookieCoord = decodeShadowCoord( mul( worldToLightProj, -surfaceToLight.L ) ).xy;
float4 cookie = TORQUE_TEX2D(cookieMap, cookieCoord);
#endif
// 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);
float3 factor = lightColor * max(surfaceToLight.NdotL, 0) * shadow * lightIntensity * attenuation;
@ -210,13 +226,13 @@ float4 main( ConvexConnectP IN ) : SV_TARGET
//get punctual light contribution
lighting = getPunctualLight(surface, surfaceToLight, lightCol, lightBrightness, lightInvSqrRange, shadow);
#ifdef USE_COOKIE_TEX
#ifdef UES_PHOTOMETRIC_MASK
// Lookup the cookie sample.d
float cosTheta = dot(-surfaceToLight.L, lightDirection);
float angle = acos(cosTheta) * ( M_1OVER_PI_F);
float cookie = TORQUE_TEX2D(cookieMap, float2(angle, 0.0)).r;
// Multiply the light with the cookie tex.
lighting *= cookie;
float iesMask = TORQUE_TEX2D(iesProfile, float2(angle, 0.0)).r;
// Multiply the light with the iesMask tex.
lighting *= iesMask;
#endif
}

View file

@ -42,11 +42,10 @@ TORQUE_UNIFORM_SAMPLER2D(shadowMap, 1);
#include "softShadow.hlsl"
TORQUE_UNIFORM_SAMPLER2D(colorBuffer, 3);
TORQUE_UNIFORM_SAMPLER2D(matInfoBuffer, 4);
#ifdef USE_COOKIE_TEX
/// The texture for cookie rendering.
TORQUE_UNIFORM_SAMPLER2D(cookieMap, 5);
TORQUE_UNIFORM_SAMPLER2D(iesProfile, 6);
#endif
uniform float4 rtParams0;
uniform float lightBrightness;
@ -96,8 +95,7 @@ float4 main( ConvexConnectP IN ) : SV_TARGET
if(dist < lightRange)
{
SurfaceToLight surfaceToLight = createSurfaceToLight(surface, L);
float3 lightCol = lightColor.rgb;
float shadow = 1.0;
#ifndef NO_SHADOW
if (getFlag(surface.matFlag, 0)) //also skip if we don't recieve shadows
@ -109,10 +107,23 @@ float4 main( ConvexConnectP IN ) : SV_TARGET
//distance to light in shadow map space
float distToLight = pxlPosLightProj.z / lightRange;
shadow = softShadow_filter(TORQUE_SAMPLER2D_MAKEARG(shadowMap), ssPos.xy, shadowCoord, shadowSoftness, distToLight, surfaceToLight.NdotL, lightParams.y);
}
#endif
float3 lightCol = lightColor.rgb;
#ifdef USE_COOKIE_TEX
float4 pxlPosLightProj = mul( worldToLightProj, float4( surface.P, 1 ) );
float2 cookieCoord = ( ( pxlPosLightProj.xy / pxlPosLightProj.w ) * 0.5 ) + float2( 0.5, 0.5 );
// Lookup the cookie sample.
float4 cookie = TORQUE_TEX2D(cookieMap, cookieCoord);
// 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);
float3 factor = lightColor * max(surfaceToLight.NdotL, 0) * shadow * lightIntensity * attenuation;
@ -144,13 +155,13 @@ float4 main( ConvexConnectP IN ) : SV_TARGET
//get spot light contribution
lighting = getSpotlight(surface, surfaceToLight, lightCol, lightBrightness, lightInvSqrRange, lightDirection, lightSpotParams, shadow);
#ifdef USE_COOKIE_TEX
#ifdef UES_PHOTOMETRIC_MASK
// Lookup the cookie sample.d
float cosTheta = dot(-surfaceToLight.L, lightDirection);
float angle = acos(cosTheta) * ( M_1OVER_PI_F);
float cookie = TORQUE_TEX2D(cookieMap, float2(angle, 0.0)).r;
// Multiply the light with the cookie tex.
lighting *= cookie;
float iesMask = TORQUE_TEX2D(iesProfile, float2(angle, 0.0)).r;
// Multiply the light with the iesMask tex.
lighting *= iesMask;
#endif
}