MCPcopy Create free account
hub / github.com/carbonengine/trinity / RenderShadowMapForSpotLight

Method RenderShadowMapForSpotLight

trinity/Eve/EveSpaceScene.cpp:2487–2554  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2485}
2486
2487void EveSpaceScene::RenderShadowMapForSpotLight(
2488 Tr2RenderContext& renderContext,
2489 const std::vector<IEveShadowCaster*>& shadowCasters,
2490 uint32_t shadowMapScale,
2491 uint32_t shadowMapOffsetX,
2492 uint32_t shadowMapOffsetY,
2493 const Vector3& lightPosition,
2494 const Matrix& view,
2495 const Matrix& projection,
2496 const Tr2TextureAL& shadowMap )
2497{
2498 CCP_STATS_ZONE( __FUNCTION__ );
2499
2500 renderContext.m_esm.PushViewport();
2501 renderContext.m_esm.UpdateRenderTargetViewport( shadowMap.GetWidth(), shadowMap.GetHeight() );
2502 renderContext.m_esm.SetViewport( shadowMapScale, shadowMapScale, shadowMapOffsetX, shadowMapOffsetY, 0, 1 );
2503
2504 const float margin = 16.f;
2505 const float marginScale = 1.f - ( margin / shadowMapScale );
2506 const Matrix marginMatrix = ScalingMatrix( Vector3( marginScale, marginScale, 1.f ) );
2507 const Matrix viewProj = view * projection * marginMatrix;
2508
2509 TriFrustum shadowFrustum;
2510 shadowFrustum.DeriveFrustum( &view, &lightPosition, &projection, renderContext.m_esm.GetViewport() );
2511 {
2512 CCP_STATS_ZONE( "get shadowbatches for light" );
2513 float sizeInShadow = 0.0f;
2514 for( auto& caster : shadowCasters )
2515 {
2516 caster->IsCastingShadow( m_updateContext.GetFrustum(), TriShadowFrustum( shadowFrustum ), TR2RENDERREASON_NORMAL, sizeInShadow );
2517 // special threshold check
2518 if( sizeInShadow > 5.0f )
2519 {
2520 auto perObjData = caster->GetShadowPerObjectData( m_shadowBatches[0].get() );
2521 caster->GetShadowBatches( m_shadowBatches[0].get(), perObjData, min( (float)shadowMapScale, sizeInShadow ) );
2522 }
2523 }
2524
2525 m_instancedMeshManager->GetShadowBatches( m_updateContext.GetFrustum(), TriShadowFrustum( shadowFrustum ), m_updateContext.GetInvLodFactor(), { { TRIBATCHTYPE_OPAQUE, *m_shadowBatches[0] } } );
2526 }
2527
2528 m_shadowBatches[0]->Finalize();
2529 PerFrameVSData data;
2530 data.ViewProjectionMat = Transpose( viewProj );
2531
2532 static const unsigned perFrameVsMask =
2533 ( 1 << VERTEX_SHADER ) |
2534 SHADER_TYPE_EXISTS( COMPUTE_SHADER ) |
2535 SHADER_TYPE_EXISTS( GEOMETRY_SHADER ) |
2536 SHADER_TYPE_EXISTS( HULL_SHADER ) |
2537 SHADER_TYPE_EXISTS( DOMAIN_SHADER );
2538 FillAndSetConstants( m_shadowPerFrameVSBuffer, &data, sizeof( data ), perFrameVsMask, Tr2Renderer::GetPerFrameVSStartRegister(), renderContext );
2539
2540 if( m_shadowBatches[0]->GetBatchCount() )
2541 {
2542 if( !renderContext.m_esm.IsDepthTestInverted() )
2543 {
2544 renderContext.m_esm.SetInvertedDepthTest( true );

Callers

nothing calls this directly

Calls 15

TriShadowFrustumClass · 0.85
TransposeFunction · 0.85
PushViewportMethod · 0.80
GetFrustumMethod · 0.80
getMethod · 0.80
GetInvLodFactorMethod · 0.80
FinalizeMethod · 0.80
GetBatchCountMethod · 0.80
IsDepthTestInvertedMethod · 0.80
SetInvertedDepthTestMethod · 0.80
ApplyStandardStatesMethod · 0.80

Tested by

no test coverage detected