Skip to content

Latest commit

 

History

History
37 lines (28 loc) · 2.63 KB

File metadata and controls

37 lines (28 loc) · 2.63 KB

D3D12 Raytracing Simple Lighting sample

D3D12 Raytracing Simple Lighting GUI

This sample demonstrates how to do ray generation for a dynamic perspective camera and calculate simple diffuse shading for a cube from a dynamic point light. The sample assumes familiarity with Dx12 programming and DirectX Raytracing concepts introduced in the D3D12 Raytracing Hello World sample.

Rendering

Each frame render happens in the sample's OnRender() call and includes executing DispatchRays() with a 2D grid dimensions matching that of backbuffer resolution and copying of the raytraced result to the backbuffer before finally presenting the it to the screen. The sample implements three shaders: ray generation, closest hit and miss shader:

  • The ray generation shader calculates a camera ray in world space for each dispatched ray corresponding to a pixel on the backbuffer. The world space ray is simply a ray's pixel screen position transformed by an inverse camera view projection matrix.
  • The closest hit shader from the cube's hit group calculates diffuse shading at the ray hit point. The shading is computed using a dot product between the ray hit to light position and a hit triangle normal, multiplied by light's and cube's color.
  • The miss shader simply stores a background color.
Shader accessed resources

The shaders access all the input data from constant buffers and buffer resources. There are two constant buffers:

  • CubeConstantBuffer contains cube's color - passed in via a shader record for the shader.
  • SceneConstantBuffer stores scene wide camera and light parameters - made available via a global root signature.

Triangle normals are accessed from index and vertex buffers that are explicitly passed in as buffer resources to the closest hit shader. First, three hit triangle's vertex indices are loaded from a 16bit index buffer. Then, the indices are used to index into the vertex buffer and load a triangle normal that is duplicatively stored for each triangle's vertex.

Usage

D3D12RaytracingSimpleLighting.exe

Additional arguments:

  • [-forceAdapter <ID>] - create a D3D12 device on an adapter <ID>. Defaults to adapter 0.

UI

The title bar of the sample provides runtime information:

  • Name of the sample
  • Frames per second
  • Million Primary Rays/s: a number of dispatched rays per second calculated based of FPS.
  • GPU[ID]: name

Controls

  • ALT+ENTER - toggles between windowed and fullscreen modes.

Requirements

  • Windows 10 with the October 2018 update or higher.
  • Consult the main D3D12 Raytracing readme for further requirements.