forked from KhronosGroup/Vulkan-Samples
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathray_queries.h
More file actions
99 lines (85 loc) · 2.93 KB
/
ray_queries.h
File metadata and controls
99 lines (85 loc) · 2.93 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
/* Copyright (c) 2021, Holochip Corporation
*
* SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0 the "License";
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/*
* Calculate shadows by extending a standard pipeline with ray queries
*/
#pragma once
#include "api_vulkan_sample.h"
#include <core/acceleration_structure.h>
namespace vkb
{
namespace sg
{
class Scene;
class Node;
class Mesh;
class SubMesh;
class Camera;
} // namespace sg
} // namespace vkb
class RayQueries : public ApiVulkanSample
{
public:
RayQueries();
~RayQueries() override;
void request_gpu_features(vkb::PhysicalDevice &gpu) override;
void render(float delta_time) override;
bool prepare(vkb::Platform &platform) override;
private:
struct GlobalUniform
{
glm::mat4x4 view;
glm::mat4x4 proj;
alignas(4) glm::vec3 camera_position;
alignas(4) glm::vec3 light_position;
} global_uniform;
struct Vertex
{
alignas(4) glm::vec3 position;
alignas(4) glm::vec3 normal;
};
struct Model
{
std::vector<Vertex> vertices;
std::vector<std::array<uint32_t, 3>> indices;
} model;
std::chrono::high_resolution_clock::time_point start_time{std::chrono::high_resolution_clock::now()};
// Buffers
std::unique_ptr<vkb::core::Buffer> vertex_buffer{nullptr};
std::unique_ptr<vkb::core::Buffer> index_buffer{nullptr};
std::unique_ptr<vkb::core::Buffer> uniform_buffer{nullptr};
// Ray tracing structures
VkPhysicalDeviceAccelerationStructureFeaturesKHR acceleration_structure_features{};
std::unique_ptr<vkb::core::AccelerationStructure> top_level_acceleration_structure = nullptr;
std::unique_ptr<vkb::core::AccelerationStructure> bottom_level_acceleration_structure = nullptr;
uint64_t get_buffer_device_address(VkBuffer buffer);
void create_top_level_acceleration_structure();
void create_bottom_level_acceleration_structure();
VkPipeline pipeline{VK_NULL_HANDLE};
VkPipelineLayout pipeline_layout{VK_NULL_HANDLE};
VkDescriptorSet descriptor_set{VK_NULL_HANDLE};
VkDescriptorSetLayout descriptor_set_layout{VK_NULL_HANDLE};
void build_command_buffers() override;
void create_uniforms();
void load_scene();
void create_descriptor_pool();
void create_descriptor_sets();
void prepare_pipelines();
void update_uniform_buffers();
void draw();
};
std::unique_ptr<vkb::VulkanSample> create_ray_queries();