PSSM Shadow Fix

fixes the issue with pssm shadows were the softness value makes the shadow cast on the entire cascade.
This commit is contained in:
marauder2k7 2026-03-12 20:47:19 +00:00
parent 058983aa42
commit 6a8d832bd6
3 changed files with 143 additions and 98 deletions

View file

@ -191,6 +191,16 @@ void PSSMLightShadowMap::_roundProjection(const MatrixF& lightMat, const MatrixF
}
void PSSMLightShadowMap::_adjustScaleAndOffset(Box3F& clipAABB, Point3F& scale, Point3F& offset) {
const ShadowMapParams* params = mLight->getExtended<ShadowMapParams>();
F32 padding = params->shadowSoftness * (2.0f / (F32)mTexSize);
clipAABB.minExtents.x -= padding;
clipAABB.minExtents.y -= padding;
clipAABB.maxExtents.x += padding;
clipAABB.maxExtents.y += padding;
scale.x = 2.0f / (clipAABB.maxExtents.x - clipAABB.minExtents.x);
scale.y = 2.0f / (clipAABB.maxExtents.y - clipAABB.minExtents.y);
scale.z = 1.0f;
@ -469,7 +479,7 @@ void PSSMLightShadowMap::setShaderParameters(GFXShaderConstBuffer* params, Light
params->setSafe( lsc->mOverDarkFactorPSSM, p->overDarkFactor);
// The softness is a factor of the texel size.
params->setSafe( lsc->mShadowSoftnessConst, p->shadowSoftness * ( 1.0f / mTexSize ) );
params->setSafe( lsc->mShadowSoftnessConst, p->shadowSoftness * ( 2.0f / mTexSize ) );
}
void PSSMLightShadowMap::_calcPlanesCullForShadowCasters(Vector< Vector<PlaneF> > &out, const Frustum &viewFrustum, const Point3F &_ligthDir)

View file

@ -112,6 +112,18 @@ void ShadowMaterialHook::init( BaseMatInstance *inMat )
mShadowMat[ShadowType_Spot] = newMat;
newMat = new ShadowMatInstance(shadowMat);
newMat->setUserObject(inMat->getUserObject());
newMat->getFeaturesDelegate().bind(&ShadowMaterialHook::_overrideFeatures);
forced.setCullMode(GFXCullCW);
forced.zBias = 1000.0f;
forced.zSlopeBias = 1.0f;
forced.setFillModeSolid();
newMat->addStateBlockDesc(forced);
forced.cullDefined = true;
newMat->init(features, inMat->getVertexFormat());
mShadowMat[ShadowType_PSSM] = newMat;
newMat = new ShadowMatInstance( shadowMat );
newMat->setUserObject( inMat->getUserObject() );
newMat->getFeaturesDelegate().bind( &ShadowMaterialHook::_overrideFeatures );
@ -162,12 +174,6 @@ BaseMatInstance* ShadowMaterialHook::getShadowMat( ShadowType type ) const
{
AssertFatal( type < ShadowType_Count, "ShadowMaterialHook::getShadowMat() - Bad light type!" );
// The cubemap and pssm shadows use the same
// spotlight material for shadows.
if ( type == ShadowType_Spot ||
type == ShadowType_PSSM )
return mShadowMat[ShadowType_Spot];
// Get the specialized shadow material.
return mShadowMat[type];
}