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

Method RenderShadows

trinity/Eve/EveSpaceScene.cpp:2611–2676  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2609}
2610
2611EveSpaceScene::ShadowResources EveSpaceScene::RenderShadows( const Tr2TextureAL& depthMap, const Tr2TextureAL& normalMap, Tr2GpuResourcePool& gpuResourcePool, Tr2RenderContext& renderContext )
2612{
2613 if( !m_display || !m_enableShadows )
2614 {
2615 return {};
2616 }
2617
2618 EveSpaceScene::ShadowResources result;
2619 if( m_cascadedShadowMap && ( m_shadowQuality == ShadowQuality::SHADOW_LOW || m_shadowQuality == ShadowQuality::SHADOW_HIGH ) )
2620 {
2621 result = SetupCascadedShadows( TR2RENDERREASON_NORMAL, *m_cascadedShadowMap, m_updateContext.GetFrustum(), depthMap, gpuResourcePool, renderContext );
2622 }
2623 else if( m_rtManager && m_shadowQuality == ShadowQuality::SHADOW_RAYTRACED && !m_objects.empty() )
2624 {
2625 constexpr size_t maxPlanets = 2;
2626 CcpMath::Sphere planets[maxPlanets];
2627 SetupPlanetsAsShadowCaster( planets, maxPlanets );
2628
2629 size_t volumetricCount = m_componentRegistry->ComponentCount<ITr2VolumetricRenderable>();
2630 size_t shadowCasterCount = m_componentRegistry->ComponentCount<IEveShadowCaster>();
2631 if( volumetricCount + shadowCasterCount != 0 )
2632 {
2633 renderContext.SetReadOnlyDepth( true );
2634 result = { m_rtManager->RenderShadows( depthMap, normalMap, m_sunData.DirWorld, planets, maxPlanets, m_upscalingAmount, gpuResourcePool, renderContext ) };
2635
2636 if( m_componentRegistry && m_volumetricsRenderer )
2637 {
2638 m_volumetricsRenderer->RenderShadows( *m_componentRegistry, result.shadowMap, renderContext );
2639
2640 RenderVolumetricShadowMap( renderContext );
2641
2642 PopulatePerFramePSData( m_perFramePS, renderContext );
2643 ApplyPerFrameData( renderContext );
2644 }
2645
2646 if( auto lightManager = Tr2LightManager::GetInstance() )
2647 {
2648 result.pointLightShadowMap = lightManager->RenderRaytracedShadows( &m_rtManager->GetGeometry(), depthMap, normalMap, planets, maxPlanets, gpuResourcePool, renderContext );
2649 }
2650
2651 renderContext.SetReadOnlyDepth( false );
2652 }
2653 }
2654
2655 if( auto lightManager = Tr2LightManager::GetInstance() )
2656 {
2657 if( lightManager->GetShadowCastingLights().size() > 0 && m_shadowQuality != ShadowQuality::SHADOW_DISABLED && m_shadowQuality != ShadowQuality::SHADOW_RAYTRACED )
2658 {
2659 GPU_REGION( renderContext, "PointLight/SpotLight Shadow Maps" );
2660 auto shadowMap = lightManager->GetShadowMapAtlas( gpuResourcePool );
2661 if( shadowMap.IsValid() ) // I HATE THIS. But it makes sense. The shadow map creation might fail, i.e. if we run out of memory.
2662 {
2663 PrepareShadowMapForLights( renderContext, shadowMap );
2664 std::vector<IEveShadowCaster*> shadowCasters = m_componentRegistry->GetComponents<IEveShadowCaster>();
2665 for( uint32_t lightIndex : lightManager->GetShadowCastingLights() )
2666 {
2667 const Tr2LightManager::PerLightData& lightData = lightManager->GetLightData( lightIndex );
2668 RenderShadowMapForLight( renderContext, shadowCasters, lightData, shadowMap );

Callers 2

ExecuteMethod · 0.45
SetupCascadedShadowsMethod · 0.45

Calls 8

PopulatePerFramePSDataFunction · 0.85
GetFrustumMethod · 0.80
emptyMethod · 0.80
sizeMethod · 0.80
GetShadowMapAtlasMethod · 0.80
SetReadOnlyDepthMethod · 0.45
IsValidMethod · 0.45

Tested by

no test coverage detected