Introduced into the vulkan SDK with version 1.2.162.0 So it's a lot easier to compile now Note: Ray tracing doesn't have to be the only process in play Could, for example, generate a shadow map using it, then apply it "normally" Main extensions: VK_KHR_acceleration_structure Provides acceleration structure building and management They're used for data mangement Both extensions below depend on it VK_KHR_ray_tracing_pipeline Provides ray tracing shader stages VK_KHR_ray_query Ray query operations for shader stages I don't think any cards support a subset of these three Could use only one of the last two Shaders can be written in GLSL or HLSL GLSL = GL Shader Language, what we've been using HLSL = High-Level Shader Language, what DirectX uses dxc is included in the SDK as a Linux binary It's also in the package manager This doesn't mean you can run the rest of a Windows program on Linux... We'll stick with GLSL, since it's the main shader language for Vulkan Acceleration Structures A data structure that represents where things are in the scene It's optimized for finding ray intersections Two-level heirarchy Grab picture online Bottom level: Geometry of the scene (vertex and index buffers) Can be triangles OR AABB's (Axis-Aligned Bounding Boxes) Remember, you don't want to buy transistors for spheres or whatever Can have multiple sets of geometry As in, multiple vertex and index buffers Top level: Refers to bottom-level structures Transformations (model matrix) are top-level These form an opaque data structure in GPU memory Bottom-level only used by reference from the top in the GPU Top level will have a descriptor binding (possible to use device address) Building one: Figure out how big it'll need to be (VkAccelerationStructureBuildGeometryInfoKHR) Described in VkAccelerationStructureBuildGeometryInfoKHR Also need scratch buffers for build and update Remember, the card/drivers will build something opaque here VkBuffer can hold the acceleration structure once built Have to use special functions to copy them around VkCopyAccelerationStructureKHR So if you want to move something around, you only need to change the top half Building of acceleration structures can require significant computation So there are both GPU AND CPU versions of many commands You can choose which resource you want to use There's a fancy VkDeferredOperationKHR system to multithread commands, etc Since the application will have a thread pool... We'll ignore this part! Compacting copy: Initial size is the worst-case size Maybe it can be represented smaller, but we didn't know ahead of time Compacting copy copies an idealized (smaller) version Maybe do this when copying from CPU to GPU memory? Ray Traversal: Is there an intersection between a ray and a geometric structure? Watertight in Vulkan (can't slip between triangles) Also won't hit one model twice Initial intersection is a candidate Might be culled later Closest hit is special Two ways to make this process happen: Ray Tracing Pipeline (whole thing is based on ray tracing) Ray Query (A shader stage can start the process) Question: Could ray marching be implemented in the fragment shader this way? I think you could ask for the closest hit with a ray query Shader execution and parallelism: ray generation any hit intersection closest hit miss For each ray, either the closest hit or miss shader will run Balance depends on the scene Ray carries a ray payload structure, for data flow Kind of like how the vertex shader delivers data to the fragment shader Compared to the way we've been doing things: Shaders don't have the same strict order Shaders from more than one object might be called at the same time The card must keep a shader binding table for dispatch Yes, this does require shaders to work more independently than rasterized graphics Alright, "how do we" section: How do we change the camera position? Answer: This happens in the ray generation shader. Compute the new ray origin and direction That's basically applying the view and projection matrix How do we apply a model transformation? (working answer) Update the top-level acceleration structure, rebuild the AS Could rebuild on CPU, but this sounds slow. Probably rebuild on GPU. Update TLAS vs. build new TLAS (is this even a choice?)