top of page
Search

Week 3: Building the ray tracer on the CPU

  • Writer: Karinne Lorig
    Karinne Lorig
  • Jun 7, 2019
  • 1 min read

My task for this week was to build up from the existing raster shader to a CPU-based ray tracing shader.


The first step to completing this was to find a way to send the color data from the CPU to the GPU so I could access it from the shader. Sending all that data over turned out to be non-trivial, however; as a bit of research revealed that constant buffers, which I had been using to transfer data for the raster shader, had a size limit well below the amount of space (64KB) I’d need to transfer all the color data. With that route blocked, I looked into alternatives. After some research I eventually found Typed Buffers, which lacked a size limit.


After that, I built the shader, ran it and got this:

the error turned out to be a misspelled variable name.

The color came across properly, so the shader was able to access the typed buffer successfully.

After that, I started to build out the ray tracer itself.


In its current form, it only accepts one object and returns one color on a hit and another on a miss. For every pixel, it sends out a single ray and then checks for collisions with the model in question. The challenge here turned out to be finding the correct angles at which to emit all the rays in order to give a good-looking result (though I’m now curious about the possibility of plugging different equations into this to give interesting distortion effects, for now, I’m using a fairly standard one). After implementing a ray-to-sphere collision detector, I got the result below:


 
 
 

Коментарі


© 2018 by Karinne Lorig

bottom of page