Home

Awesome

Introduction To DirectX Raytracing

A barebones application to get you jump started with DirectX Raytracing (DXR)! Unlike other tutorials, this sample code does not create or use any abstractions on top of the DXR Host API, and focuses on highlighting exactly what is new and different with DXR using the raw API calls.

The code sample traces primary rays and includes a simple hit shader that samples a texture.

Release Mode

Requirements

Code Organization

Data is passed through the application using structs. These structs are defined in Structures.h and are organized into three categories:

Rendering code lives in Graphics.h/cpp and is broken into four namespaces to separate new DXR functionality from existing D3D12 functionality.

D3DResources

namespace D3DResources 
{
	void Create_Buffer(D3D12Global &d3d, D3D12BufferCreateInfo &info, ID3D12Resource** ppResource);
	void Create_Texture(D3D12Global &d3d, D3D12Resources &resources, Material &material);
	void Create_Vertex_Buffer(D3D12Global &d3d, D3D12Resources &resources, Model &model);
	void Create_Index_Buffer(D3D12Global &d3d, D3D12Resources &resources, Model &model);
	...
}

Contains common functions to create D3D12 resources like (vertex, index, constant) buffers, textures, samplers, and heaps.

D3DShaders

namespace D3DShaders 
{
	void Init_Shader_Compiler(D3D12ShaderCompilerInfo &shaderCompiler);
	void Compile_Shader(D3D12ShaderCompilerInfo &compilerInfo, RtProgram &program);
	...
}

Contains functions to initialize the DXCompiler as well as load and compile shaders (including - of course - the new DXR ray tracing shaders).

D3D12

namespace D3D12 
{	
	void Create_Device(D3D12Global &d3d);
	void Create_CommandList(D3D12Global &d3d);
	...
}

Contains functions for common D3D12 setup operations like Device, Command List, Command Queue, Command Allocator, Fence, Swap Chain, and Root Signature creation. Note that small differences exist in Device and Command List creation when using DXR.

DXR

namespace DXR
{
	void Create_Bottom_Level_AS(D3D12Global &d3d, DXRGlobal &dxr, D3D12Resources &resources, Model &model);
	void Create_Top_Level_AS(D3D12Global &d3d, DXRGlobal &dxr, D3D12Resources &resources);
	void Create_RayGen_Program(D3D12Global &d3d, DXRGlobal &dxr, D3D12ShaderCompilerInfo &shaderCompiler);
	void Create_Miss_Program(D3D12Global &d3d, DXRGlobal &dxr, D3D12ShaderCompilerInfo &shaderCompiler);
	void Create_Closest_Hit_Program(D3D12Global &d3d, DXRGlobal &dxr, D3D12ShaderCompilerInfo &shaderCompiler);
	void Create_Pipeline_State_Object(D3D12Global &d3d, DXRGlobal &dxr);
	void Create_Shader_Table(D3D12Global &d3d, DXRGlobal &dxr, D3D12Resources &resources);	
	...
}

Contains new functionality specific to DirectX Raytracing. This includes acceleration structure creation, shader table creation and update, ray tracing pipeline state object (RTPSO) creation, and ray tracing shader loading and compilation.

Command Line Arguments

Suggested Exercises

After building and running the code, first thing I recommend you do is load up the Nsight Graphics project file (IntroToDXR.nsight-gfxproj), and capture a frame of the application running. This will provide a clear view of exactly what is happening as the application is running. You can download Nsight Graphics here.

Once you have a good understanding of how the application works, I encourage you to dig deeper into DXR by removing limitations of the current code and adding new rendering features. I suggest:

If you've implemented the above features, you'll be just a few steps away from your very own DXR path tracer!

Licenses and Open Source Software

The code uses two dependencies:

The repository includes assets for use when testing the renderer: