Quake II RTX doxygen  1.0 dev
shadow_map.c
Go to the documentation of this file.
1 /*
2 Copyright (C) 2019, NVIDIA CORPORATION. All rights reserved.
3 
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
8 
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13 
14 You should have received a copy of the GNU General Public License along
15 with this program; if not, write to the Free Software Foundation, Inc.,
16 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
17 */
18 
19 #include "vkpt.h"
20 #include "shader/vertex_buffer.h"
21 
22 #include <float.h>
23 
24 VkPipelineLayout pipeline_layout_smap;
25 VkRenderPass render_pass_smap;
26 VkPipeline pipeline_smap;
27 static VkFramebuffer framebuffer_smap;
28 static VkFramebuffer framebuffer_smap2;
29 static VkImage img_smap;
30 static VkImageView imv_smap_depth;
31 static VkImageView imv_smap_depth2;
32 static VkImageView imv_smap_depth_array;
33 static VkDeviceMemory mem_smap;
34 
35 static void
37 {
38  LOG_FUNC();
39  VkAttachmentDescription depth_attachment = {
40  .format = VK_FORMAT_D32_SFLOAT,
41  .samples = VK_SAMPLE_COUNT_1_BIT,
42  .loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR,
43  .storeOp = VK_ATTACHMENT_STORE_OP_STORE,
44  .stencilLoadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE,
45  .stencilStoreOp = VK_ATTACHMENT_STORE_OP_DONT_CARE,
46  .initialLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL,
47  .finalLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL,
48  };
49 
50  VkAttachmentReference depth_attachment_ref = {
51  .attachment = 0, /* index in fragment shader */
52  .layout = VK_IMAGE_LAYOUT_DEPTH_ATTACHMENT_STENCIL_READ_ONLY_OPTIMAL_KHR,
53  };
54 
55  VkSubpassDescription subpass = {
56  .pipelineBindPoint = VK_PIPELINE_BIND_POINT_GRAPHICS,
57  .pDepthStencilAttachment = &depth_attachment_ref,
58  };
59 
60  VkSubpassDependency dependencies[] = {
61  {
62  .srcSubpass = VK_SUBPASS_EXTERNAL,
63  .dstSubpass = 0, /* index for own subpass */
64  .srcStageMask = VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
65  .srcAccessMask = 0, /* XXX verify */
66  .dstStageMask = VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
67  .dstAccessMask = VK_ACCESS_COLOR_ATTACHMENT_READ_BIT
68  | VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
69  },
70  };
71 
72  VkRenderPassCreateInfo render_pass_info = {
73  .sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO,
74  .attachmentCount = 1,
75  .pAttachments = &depth_attachment,
76  .subpassCount = 1,
77  .pSubpasses = &subpass,
78  .dependencyCount = LENGTH(dependencies),
79  .pDependencies = dependencies,
80  };
81 
82  _VK(vkCreateRenderPass(qvk.device, &render_pass_info, NULL, &render_pass_smap));
84 }
85 
86 VkResult
88 {
90 
91  VkPushConstantRange push_constant_range = {
92  .stageFlags = VK_SHADER_STAGE_VERTEX_BIT,
93  .offset = 0,
94  .size = sizeof(float) * 16,
95  };
96 
98  .pushConstantRangeCount = 1,
99  .pPushConstantRanges = &push_constant_range,
100  );
101 
102 
103  VkImageCreateInfo img_info = {
104  .sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO,
105  .extent = {
106  .width = SHADOWMAP_SIZE,
107  .height = SHADOWMAP_SIZE,
108  .depth = 1,
109  },
110  .imageType = VK_IMAGE_TYPE_2D,
111  .format = VK_FORMAT_D32_SFLOAT,
112  .mipLevels = 1,
113  .arrayLayers = 2,
114  .samples = VK_SAMPLE_COUNT_1_BIT,
115  .tiling = VK_IMAGE_TILING_OPTIMAL,
116  .usage = VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT
117  | VK_IMAGE_USAGE_SAMPLED_BIT,
118  .sharingMode = VK_SHARING_MODE_EXCLUSIVE,
119  .queueFamilyIndexCount = qvk.queue_idx_graphics,
120  .initialLayout = VK_IMAGE_LAYOUT_UNDEFINED,
121  };
122 
123  _VK(vkCreateImage(qvk.device, &img_info, NULL, &img_smap));
125 
126  VkMemoryRequirements mem_req;
127  vkGetImageMemoryRequirements(qvk.device, img_smap, &mem_req);
128 
129  _VK(allocate_gpu_memory(mem_req, &mem_smap));
130 
131  _VK(vkBindImageMemory(qvk.device, img_smap, mem_smap, 0));
132 
133  VkImageViewCreateInfo img_view_info = {
134  .sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
135  .viewType = VK_IMAGE_VIEW_TYPE_2D,
136  .format = VK_FORMAT_D32_SFLOAT,
137  .image = img_smap,
138  .subresourceRange = {
139  .aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT,
140  .baseMipLevel = 0,
141  .levelCount = 1,
142  .baseArrayLayer = 0,
143  .layerCount = 1,
144  },
145  .components = {
146  VK_COMPONENT_SWIZZLE_R,
147  VK_COMPONENT_SWIZZLE_G,
148  VK_COMPONENT_SWIZZLE_B,
149  VK_COMPONENT_SWIZZLE_A,
150  },
151  };
152  _VK(vkCreateImageView(qvk.device, &img_view_info, NULL, &imv_smap_depth));
154 
155  img_view_info.subresourceRange.baseArrayLayer = 1;
156  _VK(vkCreateImageView(qvk.device, &img_view_info, NULL, &imv_smap_depth2));
158 
159  img_view_info.viewType = VK_IMAGE_VIEW_TYPE_2D_ARRAY;
160  img_view_info.subresourceRange.baseArrayLayer = 0;
161  img_view_info.subresourceRange.layerCount = 2;
162  _VK(vkCreateImageView(qvk.device, &img_view_info, NULL, &imv_smap_depth_array));
164 
165  VkCommandBuffer cmd_buf = vkpt_begin_command_buffer(&qvk.cmd_buffers_graphics);
166 
167  IMAGE_BARRIER(cmd_buf,
168  .image = img_smap,
169  .subresourceRange = { .aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT,.levelCount = 1,.layerCount = 2 },
170  .srcAccessMask = VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_READ_BIT | VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT,
171  .dstAccessMask = VK_ACCESS_SHADER_READ_BIT,
172  .oldLayout = VK_IMAGE_LAYOUT_UNDEFINED,
173  .newLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL,
174  );
175 
177 
178  return VK_SUCCESS;
179 }
180 
181 VkResult
183 {
184  vkDestroyImageView(qvk.device, imv_smap_depth, NULL);
185  imv_smap_depth = VK_NULL_HANDLE;
186  vkDestroyImageView(qvk.device, imv_smap_depth2, NULL);
187  imv_smap_depth2 = VK_NULL_HANDLE;
188  vkDestroyImageView(qvk.device, imv_smap_depth_array, NULL);
189  imv_smap_depth_array = VK_NULL_HANDLE;
190  vkDestroyImage(qvk.device, img_smap, NULL);
191  img_smap = VK_NULL_HANDLE;
192  vkFreeMemory(qvk.device, mem_smap, NULL);
193  mem_smap = VK_NULL_HANDLE;
194 
195  vkDestroyRenderPass(qvk.device, render_pass_smap, NULL);
196  render_pass_smap = VK_NULL_HANDLE;
197  vkDestroyPipelineLayout(qvk.device, pipeline_layout_smap, NULL);
198  pipeline_layout_smap = VK_NULL_HANDLE;
199 
200  return VK_SUCCESS;
201 }
202 
204 {
205  return imv_smap_depth_array;
206 }
207 
208 VkResult
210 {
211  LOG_FUNC();
212 
213  VkPipelineShaderStageCreateInfo shader_info[] = {
214  SHADER_STAGE(QVK_MOD_SHADOW_MAP_VERT, VK_SHADER_STAGE_VERTEX_BIT)
215  };
216 
217  VkVertexInputBindingDescription vertex_binding_desc = {
218  .binding = 0,
219  .stride = sizeof(float) * 3,
220  .inputRate = VK_VERTEX_INPUT_RATE_VERTEX
221  };
222 
223  VkVertexInputAttributeDescription vertex_attribute_desc = {
224  .location = 0,
225  .binding = 0,
226  .format = VK_FORMAT_R32G32B32_SFLOAT,
227  .offset = 0
228  };
229 
230  VkPipelineVertexInputStateCreateInfo vertex_input_info = {
231  .sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO,
232  .vertexBindingDescriptionCount = 1,
233  .pVertexBindingDescriptions = &vertex_binding_desc,
234  .vertexAttributeDescriptionCount = 1,
235  .pVertexAttributeDescriptions = &vertex_attribute_desc,
236  };
237 
238  VkPipelineInputAssemblyStateCreateInfo input_assembly_info = {
239  .sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO,
240  .topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST,
241  };
242 
243  VkViewport viewport = {
244  .x = 0.0f,
245  .y = 0.0f,
246  .width = (float)SHADOWMAP_SIZE,
247  .height = (float)SHADOWMAP_SIZE,
248  .minDepth = 0.0f,
249  .maxDepth = 1.0f,
250  };
251 
252  VkRect2D scissor = {
253  .offset = { 0, 0 },
254  .extent = { SHADOWMAP_SIZE, SHADOWMAP_SIZE }
255  };
256 
257  VkPipelineViewportStateCreateInfo viewport_state = {
258  .sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO,
259  .viewportCount = 1,
260  .pViewports = &viewport,
261  .scissorCount = 1,
262  .pScissors = &scissor,
263  };
264 
265  VkPipelineRasterizationStateCreateInfo rasterizer_state = {
266  .sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO,
267  .polygonMode = VK_POLYGON_MODE_FILL,
268  .lineWidth = 1.0f,
269  .cullMode = VK_CULL_MODE_FRONT_BIT,
270  .frontFace = VK_FRONT_FACE_CLOCKWISE,
271  };
272 
273  VkPipelineMultisampleStateCreateInfo multisample_state = {
274  .sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO,
275  .sampleShadingEnable = VK_FALSE,
276  .rasterizationSamples = VK_SAMPLE_COUNT_1_BIT,
277  .minSampleShading = 1.0f,
278  .pSampleMask = NULL,
279  .alphaToCoverageEnable = VK_FALSE,
280  .alphaToOneEnable = VK_FALSE,
281  };
282 
283  VkPipelineDepthStencilStateCreateInfo depth_stencil_state = {
284  .sType = VK_STRUCTURE_TYPE_PIPELINE_DEPTH_STENCIL_STATE_CREATE_INFO,
285  .depthTestEnable = VK_TRUE,
286  .depthWriteEnable = VK_TRUE,
287  .depthCompareOp = VK_COMPARE_OP_LESS,
288  };
289 
290  VkDynamicState dynamic_states[] = {
291  VK_DYNAMIC_STATE_VIEWPORT,
292  VK_DYNAMIC_STATE_SCISSOR
293  };
294 
295  VkPipelineDynamicStateCreateInfo dynamic_state_info = {
296  .sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO,
297  .dynamicStateCount = LENGTH(dynamic_states),
298  .pDynamicStates = dynamic_states
299  };
300 
301  VkGraphicsPipelineCreateInfo pipeline_info = {
302  .sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO,
303  .stageCount = LENGTH(shader_info),
304  .pStages = shader_info,
305 
306  .pVertexInputState = &vertex_input_info,
307  .pInputAssemblyState = &input_assembly_info,
308  .pViewportState = &viewport_state,
309  .pRasterizationState = &rasterizer_state,
310  .pMultisampleState = &multisample_state,
311  .pDepthStencilState = &depth_stencil_state,
312  .pColorBlendState = NULL,
313  .pDynamicState = &dynamic_state_info,
314 
315  .layout = pipeline_layout_smap,
316  .renderPass = render_pass_smap,
317  .subpass = 0,
318 
319  .basePipelineHandle = VK_NULL_HANDLE,
320  .basePipelineIndex = -1,
321  };
322 
323  _VK(vkCreateGraphicsPipelines(qvk.device, VK_NULL_HANDLE, 1, &pipeline_info, NULL, &pipeline_smap));
325 
326  VkImageView attachments[] = {
328  };
329 
330  VkFramebufferCreateInfo fb_create_info = {
331  .sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO,
332  .renderPass = render_pass_smap,
333  .attachmentCount = 1,
334  .pAttachments = attachments,
335  .width = SHADOWMAP_SIZE,
336  .height = SHADOWMAP_SIZE,
337  .layers = 1,
338  };
339 
340  _VK(vkCreateFramebuffer(qvk.device, &fb_create_info, NULL, &framebuffer_smap));
342 
343  attachments[0] = imv_smap_depth2;
344  _VK(vkCreateFramebuffer(qvk.device, &fb_create_info, NULL, &framebuffer_smap2));
346 
347  return VK_SUCCESS;
348 }
349 
350 VkResult
352 {
353  LOG_FUNC();
354  vkDestroyFramebuffer(qvk.device, framebuffer_smap, NULL);
355  framebuffer_smap = VK_NULL_HANDLE;
356  vkDestroyFramebuffer(qvk.device, framebuffer_smap2, NULL);
357  framebuffer_smap2 = VK_NULL_HANDLE;
358  vkDestroyPipeline(qvk.device, pipeline_smap, NULL);
359  pipeline_smap = VK_NULL_HANDLE;
360  return VK_SUCCESS;
361 }
362 
363 VkResult
364 vkpt_shadow_map_render(VkCommandBuffer cmd_buf, float* view_projection_matrix, int num_static_verts, int num_dynamic_verts, int transparent_offset, int num_transparent_verts)
365 {
366  IMAGE_BARRIER(cmd_buf,
367  .image = img_smap,
368  .subresourceRange = { .aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT, .levelCount = 1, .layerCount = 2 },
369  .srcAccessMask = VK_ACCESS_SHADER_READ_BIT,
370  .dstAccessMask = VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_READ_BIT | VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT,
371  .oldLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL,
372  .newLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL,
373  );
374 
375  VkClearValue clear_depth = { .depthStencil = { .depth = 1.f } };
376 
377  VkRenderPassBeginInfo render_pass_info = {
378  .sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO,
379  .renderPass = render_pass_smap,
380  .framebuffer = framebuffer_smap,
381  .renderArea.offset = { 0, 0 },
382  .renderArea.extent = { SHADOWMAP_SIZE, SHADOWMAP_SIZE },
383  .clearValueCount = 1,
384  .pClearValues = &clear_depth
385  };
386 
387  vkCmdBeginRenderPass(cmd_buf, &render_pass_info, VK_SUBPASS_CONTENTS_INLINE);
388  vkCmdBindPipeline(cmd_buf, VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_smap);
389 
390  VkViewport viewport =
391  {
392  .width = (float)SHADOWMAP_SIZE,
393  .height = (float)SHADOWMAP_SIZE,
394  .minDepth = 0,
395  .maxDepth = 1.0f,
396  };
397 
398  vkCmdSetViewport(cmd_buf, 0, 1, &viewport);
399 
400  VkRect2D scissor =
401  {
402  .extent.width = SHADOWMAP_SIZE,
403  .extent.height = SHADOWMAP_SIZE,
404  .offset.x = 0,
405  .offset.y = 0,
406  };
407 
408  vkCmdSetScissor(cmd_buf, 0, 1, &scissor);
409 
410  vkCmdPushConstants(cmd_buf, pipeline_layout_smap, VK_SHADER_STAGE_VERTEX_BIT, 0, sizeof(float) * 16, view_projection_matrix);
411 
412  VkDeviceSize vertex_offset = offsetof(struct VertexBuffer, positions_bsp);
413  vkCmdBindVertexBuffers(cmd_buf, 0, 1, &qvk.buf_vertex.buffer, &vertex_offset);
414 
415  vkCmdDraw(cmd_buf, num_static_verts, 1, 0, 0);
416 
417  vertex_offset = offsetof(struct VertexBuffer, positions_instanced);
418  vkCmdBindVertexBuffers(cmd_buf, 0, 1, &qvk.buf_vertex.buffer, &vertex_offset);
419 
420  vkCmdDraw(cmd_buf, num_dynamic_verts, 1, 0, 0);
421 
422  vkCmdEndRenderPass(cmd_buf);
423 
424 
425  render_pass_info.framebuffer = framebuffer_smap2;
426  vkCmdBeginRenderPass(cmd_buf, &render_pass_info, VK_SUBPASS_CONTENTS_INLINE);
427 
428  vertex_offset = offsetof(struct VertexBuffer, positions_bsp);
429  vkCmdBindVertexBuffers(cmd_buf, 0, 1, &qvk.buf_vertex.buffer, &vertex_offset);
430 
431  vkCmdDraw(cmd_buf, num_transparent_verts, 1, transparent_offset, 0);
432 
433  vkCmdEndRenderPass(cmd_buf);
434 
435 
436  IMAGE_BARRIER(cmd_buf,
437  .image = img_smap,
438  .subresourceRange = { .aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT,.levelCount = 1,.layerCount = 2 },
439  .srcAccessMask = VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_READ_BIT | VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT,
440  .dstAccessMask = VK_ACCESS_SHADER_READ_BIT,
441  .oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL,
442  .newLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL,
443  );
444 
445  return VK_SUCCESS;
446 }
447 
448 static void sample_disk(float* u, float* v)
449 {
450  float a = frand();
451  float b = frand();
452 
453  float theta = 2.0 * M_PI * a;
454  float r = sqrt(b);
455 
456  *u = r * cos(theta);
457  *v = r * sin(theta);
458 }
459 
460 void vkpt_shadow_map_setup(const sun_light_t* light, const float* bbox_min, const float* bbox_max, float* VP, float* depth_scale, qboolean random_sampling)
461 {
462  vec3_t up_dir = { 0.0f, 0.0f, 1.0f };
463  if (light->direction[2] >= 0.99f)
464  VectorSet(up_dir, 1.f, 0.f, 0.f);
465 
466  vec3_t look_dir;
467  VectorScale(light->direction, -1.f, look_dir);
468  VectorNormalize(look_dir);
469  vec3_t left_dir;
470  CrossProduct(up_dir, look_dir, left_dir);
471  VectorNormalize(left_dir);
472  CrossProduct(look_dir, left_dir, up_dir);
473  VectorNormalize(up_dir);
474 
475  if (random_sampling)
476  {
477  float u, v;
478  sample_disk(&u, &v);
479 
480  VectorMA(look_dir, u * light->angular_size_rad * 0.5f, left_dir, look_dir);
481  VectorMA(look_dir, v * light->angular_size_rad * 0.5f, up_dir, look_dir);
482 
483  VectorNormalize(look_dir);
484 
485  CrossProduct(up_dir, look_dir, left_dir);
486  VectorNormalize(left_dir);
487  CrossProduct(look_dir, left_dir, up_dir);
488  VectorNormalize(up_dir);
489  }
490 
491  float view_matrix[16] = {
492  left_dir[0], up_dir[0], look_dir[0], 0.f,
493  left_dir[1], up_dir[1], look_dir[1], 0.f,
494  left_dir[2], up_dir[2], look_dir[2], 0.f,
495  0.f, 0.f, 0.f, 1.f
496  };
497 
498  vec3_t view_aabb_min = { FLT_MAX, FLT_MAX, FLT_MAX };
499  vec3_t view_aabb_max = { -FLT_MAX, -FLT_MAX, -FLT_MAX };
500 
501  for (int i = 0; i < 8; i++)
502  {
503  float corner[4];
504  corner[0] = (i & 1) ? bbox_max[0] : bbox_min[0];
505  corner[1] = (i & 2) ? bbox_max[1] : bbox_min[1];
506  corner[2] = (i & 4) ? bbox_max[2] : bbox_min[2];
507  corner[3] = 1.f;
508 
509  float view_corner[4];
510  mult_matrix_vector(view_corner, view_matrix, corner);
511 
512  view_aabb_min[0] = min(view_aabb_min[0], view_corner[0]);
513  view_aabb_min[1] = min(view_aabb_min[1], view_corner[1]);
514  view_aabb_min[2] = min(view_aabb_min[2], view_corner[2]);
515  view_aabb_max[0] = max(view_aabb_max[0], view_corner[0]);
516  view_aabb_max[1] = max(view_aabb_max[1], view_corner[1]);
517  view_aabb_max[2] = max(view_aabb_max[2], view_corner[2]);
518  }
519 
520  vec3_t diagonal;
521  VectorSubtract(view_aabb_max, view_aabb_min, diagonal);
522 
523  float maxXY = max(diagonal[0], diagonal[1]);
524  vec3_t diff;
525  diff[0] = (maxXY - diagonal[0]) * 0.5f;
526  diff[1] = (maxXY - diagonal[1]) * 0.5f;
527  diff[2] = 0.f;
528  VectorSubtract(view_aabb_min, diff, view_aabb_min);
529  VectorAdd(view_aabb_max, diff, view_aabb_max);
530 
531  float projection_matrix[16];
532  create_orthographic_matrix(projection_matrix, view_aabb_min[0], view_aabb_max[0], view_aabb_min[1], view_aabb_max[1], view_aabb_min[2], view_aabb_max[2]);
533  mult_matrix_matrix(VP, projection_matrix, view_matrix);
534 
535  *depth_scale = view_aabb_max[2] - view_aabb_min[2];
536 }
sun_light_s
Definition: vkpt.h:414
vkpt_shadow_map_setup
void vkpt_shadow_map_setup(const sun_light_t *light, const float *bbox_min, const float *bbox_max, float *VP, float *depth_scale, qboolean random_sampling)
Definition: shadow_map.c:460
CREATE_PIPELINE_LAYOUT
#define CREATE_PIPELINE_LAYOUT(dev, layout,...)
Definition: vk_util.h:82
LOG_FUNC
#define LOG_FUNC()
Definition: vkpt.h:54
height
static int height
Definition: physical_sky.c:39
allocate_gpu_memory
VkResult allocate_gpu_memory(VkMemoryRequirements mem_req, VkDeviceMemory *pMemory)
Definition: vk_util.c:402
vertex_buffer.h
QVK_s::device
VkDevice device
Definition: vkpt.h:172
vkpt_shadow_map_get_view
VkImageView vkpt_shadow_map_get_view()
Definition: shadow_map.c:203
QVK_s::buf_vertex
BufferResource_t buf_vertex
Definition: vkpt.h:243
vkpt.h
imv_smap_depth_array
static VkImageView imv_smap_depth_array
Definition: shadow_map.c:32
create_orthographic_matrix
void create_orthographic_matrix(float matrix[16], float xmin, float xmax, float ymin, float ymax, float znear, float zfar)
Definition: matrix.c:100
QVK_s::cmd_buffers_graphics
cmd_buf_group_t cmd_buffers_graphics
Definition: vkpt.h:193
vkpt_shadow_map_destroy_pipelines
VkResult vkpt_shadow_map_destroy_pipelines()
Definition: shadow_map.c:351
framebuffer_smap2
static VkFramebuffer framebuffer_smap2
Definition: shadow_map.c:28
framebuffer_smap
static VkFramebuffer framebuffer_smap
Definition: shadow_map.c:27
imv_smap_depth2
static VkImageView imv_smap_depth2
Definition: shadow_map.c:31
_VK
#define _VK(...)
Definition: vkpt.h:65
img_smap
static VkImage img_smap
Definition: shadow_map.c:29
QVK_s::queue_idx_graphics
int32_t queue_idx_graphics
Definition: vkpt.h:176
pipeline_layout_smap
VkPipelineLayout pipeline_layout_smap
Definition: shadow_map.c:24
BufferResource_s::buffer
VkBuffer buffer
Definition: vk_util.h:34
create_render_pass
static void create_render_pass()
Definition: shadow_map.c:36
mult_matrix_vector
void mult_matrix_vector(float *p, const float *a, const float *b)
Definition: matrix.c:295
vkpt_shadow_map_initialize
VkResult vkpt_shadow_map_initialize()
Definition: shadow_map.c:87
LENGTH
#define LENGTH(a)
Definition: tent.c:228
SHADOWMAP_SIZE
#define SHADOWMAP_SIZE
Definition: constants.h:24
sun_light_s::angular_size_rad
float angular_size_rad
Definition: vkpt.h:418
vkpt_shadow_map_render
VkResult vkpt_shadow_map_render(VkCommandBuffer cmd_buf, float *view_projection_matrix, int num_static_verts, int num_dynamic_verts, int transparent_offset, int num_transparent_verts)
Definition: shadow_map.c:364
sun_light_s::direction
vec3_t direction
Definition: vkpt.h:415
qvk
QVK_t qvk
Definition: main.c:377
vkpt_submit_command_buffer_simple
void vkpt_submit_command_buffer_simple(VkCommandBuffer cmd_buf, VkQueue queue, qboolean all_gpus)
Definition: main.c:3473
sample_disk
static void sample_disk(float *u, float *v)
Definition: shadow_map.c:448
SHADER_STAGE
#define SHADER_STAGE(_module, _stage)
Definition: vkpt.h:116
pipeline_smap
VkPipeline pipeline_smap
Definition: shadow_map.c:26
mult_matrix_matrix
void mult_matrix_matrix(float *p, const float *a, const float *b)
Definition: matrix.c:281
diff
static q_noinline int diff(uint32_t A_u32, uint32_t B_u32)
Definition: hq2x.c:55
VertexBuffer
Definition: vertex_buffer.h:96
IMAGE_BARRIER
#define IMAGE_BARRIER(cmd_buf,...)
Definition: vk_util.h:55
ATTACH_LABEL_VARIABLE
#define ATTACH_LABEL_VARIABLE(a, type)
Definition: vk_util.h:137
vkpt_begin_command_buffer
VkCommandBuffer vkpt_begin_command_buffer(cmd_buf_group_t *group)
Definition: main.c:3301
imv_smap_depth
static VkImageView imv_smap_depth
Definition: shadow_map.c:30
render_pass_smap
VkRenderPass render_pass_smap
Definition: shadow_map.c:25
vkpt_shadow_map_create_pipelines
VkResult vkpt_shadow_map_create_pipelines()
Definition: shadow_map.c:209
vkpt_shadow_map_destroy
VkResult vkpt_shadow_map_destroy()
Definition: shadow_map.c:182
mem_smap
static VkDeviceMemory mem_smap
Definition: shadow_map.c:33
VectorNormalize
vec_t VectorNormalize(vec3_t v)
Definition: shared.c:55
QVK_s::queue_graphics
VkQueue queue_graphics
Definition: vkpt.h:173