top of page
Search

Week 7: Onto the GPU

  • Writer: Karinne Lorig
    Karinne Lorig
  • Jul 4, 2019
  • 2 min read

After the mid-term review last week, I'm starting off the second leg of the project by hopping straight into the GPU section of this project with DXR_RayTracing (Unfortunately for my earlier plans of using the Vulkan version of the API, Falcor supports both Vulkan and Nvidia's RayTracing API, but not the Vulkan version of said API). Last week, I spent what time didn't go towards preparing the summary of this project towards going through Falcor's sample code to build up some documentation about how both DXR_RayTracing and Falcor's implementation of it worked.


Ray tracing uses a different pipeline than normal, rasterized shaders do, in part because the result of a ray intersecting with a surface can easily be the creation of more rays for calculating shadows, reflections, or bounced light. Because these rays themselves then need to be traced, the ray tracing pipeline then loops back on itself, returning to an earlier stage. This recursion is a major contributing factor to why ray tracers can be so non-performant.

Nvidia's visualization of the rasterization pipeline versus the ray tracing one.

There are five major types of ray tracing shaders: Ray generation, any hit, intersection, closest hit, and miss. Of those five, you need at least a ray generation, closest/any hit, and miss shader in order to build a full ray tracer.


The ray tracer starts at the Ray generation shader; which runs once per pixel, generating and tracing as many rays as necessary, and is responsible for writing its output to a texture. After that, the ray is traced and the any hit shader is invoked against any thing that ray intersects. If it intersects nothing, then it invokes the miss shader instead; if it hits an intersection between two other pieces of geometry, it runs an intersection shader instead. Last of all, it runs the closest hit shader, which runs once on the nearest thing to its origin that the ray hit.


My starting foray into DXR_RayTracing has been to put together a Ray Tracer that does little more than check if the ray hit something or not. Although it's built in the same project as the previous ray tracer, I've yet to find a particularly elegant way to make both of them work in one project without changing the program significantly. This is largely due to this particular error message.

As it turns out, something about the way Falcor handles DXR_RayTracing plays very, very poorly with scenes that contain instanced models, which is what I had been using to build up the scenes for the CPU ray tracer. The only way I've found to get around this is to load in a .fscene file with the model load flag 'remove instancing', but that doesn't give me a great deal of control over the contents of the scene itself.


Despite that setback though, I was able to find some success with ray tracing itself after loading in the default scene that came with Falcor.

It also gets around 60fps, which is almost 20 times what the CPU renderer got with a sphere of similar size.

Comentarios


© 2018 by Karinne Lorig

bottom of page