Create shadow map sampler

This commit is contained in:
Camden Dixie O'Brien committed 2025-10-04 21:27:46 +01:00
1 parent 633a922e42
commit 3dc7c73296
2 files changed
+22 -3

No files matched your search

+21 -3
View File
@@ -828,8 +828,25 @@ void gpu_init(gpu_ctx_t *ctx, GLFWwindow *window, const char *name)
&ctx->model_pipeline);
assert(result == VK_SUCCESS);
// Create shadow sampler
const VkSamplerCreateInfo shadow_sampler_config = {
.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO,
.magFilter = VK_FILTER_LINEAR,
.minFilter = VK_FILTER_LINEAR,
.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE,
.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE,
.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE,
.compareEnable = VK_TRUE,
.compareOp = VK_COMPARE_OP_LESS_OR_EQUAL,
.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE,
.unnormalizedCoordinates = VK_FALSE,
};
result = vkCreateSampler(
ctx->dev, &shadow_sampler_config, nullptr, &ctx->shadow_sampler);
assert(result == VK_SUCCESS);
// Create framebuffers
const VkFramebufferCreateInfo shadow_framebuffer_config = {
const VkFramebufferCreateInfo shadow_framebuf_config = {
.sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO,
.renderPass = ctx->shadow_pass,
.attachmentCount = 1,
@@ -839,8 +856,7 @@ void gpu_init(gpu_ctx_t *ctx, GLFWwindow *window, const char *name)
.layers = 1,
};
result = vkCreateFramebuffer(
ctx->dev, &shadow_framebuffer_config, nullptr,
&ctx->shadow_framebuf);
ctx->dev, &shadow_framebuf_config, nullptr, &ctx->shadow_framebuf);
assert(result == VK_SUCCESS);
for (unsigned i = 0; i < ctx->swapchain_img_count; ++i) {
VkImageView attachments[] = {
@@ -960,6 +976,8 @@ void gpu_cleanup(const gpu_ctx_t *ctx)
vkDestroyImage(ctx->dev, ctx->depth_img, nullptr);
vkFreeMemory(ctx->dev, ctx->depth_mem, nullptr);
vkDestroySampler(ctx->dev, ctx->shadow_sampler, nullptr);
vkDestroyFramebuffer(ctx->dev, ctx->shadow_framebuf, nullptr);
for (unsigned i = 0; i < ctx->swapchain_img_count; ++i) {
vkDestroyFramebuffer(ctx->dev, ctx->framebuffers[i], nullptr);
+1
View File
@@ -25,6 +25,7 @@ typedef struct {
VkImage depth_img;
VkDeviceMemory depth_mem;
VkImageView depth_view;
VkSampler shadow_sampler;
VkFramebuffer shadow_framebuf;
VkFramebuffer framebuffers[MAX_FRAMES_IN_FLIGHT];
VkShaderModule floor_vert_shader;