
Accelerated “Ray Tracing in One Weekend” in CUDA - corysama
https://devblogs.nvidia.com/accelerated-ray-tracing-cuda/
======
corysama
"Ray Tracing in One Weekend" is the first in a very popular 3-part series of
short, introductory-level books on ray tracing.

"Ray Tracing in One Weekend/The Next Week/The Rest of Your Life" have recently
switched to DRM-free, "Pay What You Want" pricing
[http://in1weekend.blogspot.com/2016/01/ray-tracing-in-one-
we...](http://in1weekend.blogspot.com/2016/01/ray-tracing-in-one-weekend.html)

~~~
asafira
From the post: "Ray tracing was invented by Turner Whitted around 1980."

I believe that Turner probably did some great things, but somehow I don't
think I believe he invented ray tracing. Ray tracing has been around for so
long in physics...

~~~
twtw
Whitted published the first paper applying recursive ray tracing to the
problem of rendering an image. Quibbling over this is like saying no one
invented compute graphics because Renaissance artists knew how projection
worked.

~~~
asafira
I am sorry you feel that way =/; I understand it was a picky comment, but
quibbling over it is far from the gross overstatement you mentioned.

------
skinner_
I checked this out because I expected to learn about the brand new RT Core
accelerated ray tracing. Turns out this tutorial does not touch that topic.
It's awesome either way, but [https://devblogs.nvidia.com/nvidia-optix-ray-
tracing-powered...](https://devblogs.nvidia.com/nvidia-optix-ray-tracing-
powered-rtx/) might be more relevant for people like me.

------
fulafel
I'd also recommend this interesting blog series from Unity graphics engineer
arasp, covering many languages and platforms and incremental perf
improvements: [https://aras-p.info/blog/2018/03/28/Daily-Pathtracer-
Part-0-...](https://aras-p.info/blog/2018/03/28/Daily-Pathtracer-
Part-0-Intro/)

------
HHalvi
Can someone explain Ray Tracing to me like i'm five? Assume that this 5 year
old loves playing a lot of different varieties of games and would be glad if
his favorite developers end up making better experiences for him using ray
tracing.

~~~
zamadatix
Ray tracing is relatively easy to understand, it's not ray tracing that is
actually complicated. Ray tracing is simply sending out rays from the virtual
camera, seeing what they hit along the way, and calculating the lighting
effects of the materials and light sources when you hit those things. In the
end you've simulated a sample of light that hit the camera. Repeat a couple
million times and you've got an accurate picture of what the virtual scene
looks like.

"Normal" computer graphics is comprised of doing every dirty shortcut trick
you can imagine to avoid tracing hundreds of millions of rays per second while
still having some semblance of lighting effects in the virtual scene.

~~~
sdwisely
some good eli5s here, just adding for the grandparent post to remember that
light bounces so the calculations get rather iterative and expensive.

~~~
signa11
also, don't forget that the nature of material also influences how light
behaves e.g. scattering, reflection, refraction etc. etc. and depending on the
scene, computations can be quite expensive...

------
weebhard
What's wrong with the code? I have CUDA 10 installed and all Nvidia's shipped
samples work fine, while this doesn't. I'm new and totally lost, how can this
be debug?

[weeb@neet ~/repo/raytracinginoneweekendincuda (ch01_output_cuda)]

$ ./cudart

Rendering a 1200x600 image in 8x8 blocks. CUDA error = 48 at main.cu:48
'cudaGetLastError()'

~~~
Robadob
cuda error 48 is apparently "No Kernel Image available for execution on this
device"

Make sure that you're building for the appropriate device architecture.

[http://arnon.dk/matching-sm-architectures-arch-and-
gencode-f...](http://arnon.dk/matching-sm-architectures-arch-and-gencode-for-
various-nvidia-cards/)

~~~
weebhard
thanks! that did it, works now. Makefile had "sm_60" arch flag while my card
is sm_50.

~~~
twtw
"I'm new and totally lost"

Then I'll give you some unsolicited advice:

1\. Don't assume it's someone else's fault - "What's wrong with the code" is
the wrong first question.

2\. Read the original article, in its entirety. Fortunately people are still
nice enough to help you, but the combo of "how is this screwed up" and "I
didn't thoroughly read the article" is off-putting to people who would
otherwise love to assist you.

The relevant section:

> If you start with my Makefile, note that I build for a GTX 1070 card using
> specific -gencode flags for that card (-gencode arch=compute_60,code=sm_60).
> You will want to adjust the architecture and feature settings for the GPU or
> GPUs you will be running on.

------
IvanK_net
I made a similar thing a couple of years ago:
[http://powerstones.ivank.net/](http://powerstones.ivank.net/)

Instead of producing an image, it is an actual game :D And instead of running
just on nVidia, it runs everywhere (in a browser, even on phones etc).

------
amelius
Just a random thought: would it make sense for Rust to target GPUs?

~~~
jeffreyrogers
The programming model for GPUs is pretty different from CPUs. (Branching is
discouraged on GPUs, simpler hardware, highly parallel, etc.). I think the
right approach is to have separate languages for the two.

~~~
twtw
The original post is about how to make a C++ program run on a GPU via
relatively minor annotations.

~~~
jeffreyrogers
Yes, and the question was whether it makes sense for Rust to target the GPU,
not whether it's possible. I think most people would agree that in an ideal
world you would have a different programming language for the GPU than you
have for the CPU because the hardware is so different. CUDA uses C++ (and C
and Fortran) because there is already lots of code written in these languages
and it makes it easy to port code to run on the GPU.

------
lsb
In the newest Chrome I'm getting

    
    
        NET::ERR_CERT_SYMANTEC_LEGACY
        Subject: devblogs.nvidia.com
        Issuer: RapidSSL SHA256 CA

~~~
Goz3rr
It's their fault, but to temporarily override it so you can read the page
simply type "thisisunsafe" (without quotes) on the error page

~~~
parka
Whose fault? Chrome? I'm also facing the same problem. Same version of Chrome,
but on Windows, it loads properly, but not on Mac.

