Hello, I’m currently researching and investigating how to do raytracing on the GPU or in shaders. The goal of this is to learn and create raytraced shadows in unity that are faster than unity’s current shadow mapping algorithm. (Little to ambitious there, but fast enough for realtime use) Inspired from UE4’s results -
After following a simple raytracing tutorial in unity, I managed to create some simple raytraced shadows on the CPU. (Very simple)
However, it uses Physics.Raycast and it requires mesh colliers or some kind of collision to detect the objects. Not good or feasible for real time use, but the result is right there!!!
So my next step is to start doing this on the GPU. Only 2 questions that are not really answered for me. is this.
- How to cast the ray
A. On the CPU, for each pixel, trace the incoming rays from the directional light. - How to tell if it intersected and object.
A. On the CPU, if the object has a collider and the ray hits it, return white. If it doesn’t return black.
So Im hitting quite a few walls for when Im doing this in the shader. One of the things I found out is to find out on the shader if a ray has intersected or hit and object. The object needs to have a defined Intersection function or distance function. Which is pretty easy to do for a simple scene, but if I wanted this dynamic then it would be very very very very time consuming to create an intersection or distance function for every single complex object in a scene like shown above. Now I could create a little program that creates and objects distance functions automatically and send them to the shader. Only problem is the shader cant really take that many distance functions (Im probably wrong) and I have no idea how to create this program as its beyond my current programming abilities.
EDIT - Currently looking at command buffers documentation.
So if any could provide me with some pointers, or perhaps some helpful code or suggestions. Id appreciate it.
