Ray Tracing for fun and profit...
426
0
Advertisement
So, today I woke up and felt like doing something different, sure I could work on 4E6 stuff or even get my head into some Lua code for a Super Secret Project, however I didn't feel like either of these, instead I felt like doing something new to me and at the same time picking up and improving on some fundamental.
Yes, it was time, like all those in 3D graphics, to make a Ray Tracer... DUN DUN DUUUUUUUN!
I'll admit, I didn't work all this out from 'first principle'; ray tracing is a road well traveled and I was more intrested in bring myself up to speed and getting some output than I was working out the maths first hand; that said, despite having a guide to work from I have written all the code myself (well, aside from the maths library I used) and generally stampped my own feel upon things. Also, working from a guide does mean you've got reference images to work from so you know how things should look [wink]
I've got 4 programs built, each one adding to the last, so i've a record of how I did things and what has changed; evolutionary programming at it's best [grin]
So, first things first; basic ray tracing. In this instance it was just a matter of getting a coloured image into a file.

I was surprisingly happy when that worked; up until now 'ray tracing' had always been a Black Art to me simply because I'd never taken the time to look into it, based on that showing it was pretty easy.
Next up, some lights!

The lighting equations were pretty much second nature to me due to the work I'd done with OpenGL and GLSL before, pretty much a matter of plugging in the same equations and watching it go.
Time to improve things a bit;

Here I did get a bit of help, while knowing how to so reflections isn't a problem as such having a guide to get them in was very helpful. The specular stuff was easy however, again just like GLSL style lighting equations. When it came to the shadows, again having a guide was handy; I've done shadow mapping before of course so I know the idea behind it and how to get the hardware todo it, I'd just never consider it from this method before.
Finally, time to add some refraction;

Basic refraction was again a matter of plugging in some equations and reading about how to do it. This is also where errors start to appear in my implimentation (check the dots on the large sphere).
The addition of Beer's Law didn't make a difference there (although did change the overall feel of the image);

At the last, supersampling was added (16 samples per pixel), which improved the image quality a bit, however really highlighted the problem with the refraction code;

Which is the current state of the Ray Tracer; when I get up later today I might well try and figure out what is going wrong when refraction is added to the image, as those spots simply aren't right... [sad]
Still, it was a fun few hours working on that and it's nicely improved my knowledge base and generally patched some gaps in it.
Not that I'm going to end it there, for two reasons really;
1) Still more of the guide to read and things to impliment
2) I'd like it to get to the point where I can throw any scene at it, complete with textures etc and have it render it, correctly.
Right now however, I need some sleep...
Yes, it was time, like all those in 3D graphics, to make a Ray Tracer... DUN DUN DUUUUUUUN!
I'll admit, I didn't work all this out from 'first principle'; ray tracing is a road well traveled and I was more intrested in bring myself up to speed and getting some output than I was working out the maths first hand; that said, despite having a guide to work from I have written all the code myself (well, aside from the maths library I used) and generally stampped my own feel upon things. Also, working from a guide does mean you've got reference images to work from so you know how things should look [wink]
I've got 4 programs built, each one adding to the last, so i've a record of how I did things and what has changed; evolutionary programming at it's best [grin]
So, first things first; basic ray tracing. In this instance it was just a matter of getting a coloured image into a file.

I was surprisingly happy when that worked; up until now 'ray tracing' had always been a Black Art to me simply because I'd never taken the time to look into it, based on that showing it was pretty easy.
Next up, some lights!

The lighting equations were pretty much second nature to me due to the work I'd done with OpenGL and GLSL before, pretty much a matter of plugging in the same equations and watching it go.
Time to improve things a bit;

Here I did get a bit of help, while knowing how to so reflections isn't a problem as such having a guide to get them in was very helpful. The specular stuff was easy however, again just like GLSL style lighting equations. When it came to the shadows, again having a guide was handy; I've done shadow mapping before of course so I know the idea behind it and how to get the hardware todo it, I'd just never consider it from this method before.
Finally, time to add some refraction;

Basic refraction was again a matter of plugging in some equations and reading about how to do it. This is also where errors start to appear in my implimentation (check the dots on the large sphere).
The addition of Beer's Law didn't make a difference there (although did change the overall feel of the image);

At the last, supersampling was added (16 samples per pixel), which improved the image quality a bit, however really highlighted the problem with the refraction code;

Which is the current state of the Ray Tracer; when I get up later today I might well try and figure out what is going wrong when refraction is added to the image, as those spots simply aren't right... [sad]
Still, it was a fun few hours working on that and it's nicely improved my knowledge base and generally patched some gaps in it.
Not that I'm going to end it there, for two reasons really;
1) Still more of the guide to read and things to impliment
2) I'd like it to get to the point where I can throw any scene at it, complete with textures etc and have it render it, correctly.
Right now however, I need some sleep...
Advertisement
Advertisement
Advertisement
Discussion