How does ray tracing works?

Started by
11 comments, last by phantomus 17 years, 11 months ago
Can someone explain me the idea behind ray tracing and why is it so slow? Thanks in advance.
It's all about the wheel.Never blindly trust technoligy.I love my internal organs.Real men don't shower.Quote:Original post by Toolmaker Quote:Original post by The C modest godHow is my improoved signature?It sucks, just like you.
Advertisement
Ever tried searching?

Anyway, raytracing basically casts rays through every pixel in the screen and follows its bounces on the objects of the scene.
If you want some implementation details, there is a good tutorial on devmaster.net
So you cast the rays from the camera onto the world bouncing on objects until it hits a light source?
Is there an opposite technique of casting rays from light source and seeing if it hits the camera?
Quote:Is there an opposite technique of casting rays from light source and seeing if it hits the camera?


sure but it's rarely used because you have to shoot billions of rays to get a properly lit scenes.

regards,
m4gnus
"There are 10 types of people in the world... those who understand binary and those who don't."
Quote:Original post by Anonymous Poster

Is there an opposite technique of casting rays from light source and seeing if it hits the camera?


The name 'raytracing' actually refers to what you just described. What we usually mean with 'raytracing' is 'backward raytracing'. The main difference between the two (rendering times aside) is that the raytracing can also reproduce effects like indirect illumination (see also global illumination) and caustics. These effects are most often achieved with GI algorithms like Radiosity (for indirect illumination) or photon tracing (for both).
Quote:

The name 'raytracing' actually refers to what you just described. What we usually mean with 'raytracing' is 'backward raytracing'. The main difference between the two (rendering times aside) is that the raytracing can also reproduce effects like indirect illumination (see also global illumination) and caustics. These effects are most often achieved with GI algorithms like Radiosity (for indirect illumination) or photon tracing (for both).



the one is forward raytracing and the other one is backward raytracing but some people keep arguing which is which...

regards,
m4gnus
Quote:Original post by The C modest god
Can someone explain me the idea behind ray tracing and why is it so slow?

Thanks in advance.


Its slow because for each pixel your firing a ray into a scene & you then have to keep track of that ray as it propogates around the scene. Typically a basic raytracer will do the following:

* Note - very abstract description!

1.Fire ray through pixel into the scene from the eye(x,y) position.

2.Test for intersection -> If it intersects with an object how should the ray behave? -> If object is reflective generate new ray (usually through recursion) and cast in the reflected direction from the point of the parent rays intersection. Now follow this ray and repeat 2 until recursive limit is reached. make note of each objects colour because this will be used to determine final colour of each pixel at the eye(x,y).

3. Calculate local illumination -> recursive ray tracing (backwards) can only model specular lighting therefore to "simulate" diffuse lighting you need to fake it through a local illumination model (e.g. Phong Lighting (not phong shading - thats different)).

4. Set eye(x,y) pixel colour to be the culmination of each ray spawned from the initial eye(x,y)

So for a scene resolution of 1024 x 768 @ 1 pixel per ray (more if you use supersampling) you'll be firing at least 786, 000 + rays and thats not including the rays spawned from parents where a reflective surface has been encountered.

You can speed it up using spatial subdivision techniques like octrees or process more than one ray at a time.

Regards,

Ste
It is also be possible to instead of tracing a ray for each pixel, instead trace a ray for a neighbour of pixels.

I've never tried this but it sounds like an obvious optimisation. :)
Quote:Original post by Anonymous Poster
So you cast the rays from the camera onto the world bouncing on objects until it hits a light source?
Is there an opposite technique of casting rays from light source and seeing if it hits the camera?


MaxPayne is working on something like this, I believe. Forward ray-tracing in order to generate the image itself.

Usually forward ray-tracing is used to preprocess an approximation to the physical light transport throughout the scene, and not actually to draw it per se. This is referred to as global illumination sometimes.

One starts by casting a few (thousand) rays from the light source(s). As each ray travels through the environment, its energy is absorbed by matter that it comes into contact with.

As the absorbed light energy increases throughout the scene, it becomes lit in essence.

The more rays / the longer the light transport simulation runs, the more accurate the final solution appears.

Then in a second pass, the light energy map is used as a colour texture during the traditional backward ray-tracing method.

I'm pretty sure that it was Half Life 2 that used this preprocessed light energy map method for its static lighting recently.

Even Quake used this method. :)

This topic is closed to new replies.

Advertisement