Fix custom GUI material writing depth when it's not needed

#3294
This commit is contained in:
Wojtek Figat
2025-03-18 10:57:12 +01:00
parent e25efa8c6f
commit 68967de1f5
4 changed files with 15 additions and 18 deletions

View File

@@ -173,8 +173,10 @@ public:
/// <summary>
/// Determines whether depth buffer is binded to the pipeline.
/// [Deprecated in v1.10]
/// </summary>
/// <returns><c>true</c> if depth buffer is binded; otherwise, <c>false</c>.</returns>
DEPRECATED("IsDepthBufferBinded has been deprecated and will be removed in ")
virtual bool IsDepthBufferBinded() = 0;
public:

View File

@@ -34,8 +34,8 @@ void GUIMaterialShader::Bind(BindParameters& params)
auto materialData = reinterpret_cast<GUIMaterialShaderData*>(cb.Get());
cb = Span<byte>(cb.Get() + sizeof(GUIMaterialShaderData), cb.Length() - sizeof(GUIMaterialShaderData));
int32 srv = 0;
const auto ps = context->IsDepthBufferBinded() ? _cache.Depth : _cache.NoDepth;
auto customData = (Render2D::CustomData*)params.CustomData;
const auto ps = customData->UseDepthBuffer ? _cache.Depth : _cache.NoDepth;
// Setup parameters
MaterialParameter::BindMeta bindMeta;
@@ -83,26 +83,21 @@ void GUIMaterialShader::Unload()
bool GUIMaterialShader::Load()
{
GPUPipelineState::Description psDesc0 = GPUPipelineState::Description::DefaultFullscreenTriangle;
psDesc0.Wireframe = EnumHasAnyFlags(_info.FeaturesFlags, MaterialFeaturesFlags::Wireframe);
psDesc0.VS = _shader->GetVS("VS_GUI");
psDesc0.PS = _shader->GetPS("PS_GUI");
psDesc0.BlendMode = BlendingMode::AlphaBlend;
psDesc0.DepthEnable = psDesc0.DepthWriteEnable = true;
auto desc = GPUPipelineState::Description::DefaultFullscreenTriangle;
desc.Wireframe = EnumHasAnyFlags(_info.FeaturesFlags, MaterialFeaturesFlags::Wireframe);
desc.VS = _shader->GetVS("VS_GUI");
desc.PS = _shader->GetPS("PS_GUI");
desc.BlendMode = BlendingMode::AlphaBlend;
desc.DepthEnable = true;
_cache.Depth = GPUDevice::Instance->CreatePipelineState();
_cache.NoDepth = GPUDevice::Instance->CreatePipelineState();
bool failed = _cache.Depth->Init(psDesc0);
psDesc0.DepthEnable = psDesc0.DepthWriteEnable = false;
failed |= _cache.NoDepth->Init(psDesc0);
bool failed = _cache.Depth->Init(desc);
desc.DepthEnable = false;
failed |= _cache.NoDepth->Init(desc);
if (failed)
{
LOG(Warning, "Failed to create GUI material pipeline state.");
return true;
}
return false;
}