Create shadow map sampler
This commit is contained in:
1 parent
633a922e42
commit
3dc7c73296
2 files changed
+22
-3
No files matched your search
@@ -828,8 +828,25 @@ void gpu_init(gpu_ctx_t *ctx, GLFWwindow *window, const char *name)
|
|||||||
&ctx->model_pipeline);
|
&ctx->model_pipeline);
|
||||||
assert(result == VK_SUCCESS);
|
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
|
// Create framebuffers
|
||||||
const VkFramebufferCreateInfo shadow_framebuffer_config = {
|
const VkFramebufferCreateInfo shadow_framebuf_config = {
|
||||||
.sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO,
|
.sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO,
|
||||||
.renderPass = ctx->shadow_pass,
|
.renderPass = ctx->shadow_pass,
|
||||||
.attachmentCount = 1,
|
.attachmentCount = 1,
|
||||||
@@ -839,8 +856,7 @@ void gpu_init(gpu_ctx_t *ctx, GLFWwindow *window, const char *name)
|
|||||||
.layers = 1,
|
.layers = 1,
|
||||||
};
|
};
|
||||||
result = vkCreateFramebuffer(
|
result = vkCreateFramebuffer(
|
||||||
ctx->dev, &shadow_framebuffer_config, nullptr,
|
ctx->dev, &shadow_framebuf_config, nullptr, &ctx->shadow_framebuf);
|
||||||
&ctx->shadow_framebuf);
|
|
||||||
assert(result == VK_SUCCESS);
|
assert(result == VK_SUCCESS);
|
||||||
for (unsigned i = 0; i < ctx->swapchain_img_count; ++i) {
|
for (unsigned i = 0; i < ctx->swapchain_img_count; ++i) {
|
||||||
VkImageView attachments[] = {
|
VkImageView attachments[] = {
|
||||||
@@ -960,6 +976,8 @@ void gpu_cleanup(const gpu_ctx_t *ctx)
|
|||||||
vkDestroyImage(ctx->dev, ctx->depth_img, nullptr);
|
vkDestroyImage(ctx->dev, ctx->depth_img, nullptr);
|
||||||
vkFreeMemory(ctx->dev, ctx->depth_mem, nullptr);
|
vkFreeMemory(ctx->dev, ctx->depth_mem, nullptr);
|
||||||
|
|
||||||
|
vkDestroySampler(ctx->dev, ctx->shadow_sampler, nullptr);
|
||||||
|
|
||||||
vkDestroyFramebuffer(ctx->dev, ctx->shadow_framebuf, nullptr);
|
vkDestroyFramebuffer(ctx->dev, ctx->shadow_framebuf, nullptr);
|
||||||
for (unsigned i = 0; i < ctx->swapchain_img_count; ++i) {
|
for (unsigned i = 0; i < ctx->swapchain_img_count; ++i) {
|
||||||
vkDestroyFramebuffer(ctx->dev, ctx->framebuffers[i], nullptr);
|
vkDestroyFramebuffer(ctx->dev, ctx->framebuffers[i], nullptr);
|
||||||
|
|||||||
@@ -25,6 +25,7 @@ typedef struct {
|
|||||||
VkImage depth_img;
|
VkImage depth_img;
|
||||||
VkDeviceMemory depth_mem;
|
VkDeviceMemory depth_mem;
|
||||||
VkImageView depth_view;
|
VkImageView depth_view;
|
||||||
|
VkSampler shadow_sampler;
|
||||||
VkFramebuffer shadow_framebuf;
|
VkFramebuffer shadow_framebuf;
|
||||||
VkFramebuffer framebuffers[MAX_FRAMES_IN_FLIGHT];
|
VkFramebuffer framebuffers[MAX_FRAMES_IN_FLIGHT];
|
||||||
VkShaderModule floor_vert_shader;
|
VkShaderModule floor_vert_shader;
|
||||||
|
|||||||
Reference in new issue
Block a user