Merge branch 'CSM-new'

CSM-dev is clipmap shadow map and it works
This commit is contained in:
2025-10-23 00:35:44 +09:00
11 changed files with 128 additions and 163 deletions

View File

@@ -676,15 +676,17 @@ void RenderGraph::execute(VkCommandBuffer cmd)
if (rec && rec->imageView != VK_NULL_HANDLE)
{
depthInfo = vkinit::depth_attachment_info(rec->imageView, VK_IMAGE_LAYOUT_DEPTH_ATTACHMENT_OPTIMAL);
if (p.depthAttachment.clearOnLoad)
{
depthInfo.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
depthInfo.clearValue = p.depthAttachment.clear;
}
else
{
depthInfo.loadOp = VK_ATTACHMENT_LOAD_OP_LOAD;
}
if (p.depthAttachment.clearOnLoad)
{
depthInfo.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
depthInfo.clearValue = p.depthAttachment.clear;
}
else
{
depthInfo.loadOp = VK_ATTACHMENT_LOAD_OP_LOAD;
}
if (p.depthAttachment.clearOnLoad) depthInfo.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
else depthInfo.loadOp = VK_ATTACHMENT_LOAD_OP_LOAD;
if (!p.depthAttachment.store) depthInfo.storeOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
hasDepth = true;
if (rec->extent.width && rec->extent.height) chosenExtent = clamp_min(chosenExtent, rec->extent);

View File

@@ -19,8 +19,7 @@ public:
RGImageHandle drawHandle,
RGImageHandle gbufferPosition,
RGImageHandle gbufferNormal,
RGImageHandle gbufferAlbedo,
std::span<RGImageHandle> shadowCascades);
RGImageHandle gbufferAlbedo, std::span<RGImageHandle> shadowCascades);
private:
EngineContext *_context = nullptr;

View File

@@ -45,11 +45,11 @@ void ShadowPass::init(EngineContext *context)
b.set_cull_mode(VK_CULL_MODE_BACK_BIT, VK_FRONT_FACE_CLOCKWISE);
b.set_multisampling_none();
b.disable_blending();
// Forward-Z for shadow maps only (engine uses reversed-Z elsewhere)
// We clear depth to 1.0 and use LESS_OR_EQUAL so the nearest depth wins.
b.enable_depthtest(true, VK_COMPARE_OP_LESS_OR_EQUAL);
b.enable_depthtest(true, VK_COMPARE_OP_GREATER_OR_EQUAL);
b.set_depth_format(VK_FORMAT_D32_SFLOAT);
// Static depth bias to help with surface acne (tune later)
b._rasterizer.depthBiasEnable = VK_TRUE;
b._rasterizer.depthBiasConstantFactor = 2.0f;
b._rasterizer.depthBiasSlopeFactor = 2.0f;
@@ -85,8 +85,7 @@ void ShadowPass::register_graph(RenderGraph *graph, std::span<RGImageHandle> cas
RGPassType::Graphics,
[shadowDepth](RGPassBuilder &builder, EngineContext *ctx)
{
// Forward-Z in shadow pass: clear depth to 1.0 (far)
VkClearValue clear{}; clear.depthStencil = {1.f, 0};
VkClearValue clear{}; clear.depthStencil = {0.f, 0};
builder.write_depth(shadowDepth, true, clear);
// Ensure index/vertex buffers are tracked as reads (like Geometry)