Add depth bias config to shader
This commit is contained in:
@@ -58,6 +58,7 @@ namespace OpenVulkano::Scene
|
||||
billboardUniformBinding.stageFlags = ShaderProgramType::Type::VERTEX;
|
||||
shader.AddDescriptorSetLayoutBinding(billboardUniformBinding, 4);
|
||||
}
|
||||
shader.EnableDepthBias();
|
||||
return shader;
|
||||
}
|
||||
|
||||
|
||||
@@ -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())
|
||||
|
||||
@@ -84,6 +84,13 @@ namespace OpenVulkano::Vulkan
|
||||
vk::PipelineInputAssemblyStateCreateInfo inputAssembly = { {}, static_cast<vk::PrimitiveTopology>(shader->topology), 0 };
|
||||
vk::PipelineRasterizationStateCreateInfo rasterizer = {};
|
||||
rasterizer.cullMode = static_cast<vk::CullModeFlagBits>(shader->cullMode);
|
||||
if (shader->depthBias)
|
||||
{
|
||||
rasterizer.depthBiasEnable = VK_TRUE;
|
||||
rasterizer.depthBiasClamp = shader->depthBiasClamp;
|
||||
rasterizer.depthBiasConstantFactor = shader->depthBiasConstant;
|
||||
rasterizer.depthBiasSlopeFactor = shader->depthBiasSlope;
|
||||
}
|
||||
vk::PipelineMultisampleStateCreateInfo msaa = {};
|
||||
vk::PipelineDepthStencilStateCreateInfo depth = { {}, shader->depthTest, shader->depthWrite, static_cast<vk::CompareOp>(shader->depthCompareOp) };
|
||||
depth.maxDepthBounds = 1;
|
||||
|
||||
@@ -11,10 +11,8 @@
|
||||
#include <vulkan/vulkan.hpp>
|
||||
#include <vector>
|
||||
|
||||
namespace OpenVulkano
|
||||
namespace OpenVulkano::Vulkan
|
||||
{
|
||||
namespace Vulkan
|
||||
{
|
||||
class Context;
|
||||
class IShaderOwner;
|
||||
|
||||
@@ -45,5 +43,4 @@ namespace OpenVulkano
|
||||
|
||||
void CreatePipelineLayout();
|
||||
};
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user