| 192 | } |
| 193 | |
| 194 | void PSSMLightShadowMap::_render( RenderPassManager* renderPass, |
| 195 | const SceneRenderState *diffuseState ) |
| 196 | { |
| 197 | PROFILE_SCOPE(PSSMLightShadowMap_render); |
| 198 | |
| 199 | const ShadowMapParams *params = mLight->getExtended<ShadowMapParams>(); |
| 200 | const LightMapParams *lmParams = mLight->getExtended<LightMapParams>(); |
| 201 | const bool bUseLightmappedGeometry = lmParams ? !lmParams->representedInLightmap || lmParams->includeLightmappedGeometryInShadow : true; |
| 202 | |
| 203 | const U32 texSize = getBestTexSize( params->numSplits < 4 ? params->numSplits : 2 ); |
| 204 | |
| 205 | if ( mShadowMapTex.isNull() || |
| 206 | mNumSplits != params->numSplits || |
| 207 | mTexSize != texSize ) |
| 208 | { |
| 209 | _setNumSplits( params->numSplits, texSize ); |
| 210 | mShadowMapDepth = _getDepthTarget( mShadowMapTex->getWidth(), mShadowMapTex->getHeight() ); |
| 211 | } |
| 212 | mLogWeight = params->logWeight; |
| 213 | |
| 214 | Frustum fullFrustum( diffuseState->getCameraFrustum() ); |
| 215 | fullFrustum.cropNearFar(fullFrustum.getNearDist(), params->shadowDistance); |
| 216 | |
| 217 | GFXFrustumSaver frustSaver; |
| 218 | GFXTransformSaver saver; |
| 219 | |
| 220 | // Set our render target |
| 221 | GFX->pushActiveRenderTarget(); |
| 222 | mTarget->attachTexture( GFXTextureTarget::Color0, mShadowMapTex ); |
| 223 | mTarget->attachTexture( GFXTextureTarget::DepthStencil, mShadowMapDepth ); |
| 224 | GFX->setActiveRenderTarget( mTarget ); |
| 225 | GFX->clear( GFXClearStencil | GFXClearZBuffer | GFXClearTarget, ColorI(255,255,255), 1.0f, 0 ); |
| 226 | |
| 227 | // Calculate our standard light matrices |
| 228 | MatrixF lightMatrix; |
| 229 | calcLightMatrices( lightMatrix, diffuseState->getCameraFrustum() ); |
| 230 | lightMatrix.inverse(); |
| 231 | MatrixF lightViewProj = GFX->getProjectionMatrix() * lightMatrix; |
| 232 | |
| 233 | // TODO: This is just retrieving the near and far calculated |
| 234 | // in calcLightMatrices... we should make that clear. |
| 235 | F32 pnear, pfar; |
| 236 | GFX->getFrustum( NULL, NULL, NULL, NULL, &pnear, &pfar, NULL ); |
| 237 | |
| 238 | // Set our view up |
| 239 | GFX->setWorldMatrix(lightMatrix); |
| 240 | MatrixF toLightSpace = lightMatrix; // * invCurrentView; |
| 241 | |
| 242 | _calcSplitPos(fullFrustum); |
| 243 | |
| 244 | mWorldToLightProj = GFX->getProjectionMatrix() * toLightSpace; |
| 245 | |
| 246 | // Apply the PSSM |
| 247 | const F32 savedSmallestVisible = TSShapeInstance::smSmallestVisiblePixelSize; |
| 248 | const F32 savedDetailAdjust = TSShapeInstance::smDetailAdjust; |
| 249 | TSShapeInstance::smDetailAdjust *= smDetailAdjustScale; |
| 250 | TSShapeInstance::smSmallestVisiblePixelSize = smSmallestVisiblePixelSize; |
| 251 |
nothing calls this directly
no test coverage detected