| 707 | } |
| 708 | |
| 709 | bool 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 | } |
nothing calls this directly
no test coverage detected