| 457 | } |
| 458 | |
| 459 | void ProjectedShadow::_renderToTexture( F32 camDist, const TSRenderState &rdata ) |
| 460 | { |
| 461 | PROFILE_SCOPE( ProjectedShadow_RenderToTexture ); |
| 462 | |
| 463 | GFXDEBUGEVENT_SCOPE( ProjectedShadow_RenderToTexture, ColorI( 255, 0, 0 ) ); |
| 464 | |
| 465 | RenderPassManager *renderPass = _getRenderPass(); |
| 466 | if ( !renderPass ) |
| 467 | return; |
| 468 | |
| 469 | GFXTransformSaver saver; |
| 470 | |
| 471 | // NOTE: GFXTransformSaver does not save/restore the frustum |
| 472 | // so we must save it here before we modify it. |
| 473 | F32 l, r, b, t, n, f; |
| 474 | bool ortho; |
| 475 | GFX->getFrustum( &l, &r, &b, &t, &n, &f, &ortho ); |
| 476 | |
| 477 | // Set the orthographic projection |
| 478 | // matrix up, to be based on the radius |
| 479 | // generated based on our shape. |
| 480 | GFX->setOrtho( -mRadius, mRadius, -mRadius, mRadius, 0.001f, (mRadius * 2) * smDepthAdjust, true ); |
| 481 | |
| 482 | // Set the world to light space |
| 483 | // matrix set up in shouldRender(). |
| 484 | GFX->setWorldMatrix( mWorldToLight ); |
| 485 | |
| 486 | // Get the shapebase datablock if we have one. |
| 487 | ShapeBaseData *data = NULL; |
| 488 | if ( mShapeBase ) |
| 489 | data = static_cast<ShapeBaseData*>( mShapeBase->getDataBlock() ); |
| 490 | |
| 491 | // Init or update the shadow texture size. |
| 492 | if ( mShadowTexture.isNull() || ( data && data->shadowSize != mShadowTexture.getWidth() ) ) |
| 493 | { |
| 494 | U32 texSize = getNextPow2( data ? data->shadowSize : 256 * LightShadowMap::smShadowTexScalar ); |
| 495 | mShadowTexture.set( texSize, texSize, GFXFormatR8G8B8A8, &PostFxTargetProfile, "BLShadow" ); |
| 496 | } |
| 497 | |
| 498 | GFX->pushActiveRenderTarget(); |
| 499 | |
| 500 | if ( !mRenderTarget ) |
| 501 | mRenderTarget = GFX->allocRenderToTextureTarget(); |
| 502 | |
| 503 | mRenderTarget->attachTexture( GFXTextureTarget::DepthStencil, _getDepthTarget( mShadowTexture->getWidth(), mShadowTexture->getHeight() ) ); |
| 504 | mRenderTarget->attachTexture( GFXTextureTarget::Color0, mShadowTexture ); |
| 505 | GFX->setActiveRenderTarget( mRenderTarget ); |
| 506 | |
| 507 | GFX->clear( GFXClearZBuffer | GFXClearStencil | GFXClearTarget, ColorI( 0, 0, 0, 0 ), 1.0f, 0 ); |
| 508 | |
| 509 | const SceneRenderState *diffuseState = rdata.getSceneState(); |
| 510 | SceneManager *sceneManager = diffuseState->getSceneManager(); |
| 511 | |
| 512 | SceneRenderState baseState |
| 513 | ( |
| 514 | sceneManager, |
| 515 | SPT_Shadow, |
| 516 | SceneCameraState::fromGFXWithViewport( diffuseState->getViewport() ), |
nothing calls this directly
no test coverage detected