From 0b7fd2f0b3723293b98a363dc311d3ba869f0d29 Mon Sep 17 00:00:00 2001 From: AzaezelX Date: Thu, 22 Feb 2024 16:00:26 -0600 Subject: [PATCH 1/7] ies bugfixes --- .../core/lighting/scripts/advancedLighting_Shaders.tscript | 7 +++++-- .../shaders/lighting/advanced/gl/pointLightP.glsl | 1 + 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/Templates/BaseGame/game/core/lighting/scripts/advancedLighting_Shaders.tscript b/Templates/BaseGame/game/core/lighting/scripts/advancedLighting_Shaders.tscript index 104056efe..964e9e045 100644 --- a/Templates/BaseGame/game/core/lighting/scripts/advancedLighting_Shaders.tscript +++ b/Templates/BaseGame/game/core/lighting/scripts/advancedLighting_Shaders.tscript @@ -118,6 +118,7 @@ singleton GFXStateBlockData( AL_ConvexLightState ) samplerStates[3] = SamplerClampPoint; // colorBuffer samplerStates[4] = SamplerClampPoint; // matInfoBuffer samplerStates[5] = SamplerClampLinear; // Cookie Map + samplerStates[6] = SamplerClampLinear; // Cookie Map cullDefined = true; cullMode = GFXCullCW; @@ -142,6 +143,7 @@ singleton shaderData( AL_PointLightShader ) samplerNames[3] = "$colorBuffer"; samplerNames[4] = "$matInfoBuffer"; samplerNames[5] = "$cookieMap"; + samplerNames[6] = "$iesProfile"; pixVersion = 3.0; }; @@ -156,7 +158,7 @@ singleton CustomMaterial( AL_PointLightMaterial ) sampler["cookieMap"] = "$dynamiclightmask"; sampler["colorBuffer"] = "#color"; sampler["matInfoBuffer"] = "#matinfo"; - + sampler["iesProfile"] = "$photometricmask"; target = "AL_FormatToken"; pixVersion = 3.0; @@ -177,6 +179,7 @@ singleton shaderData( AL_SpotLightShader ) samplerNames[3] = "$colorBuffer"; samplerNames[4] = "$matInfoBuffer"; samplerNames[5] = "$cookieMap"; + samplerNames[6] = "$iesProfile"; pixVersion = 3.0; }; @@ -191,7 +194,7 @@ singleton CustomMaterial( AL_SpotLightMaterial ) sampler["cookieMap"] = "$dynamiclightmask"; sampler["colorBuffer"] = "#color"; sampler["matInfoBuffer"] = "#matinfo"; - + sampler["iesProfile"] = "$photometricmask"; target = "AL_FormatToken"; pixVersion = 3.0; diff --git a/Templates/BaseGame/game/core/rendering/shaders/lighting/advanced/gl/pointLightP.glsl b/Templates/BaseGame/game/core/rendering/shaders/lighting/advanced/gl/pointLightP.glsl index 7e6984e21..01a547011 100644 --- a/Templates/BaseGame/game/core/rendering/shaders/lighting/advanced/gl/pointLightP.glsl +++ b/Templates/BaseGame/game/core/rendering/shaders/lighting/advanced/gl/pointLightP.glsl @@ -120,6 +120,7 @@ uniform sampler2D iesProfile; uniform vec4 rtParams0; uniform vec3 lightPosition; +uniform vec3 lightDirection; uniform vec4 lightColor; uniform float lightBrightness; uniform float lightRange; From 14b6822e49f08d01405c6fb08c2f425ed0cd7e46 Mon Sep 17 00:00:00 2001 From: AzaezelX Date: Thu, 22 Feb 2024 17:53:53 -0600 Subject: [PATCH 2/7] a) use a 1d texture for this b) if we're going to optionally assign iesProfiles via shadowMacros.push_back, should specify the entries for the samplers too --- .../lighting/advanced/gl/pointLightP.glsl | 16 ++++++++++------ .../lighting/advanced/gl/spotLightP.glsl | 18 +++++++++++++----- .../shaders/lighting/advanced/pointLightP.hlsl | 17 +++++++++++------ .../shaders/lighting/advanced/spotLightP.hlsl | 17 ++++++++++++----- 4 files changed, 46 insertions(+), 22 deletions(-) diff --git a/Templates/BaseGame/game/core/rendering/shaders/lighting/advanced/gl/pointLightP.glsl b/Templates/BaseGame/game/core/rendering/shaders/lighting/advanced/gl/pointLightP.glsl index 01a547011..b0b02d226 100644 --- a/Templates/BaseGame/game/core/rendering/shaders/lighting/advanced/gl/pointLightP.glsl +++ b/Templates/BaseGame/game/core/rendering/shaders/lighting/advanced/gl/pointLightP.glsl @@ -108,6 +108,7 @@ uniform sampler2D deferredBuffer; #include "softShadow.glsl" uniform sampler2D colorBuffer; uniform sampler2D matInfoBuffer; + #ifdef SHADOW_CUBE /// The texture for cookie rendering. uniform samplerCube cookieMap; @@ -115,7 +116,9 @@ uniform samplerCube cookieMap; uniform sampler2D cookieMap; #endif -uniform sampler2D iesProfile; +#ifdef UES_PHOTOMETRIC_MASK +uniform sampler1D iesProfile; +#endif uniform vec4 rtParams0; @@ -231,17 +234,18 @@ void main() OUT_col = vec4(final, 0); return #endif - - //get punctual light contribution - lighting = getPunctualLight(surface, surfaceToLight, lightCol, lightBrightness, lightInvSqrRange, shadow); + #ifdef UES_PHOTOMETRIC_MASK // Lookup the cookie sample.d float cosTheta = dot(-surfaceToLight.L, lightDirection); float angle = acos(cosTheta) * ( M_1OVER_PI_F); - float iesMask = texture(iesProfile, vec2(angle, 0.0)).r; + float iesMask = texture(iesProfile,angle).r; // Multiply the light with the iesMask tex. - lighting *= iesMask; + shadow *= iesMask; #endif + + //get punctual light contribution + lighting = getPunctualLight(surface, surfaceToLight, lightCol, lightBrightness, lightInvSqrRange, shadow); } diff --git a/Templates/BaseGame/game/core/rendering/shaders/lighting/advanced/gl/spotLightP.glsl b/Templates/BaseGame/game/core/rendering/shaders/lighting/advanced/gl/spotLightP.glsl index f5983eb0d..f96212c8d 100644 --- a/Templates/BaseGame/game/core/rendering/shaders/lighting/advanced/gl/spotLightP.glsl +++ b/Templates/BaseGame/game/core/rendering/shaders/lighting/advanced/gl/spotLightP.glsl @@ -38,8 +38,15 @@ uniform sampler2D shadowMap; #include "softShadow.glsl" uniform sampler2D colorBuffer; uniform sampler2D matInfoBuffer; + +#ifdef USE_COOKIE_TEX uniform sampler2D cookieMap; -uniform sampler2D iesProfile; +#endif + +#ifdef UES_PHOTOMETRIC_MASK +uniform sampler1D iesProfile; +#endif + uniform vec4 rtParams0; uniform float lightBrightness; @@ -154,16 +161,17 @@ void main() return; #endif - //get spot light contribution - lighting = getSpotlight(surface, surfaceToLight, lightCol, lightBrightness, lightInvSqrRange, lightDirection, lightSpotParams, shadow); #ifdef UES_PHOTOMETRIC_MASK // Lookup the cookie sample.d float cosTheta = dot(-surfaceToLight.L, lightDirection); float angle = acos(cosTheta) * ( M_1OVER_PI_F); - float iesMask = texture(iesProfile, vec2(angle, 0.0)).r; + float iesMask = texture(iesProfile, angle).r; // Multiply the light with the iesMask tex. - lighting *= iesMask; + shadow *= iesMask; #endif + + //get spot light contribution + lighting = getSpotlight(surface, surfaceToLight, lightCol, lightBrightness, lightInvSqrRange, lightDirection, lightSpotParams, shadow); } OUT_col = vec4(lighting, 0); diff --git a/Templates/BaseGame/game/core/rendering/shaders/lighting/advanced/pointLightP.hlsl b/Templates/BaseGame/game/core/rendering/shaders/lighting/advanced/pointLightP.hlsl index de3d3433f..747f168a6 100644 --- a/Templates/BaseGame/game/core/rendering/shaders/lighting/advanced/pointLightP.hlsl +++ b/Templates/BaseGame/game/core/rendering/shaders/lighting/advanced/pointLightP.hlsl @@ -107,13 +107,17 @@ TORQUE_UNIFORM_SAMPLER2D(shadowMap, 1); #include "softShadow.hlsl" TORQUE_UNIFORM_SAMPLER2D(colorBuffer, 3); TORQUE_UNIFORM_SAMPLER2D(matInfoBuffer, 4); + /// 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); + +#ifdef UES_PHOTOMETRIC_MASK +TORQUE_UNIFORM_SAMPLER1D(iesProfile, 6); +#endif uniform float4 rtParams0; uniform float4 lightColor; @@ -223,17 +227,18 @@ float4 main( ConvexConnectP IN ) : SV_TARGET return final; #endif - //get punctual light contribution - lighting = getPunctualLight(surface, surfaceToLight, lightCol, lightBrightness, lightInvSqrRange, shadow); - #ifdef UES_PHOTOMETRIC_MASK // Lookup the cookie sample.d float cosTheta = dot(-surfaceToLight.L, lightDirection); float angle = acos(cosTheta) * ( M_1OVER_PI_F); - float iesMask = TORQUE_TEX2D(iesProfile, float2(angle, 0.0)).r; + float iesMask = TORQUE_TEX2D(iesProfile, angle).r; // Multiply the light with the iesMask tex. - lighting *= iesMask; + shadow *= iesMask; #endif + + //get punctual light contribution + lighting = getPunctualLight(surface, surfaceToLight, lightCol, lightBrightness, lightInvSqrRange, shadow); + } diff --git a/Templates/BaseGame/game/core/rendering/shaders/lighting/advanced/spotLightP.hlsl b/Templates/BaseGame/game/core/rendering/shaders/lighting/advanced/spotLightP.hlsl index efd07fa30..dc47ea23d 100644 --- a/Templates/BaseGame/game/core/rendering/shaders/lighting/advanced/spotLightP.hlsl +++ b/Templates/BaseGame/game/core/rendering/shaders/lighting/advanced/spotLightP.hlsl @@ -43,8 +43,14 @@ TORQUE_UNIFORM_SAMPLER2D(shadowMap, 1); TORQUE_UNIFORM_SAMPLER2D(colorBuffer, 3); TORQUE_UNIFORM_SAMPLER2D(matInfoBuffer, 4); /// The texture for cookie rendering. + +#ifdef USE_COOKIE_TEX TORQUE_UNIFORM_SAMPLER2D(cookieMap, 5); -TORQUE_UNIFORM_SAMPLER2D(iesProfile, 6); +#endif + +#ifdef UES_PHOTOMETRIC_MASK +TORQUE_UNIFORM_SAMPLER1D(iesProfile, 6); +#endif uniform float4 rtParams0; @@ -153,16 +159,17 @@ float4 main( ConvexConnectP IN ) : SV_TARGET return final; #endif - //get spot light contribution - lighting = getSpotlight(surface, surfaceToLight, lightCol, lightBrightness, lightInvSqrRange, lightDirection, lightSpotParams, shadow); #ifdef UES_PHOTOMETRIC_MASK // Lookup the cookie sample.d float cosTheta = dot(-surfaceToLight.L, lightDirection); float angle = acos(cosTheta) * ( M_1OVER_PI_F); - float iesMask = TORQUE_TEX2D(iesProfile, float2(angle, 0.0)).r; + float iesMask = TORQUE_TEX1D(iesProfile, angle).r; // Multiply the light with the iesMask tex. - lighting *= iesMask; + shadow *= iesMask; #endif + + //get spot light contribution + lighting = getSpotlight(surface, surfaceToLight, lightCol, lightBrightness, lightInvSqrRange, lightDirection, lightSpotParams, shadow); } return float4(lighting, 0); From bbe9bc88711fd7dc4d594f622eb487eaaa8b9d48 Mon Sep 17 00:00:00 2001 From: AzaezelX Date: Thu, 22 Feb 2024 23:47:57 -0600 Subject: [PATCH 3/7] missed a 1d convert --- .../core/rendering/shaders/lighting/advanced/pointLightP.hlsl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Templates/BaseGame/game/core/rendering/shaders/lighting/advanced/pointLightP.hlsl b/Templates/BaseGame/game/core/rendering/shaders/lighting/advanced/pointLightP.hlsl index 747f168a6..ab5145849 100644 --- a/Templates/BaseGame/game/core/rendering/shaders/lighting/advanced/pointLightP.hlsl +++ b/Templates/BaseGame/game/core/rendering/shaders/lighting/advanced/pointLightP.hlsl @@ -231,7 +231,7 @@ float4 main( ConvexConnectP IN ) : SV_TARGET // Lookup the cookie sample.d float cosTheta = dot(-surfaceToLight.L, lightDirection); float angle = acos(cosTheta) * ( M_1OVER_PI_F); - float iesMask = TORQUE_TEX2D(iesProfile, angle).r; + float iesMask = TORQUE_TEX1D(iesProfile, angle).r; // Multiply the light with the iesMask tex. shadow *= iesMask; #endif From c27b9bf48fbb480e9463f02668be7305f34c52dd Mon Sep 17 00:00:00 2001 From: AzaezelX Date: Fri, 23 Feb 2024 01:28:15 -0600 Subject: [PATCH 4/7] allow spotlights specifically to comprress ies based on angle differentials --- .../core/rendering/shaders/lighting/advanced/gl/spotLightP.glsl | 2 +- .../core/rendering/shaders/lighting/advanced/spotLightP.hlsl | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Templates/BaseGame/game/core/rendering/shaders/lighting/advanced/gl/spotLightP.glsl b/Templates/BaseGame/game/core/rendering/shaders/lighting/advanced/gl/spotLightP.glsl index f96212c8d..0c423630e 100644 --- a/Templates/BaseGame/game/core/rendering/shaders/lighting/advanced/gl/spotLightP.glsl +++ b/Templates/BaseGame/game/core/rendering/shaders/lighting/advanced/gl/spotLightP.glsl @@ -165,7 +165,7 @@ void main() // Lookup the cookie sample.d float cosTheta = dot(-surfaceToLight.L, lightDirection); float angle = acos(cosTheta) * ( M_1OVER_PI_F); - float iesMask = texture(iesProfile, angle).r; + float iesMask = texture(iesProfile, angle/(lightSpotParams.x-lightSpotParams.y)).r; // Multiply the light with the iesMask tex. shadow *= iesMask; #endif diff --git a/Templates/BaseGame/game/core/rendering/shaders/lighting/advanced/spotLightP.hlsl b/Templates/BaseGame/game/core/rendering/shaders/lighting/advanced/spotLightP.hlsl index dc47ea23d..c2d8d1e9e 100644 --- a/Templates/BaseGame/game/core/rendering/shaders/lighting/advanced/spotLightP.hlsl +++ b/Templates/BaseGame/game/core/rendering/shaders/lighting/advanced/spotLightP.hlsl @@ -163,7 +163,7 @@ float4 main( ConvexConnectP IN ) : SV_TARGET // Lookup the cookie sample.d float cosTheta = dot(-surfaceToLight.L, lightDirection); float angle = acos(cosTheta) * ( M_1OVER_PI_F); - float iesMask = TORQUE_TEX1D(iesProfile, angle).r; + float iesMask = TORQUE_TEX1D(iesProfile, angle/(lightSpotParams.x-lightSpotParams.y)).r; // Multiply the light with the iesMask tex. shadow *= iesMask; #endif From 4d1395dd57832ad87e230d6e9a92934ed7b732e4 Mon Sep 17 00:00:00 2001 From: AzaezelX Date: Fri, 23 Feb 2024 11:23:07 -0600 Subject: [PATCH 5/7] from mar: fix the opengl cookie uv lookup --- .../shaders/lighting/advanced/gl/spotLightP.glsl | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/Templates/BaseGame/game/core/rendering/shaders/lighting/advanced/gl/spotLightP.glsl b/Templates/BaseGame/game/core/rendering/shaders/lighting/advanced/gl/spotLightP.glsl index 0c423630e..3585bfde2 100644 --- a/Templates/BaseGame/game/core/rendering/shaders/lighting/advanced/gl/spotLightP.glsl +++ b/Templates/BaseGame/game/core/rendering/shaders/lighting/advanced/gl/spotLightP.glsl @@ -19,7 +19,6 @@ // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS // IN THE SOFTWARE. //----------------------------------------------------------------------------- - #include "../../../gl/hlslCompat.glsl" #include "farFrustumQuad.glsl" #include "../../shadowMap/shadowMapIO_GLSL.h" @@ -116,7 +115,10 @@ void main() vec3 lightCol = lightColor.rgb; #ifdef USE_COOKIE_TEX // Lookup the cookie sample. - vec4 cookie = texture(cookieMap, shadowCoord); + vec4 pxlPosLightProj = tMul( worldToLightProj, vec4( surface.P, 1 ) ); + vec2 cookieCoord = ( ( pxlPosLightProj.xy / pxlPosLightProj.w ) * 0.5 ) + vec2( 0.5, 0.5 ); + cookieCoord.y = 1.0f - cookieCoord.y; + vec4 cookie = texture(cookieMap, cookieCoord); // Multiply the light with the cookie tex. lightCol *= cookie.rgb; // Use a maximum channel luminance to attenuate @@ -169,7 +171,7 @@ void main() // Multiply the light with the iesMask tex. shadow *= iesMask; #endif - + //get spot light contribution lighting = getSpotlight(surface, surfaceToLight, lightCol, lightBrightness, lightInvSqrRange, lightDirection, lightSpotParams, shadow); } From c7cc86b357e0a8602adeff91d12ba761159f1c4f Mon Sep 17 00:00:00 2001 From: AzaezelX Date: Fri, 23 Feb 2024 11:52:43 -0600 Subject: [PATCH 6/7] clamp spot angle to 179, up custommaterial inputs to 16 add Material::PhotometricMask:handling to processedcustommaterial and for paranoias sake go ahead and be explicit about _getLightMaterial (those *should* be unneeded as they optionally default to that, but it's how they were in the beatup fork during testing) --- Engine/source/T3D/spotLight.cpp | 2 +- Engine/source/lighting/advanced/advancedLightBinManager.cpp | 4 ++-- Engine/source/materials/materialDefinition.h | 2 +- Engine/source/materials/processedCustomMaterial.cpp | 1 + 4 files changed, 5 insertions(+), 4 deletions(-) diff --git a/Engine/source/T3D/spotLight.cpp b/Engine/source/T3D/spotLight.cpp index 3f43305f7..6653a5365 100644 --- a/Engine/source/T3D/spotLight.cpp +++ b/Engine/source/T3D/spotLight.cpp @@ -132,7 +132,7 @@ void SpotLight::_conformLights() mLight->setDynamicRefreshFreq(mDynamicRefreshFreq); mLight->setPriority( mPriority ); - mOuterConeAngle = getMax( 0.01f, mOuterConeAngle ); + mOuterConeAngle = getMin(getMax( 0.01f, mOuterConeAngle ),179.0f); mInnerConeAngle = getMin( mInnerConeAngle, mOuterConeAngle ); mLight->setInnerConeAngle( mInnerConeAngle ); diff --git a/Engine/source/lighting/advanced/advancedLightBinManager.cpp b/Engine/source/lighting/advanced/advancedLightBinManager.cpp index 431ec28ad..24637de6c 100644 --- a/Engine/source/lighting/advanced/advancedLightBinManager.cpp +++ b/Engine/source/lighting/advanced/advancedLightBinManager.cpp @@ -399,9 +399,9 @@ void AdvancedLightBinManager::render( SceneRenderState *state ) sunLight->getCastShadows() && !disableShadows && sunLight->getExtended() ) - vectorMatInfo = _getLightMaterial( LightInfo::Vector, ShadowType_PSSM ); + vectorMatInfo = _getLightMaterial( LightInfo::Vector, ShadowType_PSSM,false,false ); else - vectorMatInfo = _getLightMaterial( LightInfo::Vector, ShadowType_None ); + vectorMatInfo = _getLightMaterial( LightInfo::Vector, ShadowType_None, false, false); // Initialize and set the per-frame parameters after getting // the vector light material as we use lazy creation. diff --git a/Engine/source/materials/materialDefinition.h b/Engine/source/materials/materialDefinition.h index 504fecaa6..29996cf66 100644 --- a/Engine/source/materials/materialDefinition.h +++ b/Engine/source/materials/materialDefinition.h @@ -71,7 +71,7 @@ public: //----------------------------------------------------------------------- enum Constants { - MAX_TEX_PER_PASS = 8, ///< Number of textures per pass + MAX_TEX_PER_PASS = 16, ///< Number of textures per pass MAX_STAGES = 4, NUM_EFFECT_COLOR_STAGES = 2, ///< Number of effect color definitions for transitioning effects. }; diff --git a/Engine/source/materials/processedCustomMaterial.cpp b/Engine/source/materials/processedCustomMaterial.cpp index 15772c078..1610d7ec9 100644 --- a/Engine/source/materials/processedCustomMaterial.cpp +++ b/Engine/source/materials/processedCustomMaterial.cpp @@ -361,6 +361,7 @@ void ProcessedCustomMaterial::setTextureStages( SceneRenderState *state, const S break; case Material::Mask: + case Material::PhotometricMask: case Material::Standard: case Material::Bump: case Material::Detail: From 3ab716063f17a223ca6287bb5377a653950efade Mon Sep 17 00:00:00 2001 From: AzaezelX Date: Fri, 23 Feb 2024 12:39:26 -0600 Subject: [PATCH 7/7] doc correction --- .../core/lighting/scripts/advancedLighting_Shaders.tscript | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Templates/BaseGame/game/core/lighting/scripts/advancedLighting_Shaders.tscript b/Templates/BaseGame/game/core/lighting/scripts/advancedLighting_Shaders.tscript index 964e9e045..1fcee6079 100644 --- a/Templates/BaseGame/game/core/lighting/scripts/advancedLighting_Shaders.tscript +++ b/Templates/BaseGame/game/core/lighting/scripts/advancedLighting_Shaders.tscript @@ -118,7 +118,7 @@ singleton GFXStateBlockData( AL_ConvexLightState ) samplerStates[3] = SamplerClampPoint; // colorBuffer samplerStates[4] = SamplerClampPoint; // matInfoBuffer samplerStates[5] = SamplerClampLinear; // Cookie Map - samplerStates[6] = SamplerClampLinear; // Cookie Map + samplerStates[6] = SamplerClampLinear; // iesProfile cullDefined = true; cullMode = GFXCullCW; @@ -191,10 +191,10 @@ singleton CustomMaterial( AL_SpotLightMaterial ) sampler["deferredBuffer"] = "#deferred"; sampler["shadowMap"] = "$dynamiclight"; + sampler["iesProfile"] = "$photometricmask"; sampler["cookieMap"] = "$dynamiclightmask"; sampler["colorBuffer"] = "#color"; sampler["matInfoBuffer"] = "#matinfo"; - sampler["iesProfile"] = "$photometricmask"; target = "AL_FormatToken"; pixVersion = 3.0;