Giter Site home page Giter Site logo

h34tn / introtodxr Goto Github PK

View Code? Open in Web Editor NEW

This project forked from acmarrs/introtodxr

0.0 0.0 0.0 39.93 MB

A barebones sample application to get you jump started with DirectX Raytracing (DXR)!

Home Page: http://www.visualextract.com/posts/introduction-to-dxr/

C++ 90.72% HLSL 9.19% Batchfile 0.09%

introtodxr's Introduction

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) or later
  • Windows 10 SDK v1809 (10.0.17763.0) or later. Download it here.
  • Visual Studio 2017, 2019, 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 creation and update, ray tracing pipeline state object (RTPSO) 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
  • -vsync [0|1] specifies whether vsync is enabled or disabled
  • -model [path] specifies the file path to a OBJ model

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:

  • 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:

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.