Add depth bias config to shader

This commit is contained in:
Georg Hagen
2025-01-05 17:36:19 +01:00
parent 56cb508002
commit 4f1d730e30
4 changed files with 41 additions and 26 deletions

View File

@@ -81,7 +81,6 @@ namespace OpenVulkano::Scene
};
class Shader final : public RenderResourceHolder<Shader>, public ICloseable
{
public:
@@ -96,6 +95,8 @@ namespace OpenVulkano::Scene
bool depthTest = true;
bool depthWrite = true;
bool dynamicViewport = true; // If disabled the swapchains fullscreen viewport will always be used, regardless of framebuffer or viewport
bool depthBias = false;
float depthBiasClamp = 0.0f, depthBiasSlope = 0.0f, depthBiasConstant = 0.0f;
Shader() = default;
~Shader() override { Shader::Close(); }
@@ -128,6 +129,7 @@ namespace OpenVulkano::Scene
{
CheckShaderInitState();
if (bindingId < 0) bindingId = static_cast<int>(vertexInputDescriptions.size());
// ReSharper disable once CppDFALoopConditionNotUpdated
while (bindingId > static_cast<int>(vertexInputDescriptions.size()))
{
vertexInputDescriptions.emplace_back(0, 0);
@@ -149,6 +151,7 @@ namespace OpenVulkano::Scene
if (setId < 0) setId = static_cast<int>(descriptorSets.size() + 2);
if (setId < 2) throw std::runtime_error("Cant bind set id 0 or 1! They are used for node and camera!");
setId -= 2;
// ReSharper disable once CppDFALoopConditionNotUpdated
while (setId >= static_cast<int>(descriptorSets.size()))
{
descriptorSets.emplace_back();
@@ -163,6 +166,13 @@ namespace OpenVulkano::Scene
pushConstantRanges.push_back(pushConstantRange);
}
void EnableDepthBias(const float slope = -1.0, const float constant = 0.001f)
{
depthBias = true;
depthBiasSlope = slope;
depthBiasConstant = constant;
}
void Close() override
{
if (HasRenderResource())