MCPcopy Create free account
hub / github.com/FlaxEngine/FlaxEngine / Render

Method Render

Source/Engine/Renderer/GlobalSignDistanceFieldPass.cpp:709–1073  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

707}
708
709bool GlobalSignDistanceFieldPass::Render(RenderContext& renderContext, GPUContext* context, BindingData& result)
710{
711 // Skip if not supported
712 if (checkIfSkipPass())
713 return true;
714 if (renderContext.List->Scenes.Count() == 0)
715 return true;
716 auto& sdfData = *renderContext.Buffers->GetCustomBuffer<GlobalSignDistanceFieldCustomBuffer>(TEXT("GlobalSignDistanceField"));
717
718 // Skip if already done in the current frame
719 const auto currentFrame = Engine::FrameCount;
720 if (sdfData.LastFrameUsed == currentFrame)
721 {
722 result = sdfData.Result;
723 return false;
724 }
725 sdfData.LastFrameUsed = currentFrame;
726 PROFILE_GPU_CPU("Global SDF");
727
728 // Setup options
729 int32 resolution, cascadesCount, resolutionMip;
730 float distance;
731 sdfData.GetOptions(renderContext, resolution, cascadesCount, resolutionMip, distance);
732 const float distanceExtent = distance / sdfData.CascadesDistanceScales[cascadesCount - 1];
733
734 // Initialize buffers
735 bool reset = false;
736 if (sdfData.Cascades.Count() != cascadesCount || sdfData.Resolution != resolution)
737 {
738 sdfData.Cascades.Resize(cascadesCount);
739 sdfData.Resolution = resolution;
740 sdfData.FrameIndex = 0;
741 reset = true;
742 auto desc = GPUTextureDescription::New3D(resolution * cascadesCount, resolution, resolution, GLOBAL_SDF_FORMAT, GPUTextureFlags::ShaderResource | GPUTextureFlags::UnorderedAccess, 1);
743 {
744 GPUTexture*& texture = sdfData.Texture;
745 if (texture && texture->Width() != desc.Width)
746 {
747 RenderTargetPool::Release(texture);
748 sdfData.Texture = nullptr;
749 }
750 if (!texture)
751 {
752 texture = RenderTargetPool::Get(desc);
753 if (!texture)
754 return true;
755 RENDER_TARGET_POOL_SET_NAME(texture, "GlobalSDF.Cascade");
756 }
757 }
758 desc.Width = resolutionMip * cascadesCount;
759 desc.Height = desc.Depth = resolutionMip;
760 {
761 GPUTexture*& texture = sdfData.TextureMip;
762 if (texture && texture->Width() != desc.Width)
763 {
764 RenderTargetPool::Release(texture);
765 texture = nullptr;
766 }

Callers

nothing calls this directly

Calls 15

New3DFunction · 0.85
ReleaseFunction · 0.85
Float3Class · 0.85
DivideAndRoundUpFunction · 0.85
Vector4Class · 0.85
ListenSceneRenderingMethod · 0.80
NextLayerMethod · 0.80
GetFunction · 0.50
MaxFunction · 0.50
ToStringFunction · 0.50
CountMethod · 0.45
GetOptionsMethod · 0.45

Tested by

no test coverage detected