A barebones sample application to get you jump started with DirectX Raytracing (DXR)!
Switch branches/tags
Nothing to show
Clone or download
Latest commit 8eaa711 Oct 25, 2018
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
bin Initial commit Oct 25, 2018
include Initial commit Oct 25, 2018
materials Initial commit Oct 25, 2018
models Initial commit Oct 25, 2018
shaders Initial commit Oct 25, 2018
src Initial commit Oct 25, 2018
textures Initial commit Oct 25, 2018
IntroToDXR-Debug.png Initial commit Oct 25, 2018
IntroToDXR.png Initial commit Oct 25, 2018
IntroToDXR.sln Initial commit Oct 25, 2018
IntroToDXR.vcxproj Initial commit Oct 25, 2018
IntroToDXR.vcxproj.filters Initial commit Oct 25, 2018
IntroToDXR.vcxproj.user Initial commit Oct 25, 2018
LICENSES.txt Initial commit Oct 25, 2018
README.md Update README.md Oct 25, 2018

README.md

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

  • Windows 10 v1809, "October 2018 Update" (RS5)
  • Windows 10 SDK v1809 (10.0.17763.0). Download it here.
  • Visual Studio 2017 or VS Code

Code Organization

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

  • Global
  • Standard D3D12
  • DXR

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 allocation and population, ray tracing pipeline state object creation, and ray tracing shader loading and compilation.

Command Line Arguments

  • -width [integer] specifies the width (in pixels) of the rendering window
  • -height [integer] specifies the height(in pixels of the rendering window
  • -model [path] specifies the file path to a OBJ model

Suggested Exercises

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:

  • Add antialiasing by casting multiple rays per pixel.
  • Add loading and rendering of models with multiple materials (only a single material is supported now)
  • Add realistic lighting and shading (lighting is currently baked!)
  • Add ray traced shadows. Extra credit: use Any Hit Shaders for shadow rendering
  • Add ray traced ambient occlusion.
  • Add ray traced reflections for mirror-like materials.
  • Add camera translation and rotation mapped to keyboard and mouse inputs.

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: