diff --git a/Content/Shaders/GI/GlobalSurfaceAtlas.flax b/Content/Shaders/GI/GlobalSurfaceAtlas.flax index 113c96beb..5fb11c46a 100644 --- a/Content/Shaders/GI/GlobalSurfaceAtlas.flax +++ b/Content/Shaders/GI/GlobalSurfaceAtlas.flax @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:16457c650f2c3f2e04356e579423ccf8cba776555409af7cbaf8f4dec407c1db -size 12835 +oid sha256:b0acbc356eb19ea1cdcc131df43074578d3f5a2b2673d7ec52c3619e39ec080a +size 12945 diff --git a/Source/Engine/Renderer/GI/GlobalSurfaceAtlasPass.cpp b/Source/Engine/Renderer/GI/GlobalSurfaceAtlasPass.cpp index c56b1ec23..716e6e8ee 100644 --- a/Source/Engine/Renderer/GI/GlobalSurfaceAtlasPass.cpp +++ b/Source/Engine/Renderer/GI/GlobalSurfaceAtlasPass.cpp @@ -268,11 +268,15 @@ bool GlobalSurfaceAtlasPass::setupResources() // Create pipeline state GPUPipelineState::Description psDesc = GPUPipelineState::Description::DefaultFullscreenTriangle; - if (!_psDebug) + if (!_psDebug0) { - _psDebug = device->CreatePipelineState(); - psDesc.PS = shader->GetPS("PS_Debug"); - if (_psDebug->Init(psDesc)) + _psDebug0 = device->CreatePipelineState(); + _psDebug1 = device->CreatePipelineState(); + psDesc.PS = shader->GetPS("PS_Debug", 0); + if (_psDebug0->Init(psDesc)) + return true; + psDesc.PS = shader->GetPS("PS_Debug", 1); + if (_psDebug1->Init(psDesc)) return true; } if (!_psClear) @@ -327,7 +331,8 @@ void GlobalSurfaceAtlasPass::OnShaderReloading(Asset* obj) SAFE_DELETE_GPU_RESOURCE(_psDirectLighting0); SAFE_DELETE_GPU_RESOURCE(_psDirectLighting1); SAFE_DELETE_GPU_RESOURCE(_psIndirectLighting); - SAFE_DELETE_GPU_RESOURCE(_psDebug); + SAFE_DELETE_GPU_RESOURCE(_psDebug0); + SAFE_DELETE_GPU_RESOURCE(_psDebug1); invalidateResources(); } @@ -345,7 +350,8 @@ void GlobalSurfaceAtlasPass::Dispose() SAFE_DELETE_GPU_RESOURCE(_psDirectLighting0); SAFE_DELETE_GPU_RESOURCE(_psDirectLighting1); SAFE_DELETE_GPU_RESOURCE(_psIndirectLighting); - SAFE_DELETE_GPU_RESOURCE(_psDebug); + SAFE_DELETE_GPU_RESOURCE(_psDebug0); + SAFE_DELETE_GPU_RESOURCE(_psDebug1); _cb0 = nullptr; _shader = nullptr; } @@ -1091,7 +1097,7 @@ void GlobalSurfaceAtlasPass::RenderDebug(RenderContext& renderContext, GPUContex context->BindSR(4, bindingData.Objects ? bindingData.Objects->View() : nullptr); context->BindSR(6, bindingData.AtlasDepth->View()); context->BindSR(7, skybox); - context->SetState(_psDebug); + context->SetState(_psDebug0); { Float2 outputSizeThird = outputSize * 0.333f; Float2 outputSizeTwoThird = outputSize * 0.666f; @@ -1123,19 +1129,20 @@ void GlobalSurfaceAtlasPass::RenderDebug(RenderContext& renderContext, GPUContex context->BindSR(6, bindingData.AtlasDepth->View()); context->BindSR(7, skybox); context->BindCB(0, _cb0); - context->SetState(_psDebug); context->SetRenderTarget(output->View()); // Disable skybox data.SkyboxIntensity = 0.0f; context->UpdateCB(_cb0, &data); - // Bottom left - diffuse + // Bottom left - diffuse (with missing surface coverage debug) + context->SetState(_psDebug1); context->BindSR(5, bindingData.AtlasGBuffer0->View()); context->SetViewportAndScissors(Viewport(outputSizeTwoThird.X, 0, outputSizeThird.X, outputSizeThird.Y)); context->DrawFullscreenTriangle(); // Bottom middle - normals + context->SetState(_psDebug0); context->BindSR(5, bindingData.AtlasGBuffer1->View()); context->SetViewportAndScissors(Viewport(outputSizeTwoThird.X, outputSizeThird.Y, outputSizeThird.X, outputSizeThird.Y)); context->DrawFullscreenTriangle(); diff --git a/Source/Engine/Renderer/GI/GlobalSurfaceAtlasPass.h b/Source/Engine/Renderer/GI/GlobalSurfaceAtlasPass.h index 9e1a1feb1..87f7d84c1 100644 --- a/Source/Engine/Renderer/GI/GlobalSurfaceAtlasPass.h +++ b/Source/Engine/Renderer/GI/GlobalSurfaceAtlasPass.h @@ -50,7 +50,8 @@ private: GPUPipelineState* _psDirectLighting0 = nullptr; GPUPipelineState* _psDirectLighting1 = nullptr; GPUPipelineState* _psIndirectLighting = nullptr; - GPUPipelineState* _psDebug = nullptr; + GPUPipelineState* _psDebug0 = nullptr; + GPUPipelineState* _psDebug1 = nullptr; GPUConstantBuffer* _cb0 = nullptr; GPUShaderProgramCS* _csCullObjects; diff --git a/Source/Shaders/GI/GlobalSurfaceAtlas.hlsl b/Source/Shaders/GI/GlobalSurfaceAtlas.hlsl index 0fa43d451..deff969a3 100644 --- a/Source/Shaders/GI/GlobalSurfaceAtlas.hlsl +++ b/Source/Shaders/GI/GlobalSurfaceAtlas.hlsl @@ -11,6 +11,14 @@ #define GLOBAL_SURFACE_ATLAS_TILE_NORMAL_THRESHOLD_ENABLED 0 // Enables using tile normal threshold to prevent sampling pixels behind the view point (but might cause back artifacts) #define GLOBAL_SURFACE_ATLAS_TILE_NORMAL_THRESHOLD 0.05f // Cut-off value for tiles transitions blending during sampling #define GLOBAL_SURFACE_ATLAS_TILE_PROJ_PLANE_OFFSET 0.1f // Small offset to prevent clipping with the closest triangles (shifts near and far planes) +#ifndef GLOBAL_SURFACE_ATLAS_DEBUG_MODE +// 0 - disabled +// 1 - atlas coverage (pink for missing surface data) +#define GLOBAL_SURFACE_ATLAS_DEBUG_MODE 0 +#elif GLOBAL_SURFACE_ATLAS_DEBUG_MODE == 1 +#define GLOBAL_SURFACE_ATLAS_TILE_NORMAL_WEIGHT_ENABLED 0 +#define GLOBAL_SURFACE_ATLAS_TILE_NORMAL_THRESHOLD 0 +#endif struct GlobalSurfaceTile { @@ -268,6 +276,11 @@ float4 SampleGlobalSurfaceAtlas(const GlobalSurfaceAtlasData data, ByteAddressBu } #endif } + +#if GLOBAL_SURFACE_ATLAS_DEBUG_MODE + if (result.a < 0.05f) + result = float4(1, 0, 1, 1); +#endif // Normalize result result.rgb /= max(result.a, 0.0001f); diff --git a/Source/Shaders/GI/GlobalSurfaceAtlas.shader b/Source/Shaders/GI/GlobalSurfaceAtlas.shader index a9375e105..730ecc9ef 100644 --- a/Source/Shaders/GI/GlobalSurfaceAtlas.shader +++ b/Source/Shaders/GI/GlobalSurfaceAtlas.shader @@ -302,6 +302,8 @@ TextureCube Skybox : register(t7); // Pixel shader for Global Surface Atlas debug drawing META_PS(true, FEATURE_LEVEL_SM5) +META_PERMUTATION_1(GLOBAL_SURFACE_ATLAS_DEBUG_MODE=0) +META_PERMUTATION_1(GLOBAL_SURFACE_ATLAS_DEBUG_MODE=1) float4 PS_Debug(Quad_VS2PS input) : SV_Target { #if 0