From de0bf0d552358107a3879cc2b575e1dbccceb505 Mon Sep 17 00:00:00 2001 From: Wojtek Figat Date: Fri, 7 Aug 2026 06:16:30 +0200 Subject: [PATCH] Fix missing distortion rendering on Deformable materials #4045 --- .../Materials/DeformableMaterialShader.cpp | 16 +++++++++++++--- .../Materials/DeformableMaterialShader.h | 4 ++++ .../MaterialGenerator/MaterialGenerator.cpp | 4 +++- 3 files changed, 20 insertions(+), 4 deletions(-) diff --git a/Source/Engine/Graphics/Materials/DeformableMaterialShader.cpp b/Source/Engine/Graphics/Materials/DeformableMaterialShader.cpp index 6260163f4..6c7e5a20c 100644 --- a/Source/Engine/Graphics/Materials/DeformableMaterialShader.cpp +++ b/Source/Engine/Graphics/Materials/DeformableMaterialShader.cpp @@ -112,6 +112,7 @@ bool DeformableMaterialShader::Load() auto psDesc = GPUPipelineState::Description::Default; psDesc.DepthEnable = (_info.FeaturesFlags & MaterialFeaturesFlags::DisableDepthTest) == MaterialFeaturesFlags::None; psDesc.DepthWriteEnable = (_info.FeaturesFlags & MaterialFeaturesFlags::DisableDepthWrite) == MaterialFeaturesFlags::None; + psDesc.VS = _shader->GetVS("VS_SplineModel"); #if GPU_ALLOW_TESSELLATION_SHADERS // Check if use tessellation (both material and runtime supports it) @@ -127,7 +128,6 @@ bool DeformableMaterialShader::Load() if (_shader->HasShader("PS_QuadOverdraw")) { // Quad Overdraw - psDesc.VS = _shader->GetVS("VS_SplineModel"); psDesc.PS = _shader->GetPS("PS_QuadOverdraw"); _cache.QuadOverdraw.Init(psDesc); } @@ -142,7 +142,6 @@ bool DeformableMaterialShader::Load() psDesc.StencilPassOp = StencilOperation::Replace; // GBuffer Pass - psDesc.VS = _shader->GetVS("VS_SplineModel"); psDesc.PS = _shader->GetPS("PS_GBuffer"); _cache.Default.Init(psDesc); @@ -154,7 +153,6 @@ bool DeformableMaterialShader::Load() _drawModes |= DrawPass::Forward; // Forward Pass - psDesc.VS = _shader->GetVS("VS_SplineModel"); psDesc.PS = _shader->GetPS("PS_Forward"); psDesc.DepthWriteEnable = false; psDesc.BlendMode = BlendingMode::AlphaBlend; @@ -171,6 +169,18 @@ bool DeformableMaterialShader::Load() break; } _cache.Default.Init(psDesc); + + // Check if use transparent distortion pass + if (_shader->HasShader("PS_Distortion")) + { + _drawModes |= DrawPass::Distortion; + + // Accumulate Distortion Pass + psDesc.PS = _shader->GetPS("PS_Distortion"); + psDesc.BlendMode = BlendingMode::Add; + psDesc.DepthWriteEnable = false; + _cache.Distortion.Init(psDesc); + } } // Depth Pass diff --git a/Source/Engine/Graphics/Materials/DeformableMaterialShader.h b/Source/Engine/Graphics/Materials/DeformableMaterialShader.h index 45651c090..64c40c165 100644 --- a/Source/Engine/Graphics/Materials/DeformableMaterialShader.h +++ b/Source/Engine/Graphics/Materials/DeformableMaterialShader.h @@ -14,6 +14,7 @@ private: { PipelineStateCache Default; PipelineStateCache Depth; + PipelineStateCache Distortion; #if USE_EDITOR PipelineStateCache QuadOverdraw; #endif @@ -29,6 +30,8 @@ private: case DrawPass::GlobalSurfaceAtlas: case DrawPass::Forward: return &Default; + case DrawPass::Distortion: + return &Distortion; #if USE_EDITOR case DrawPass::QuadOverdraw: return &QuadOverdraw; @@ -42,6 +45,7 @@ private: { Default.Release(); Depth.Release(); + Distortion.Release(); #if USE_EDITOR QuadOverdraw.Release(); #endif diff --git a/Source/Engine/Tools/MaterialGenerator/MaterialGenerator.cpp b/Source/Engine/Tools/MaterialGenerator/MaterialGenerator.cpp index 685aa1040..dab832758 100644 --- a/Source/Engine/Tools/MaterialGenerator/MaterialGenerator.cpp +++ b/Source/Engine/Tools/MaterialGenerator/MaterialGenerator.cpp @@ -246,7 +246,9 @@ bool MaterialGenerator::Generate(WriteStream& source, MaterialInfo& materialInfo ADD_FEATURE(TessellationFeature); if (isOpaque) ADD_FEATURE(DeferredShadingFeature); - if (materialInfo.BlendMode != MaterialBlendMode::Opaque) + if (!isOpaque && (materialInfo.FeaturesFlags & MaterialFeaturesFlags::DisableDistortion) == MaterialFeaturesFlags::None) + ADD_FEATURE(DistortionFeature); + if (!isOpaque) ADD_FEATURE(ForwardShadingFeature); break; default: