Direct3D 12 Ray Tracing Samples
Introduction to D3D12 Ray Tracing
Explore the power of real-time ray tracing with Direct3D 12. These samples demonstrate how to leverage the latest graphics hardware and the D3D12 Raytracing API to achieve photorealistic rendering, advanced lighting effects, and more. Dive into the code to understand the fundamental concepts, from acceleration structures to shader stages, and unlock new possibilities for your graphics applications.
Ray tracing opens up a new paradigm for rendering, allowing for more accurate simulation of light transport. This section provides a curated collection of samples, each focusing on specific aspects of D3D12 ray tracing implementation.
Featured Samples
Basic Ray Generation
A foundational sample demonstrating the essential steps for setting up and executing a basic ray tracing pipeline. Covers ray generation, closest hit, and miss shaders.
View SampleAcceleration Structure Building
Learn how to efficiently build and update bottom-up and top-down acceleration structures (BVH) for ray intersection testing.
View SampleRay-AABB Intersection
A focused sample showcasing an optimized implementation of ray-axis-aligned bounding box (AABB) intersection tests, crucial for efficient ray traversal.
View SampleRay-Triangle Intersection
Explore the details of ray-triangle intersection algorithms, including Möller–Trumbore and barycentric coordinate methods, within the D3D12 RT framework.
View SampleRecursive Ray Tracing (Reflections)
Implement recursive ray tracing to achieve realistic reflections by bouncing rays off surfaces.
View SampleShadows with Ray Tracing
Demonstrates how to generate shadow rays to accurately compute shadows cast by lights.
View SampleGlobal Illumination Techniques
Implement advanced global illumination techniques like path tracing for more immersive and physically accurate lighting.
View SampleKey Concepts
Understanding the following concepts is crucial for working with D3D12 Ray Tracing:
- Ray Generation Shader: The entry point for ray tracing, responsible for generating primary rays.
- Intersection Shader: Custom shader for handling intersections with non-triangle primitives.
- Any Hit Shader: Executed for any potential intersection, useful for alpha-testing or early rejection.
- Closest Hit Shader: Executed when the closest intersection to the ray origin is found.
- Miss Shader: Executed when a ray does not intersect any geometry.
- Raytracing Pipeline State Object (RPSO): Manages the shaders and state for ray tracing operations.
- Acceleration Structures: Hierarchical data structures (like BVHs) used to accelerate ray intersection tests.
Getting Started
To run these samples, you will need:
- A DirectX 12 compatible GPU with Ray Tracing support.
- The latest Windows 10/11 SDK.
- A C++ development environment (e.g., Visual Studio).
Each sample typically includes a solution file (.sln) that can be opened in Visual Studio. Refer to the individual sample documentation for specific build and execution instructions.
struct RayPayload { float4 Color; };
[shader("raygeneration")]
void RayGen()
{
uint2 idx = DispatchRaysIndex().xy;
RayDesc ray;
ray.Origin = float3(0.0, 0.0, 0.0);
ray.Direction = float3(1.0, 0.0, 0.0); // Example direction
ray.TMin = 0.0;
ray.TMax = 1000.0;
RayPayload payload;
payload.Color = float4(0.0, 0.0, 0.0, 1.0);
TraceRay(TopLevelAS, 1, 0, ray, payload);
OutputImage[idx] = payload.Color;
}