| 225 | } |
| 226 | |
| 227 | bool AsyncComputeSample::prepare(const vkb::ApplicationOptions &options) |
| 228 | { |
| 229 | // Set setup_queues() for details. |
| 230 | set_high_priority_graphics_queue_enable(true); |
| 231 | |
| 232 | if (!VulkanSample::prepare(options)) |
| 233 | { |
| 234 | return false; |
| 235 | } |
| 236 | |
| 237 | load_scene("scenes/bonza/Bonza.gltf"); |
| 238 | |
| 239 | auto &camera_node = vkb::add_free_camera(get_scene(), "main_camera", get_render_context().get_surface_extent()); |
| 240 | camera = &camera_node.get_component<vkb::sg::Camera>(); |
| 241 | |
| 242 | // Attach a shadow camera to the directional light. |
| 243 | auto lights = get_scene().get_components<vkb::sg::Light>(); |
| 244 | for (auto &light : lights) |
| 245 | { |
| 246 | if (light->get_light_type() == vkb::sg::LightType::Directional) |
| 247 | { |
| 248 | vkb::sg::LightProperties props{}; |
| 249 | props.color = glm::vec3(50.0f, 40.0f, 30.0f); |
| 250 | light->set_properties(props); |
| 251 | auto *node = light->get_node(); |
| 252 | |
| 253 | // Hardcoded to fit to the scene. |
| 254 | auto ortho_camera = std::make_unique<vkb::sg::OrthographicCamera>("shadow_camera", |
| 255 | -2000.0f, 3000.0f, |
| 256 | -2500.0f, 1500.0f, |
| 257 | -2000.0f, 2000.0f); |
| 258 | |
| 259 | ortho_camera->set_node(*node); |
| 260 | get_scene().add_component(std::move(ortho_camera), *node); |
| 261 | shadow_camera = &node->get_component<vkb::sg::Camera>(); |
| 262 | break; |
| 263 | } |
| 264 | } |
| 265 | |
| 266 | prepare_render_targets(); |
| 267 | |
| 268 | vkb::ShaderSource vert_shader("async_compute/forward.vert.spv"); |
| 269 | vkb::ShaderSource frag_shader("async_compute/forward.frag.spv"); |
| 270 | auto scene_subpass = |
| 271 | std::make_unique<ShadowMapForwardSubpass>(get_render_context(), std::move(vert_shader), std::move(frag_shader), get_scene(), *camera, *shadow_camera); |
| 272 | |
| 273 | vkb::ShaderSource shadow_vert_shader("async_compute/shadow.vert.spv"); |
| 274 | vkb::ShaderSource shadow_frag_shader("async_compute/shadow.frag.spv"); |
| 275 | auto shadow_scene_subpass = |
| 276 | std::make_unique<DepthMapSubpass>(get_render_context(), std::move(shadow_vert_shader), std::move(shadow_frag_shader), get_scene(), *shadow_camera); |
| 277 | shadow_render_pipeline.add_subpass(std::move(shadow_scene_subpass)); |
| 278 | shadow_render_pipeline.set_load_store({{VK_ATTACHMENT_LOAD_OP_CLEAR, VK_ATTACHMENT_STORE_OP_STORE}}); |
| 279 | |
| 280 | vkb::ShaderSource composite_vert_shader("async_compute/composite.vert.spv"); |
| 281 | vkb::ShaderSource composite_frag_shader("async_compute/composite.frag.spv"); |
| 282 | auto composite_scene_subpass = |
| 283 | std::make_unique<CompositeSubpass>(get_render_context(), std::move(composite_vert_shader), std::move(composite_frag_shader)); |
| 284 |
nothing calls this directly
no test coverage detected