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

Method RenderBloom

trinity/PostProcess/Tr2PostProcessRenderer.cpp:957–1113  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

955
956
957Tr2GpuResourcePool::Texture Tr2PostProcessRenderer::RenderBloom( Tr2GpuResourcePool::Texture& dest, Tr2GpuResourcePool& gpuResourcePool, Tr2RenderContext& renderContext, Tr2PPBloomEffect* bloom, Tr2PPDynamicExposureEffect* dynamicExposure )
958{
959 GPU_REGION( renderContext, "Bloom" );
960 renderContext.m_esm.ApplyStandardStates( Tr2EffectStateManager::RM_FULLSCREEN );
961
962 bool hasDynamicExposure = dynamicExposure != nullptr;
963 bool exposureDependant = bloom->m_exposureDependency && hasDynamicExposure;
964
965 if( !m_useNewBloom )
966 {
967 m_bloomHighPassFilter->SetParameter( MEMOIZED_STRING( "LuminanceThreshold" ), std::max( 0.0f, bloom->m_luminanceThreshold ) );
968 m_bloomHighPassFilter->SetParameter( MEMOIZED_STRING( "LuminanceScale" ), bloom->m_luminanceScale );
969 m_bloomHighPassFilter->SetParameter( MEMOIZED_STRING( "ExposureDependency" ), exposureDependant ? 1.0f : 0.0f );
970 auto rt1 = gpuResourcePool.GetTempTexture( "Bloom", TextureSize2D( dest->GetDesc() ) * 0.5f, dest->GetFormat(), RENDER_TARGET );
971 TEMP_PARAM( m_bloomHighPassFilter, "BlitCurrent", dest );
972 TEMP_PARAM( m_bloomHighPassFilter, "Exposure", GetExposureBuffer( gpuResourcePool ) );
973 DrawInto( rt1, Tr2LoadAction::DONT_CARE, m_bloomHighPassFilter, renderContext );
974
975 return Blur( std::move( rt1 ), gpuResourcePool, renderContext, {} );
976 }
977
978 int depth = 0;
979 auto black = GetBlackTexture( gpuResourcePool );
980
981 float currentSize = 0.5f;
982 uint32_t minDim = std::min( dest->GetHeight(), dest->GetWidth() );
983
984 m_downSamplerLuminancePreserve->SetOption( MEMOIZED_STRING( "EXPOSURE_DEPENDANCE" ), hasDynamicExposure ? MEMOIZED_STRING( "EXPOSURE_DEPENDANCE_ON" ) : MEMOIZED_STRING( "EXPOSURE_DEPENDANCE_OFF" ) );
985 m_downSamplerLuminancePreserve->SetParameter( MEMOIZED_STRING( "LuminanceThreshold" ), bloom->m_luminanceThreshold );
986
987 std::array<Tr2GpuResourcePool::Texture, Bloom::MAX_BLOOM_STEPS> downsampleTexture;
988 std::array<Tr2GpuResourcePool::Texture, Bloom::MAX_BLOOM_STEPS> upsampleHorizontalTexture;
989 std::array<Tr2GpuResourcePool::Texture, Bloom::MAX_BLOOM_STEPS> upsampleTexture;
990
991 for( int i = 0; i < Bloom::MAX_BLOOM_STEPS; ++i )
992 {
993 if( (uint32_t)( (float)minDim * currentSize ) == 0 )
994 {
995 break;
996 }
997
998 auto size = TextureSize2D( dest->GetDesc() ) * currentSize;
999
1000 auto name = "Downsample_" + std::to_string( i );
1001 downsampleTexture[i] = gpuResourcePool.GetTempTexture( name.c_str(), size, dest->GetFormat(), RENDER_TARGET );
1002
1003 name = "Upsample_" + std::to_string( i );
1004 upsampleTexture[i] = gpuResourcePool.GetTempTexture( name.c_str(), size, dest->GetFormat(), RENDER_TARGET );
1005
1006 if( m_bloomDebugMode != BloomDebugMode::BLOOM_DEBUG_NONE )
1007 {
1008 name = "Upsample_Horizontal_" + std::to_string( i );
1009 upsampleHorizontalTexture[i] = gpuResourcePool.GetTempTexture( name.c_str(), size, dest->GetFormat(), RENDER_TARGET );
1010 }
1011
1012 currentSize *= 0.5f;
1013 ++depth;
1014 }

Callers

nothing calls this directly

Calls 13

TextureSize2DClass · 0.85
DrawIntoFunction · 0.85
to_stringFunction · 0.85
ApplyStandardStatesMethod · 0.80
GetTempTextureMethod · 0.80
SetOptionMethod · 0.80
FillAndSetConstantsFunction · 0.50
Vector3Class · 0.50
SetParameterMethod · 0.45
GetFormatMethod · 0.45
GetHeightMethod · 0.45

Tested by

no test coverage detected