Raycasting for additional VFX

Oh boy, I was supposed to write this in the spring..

So in early 2018 when I saw the Real-Time Raytraced Reflections demo by Unreal, I immediately wanted to finally implement raytracing against full meshes in some form or shape. This is something that a lot of graphics programmers obviously want to do at some point, even if only hastily and without much optimization.

But specifically I wanted to do it in a similar, scalable way as the Unreal team had done it. I wanted to validate that I understood how it's being done. Unless I've terribly mistaken at some point, in this style of raytracing the idea isn't to raytrace the whole scene, as that is still a too expensive process to do in full in real-time. Instead, you raytrace parts of the scene on top of the scene that is first rendered normally. For example, if you raytrace reflections only, then you can start your raytracing from the reflecting surfaces that you already have rendered. You can also use a significantly smaller resolution than what would be acceptable for the whole scene. You can even opt out from testing against certain geometry. You could only raytrace say, on every 2nd frame.

What you get in the end is improved visual fidelity for effects such as reflection, refraction, shadows, ambient occlusion and so on, without nearly as drastic a performance hit as you would have if you attempted to raytrace the whole scene.

As usual, I kind of ran out of steam before I could fully optimize the system, but here's what I ended up with:

I didn't really get proper assets or implement full raytracing. In the reflections, for example, shadows and light direction is not taken into account properly. But I am, either way, happy with the outcome; it doesn't look like much, but, it ran in realtime (even before I lowered the resolution of the shadow and reflection "map") and worked as expected. Both the shadows and the reflections as the cubes fall are raytraced. What was a little bit surprising to me was that the default hard shadows in Unity match the raytraced result not almost, but exactly when the viewport is close. That's pretty neat.

Anyway - to me this showed that partial raytracing in a scene in realtime is certainly possible even without the dedicated hardware (the above video was taken with GTX 1060. Raytracing is 100% GPU-side). By now the RTX line of cards by Nvidia has come out and those feature a dedicated chip for raytracing. I think it's fair to say that raytracing is finally a plausible possibility in high-fidelity realtime gaming.

Code for the Unity project is here: https://gitlab.com/tzaeru/Enviromental-Raytracing-Experiments Be warned though, it's some pretty crappy and unfinished code with bits and pieces of copy pasta here and there for a good measure.

Jalmari Ikävalko

Read more posts by this author.