Jump to content
  • Advertisement
Sign in to follow this  
The C modest god

How does ray tracing works?

This topic is 4450 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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.

Share this post


Link to post
Share on other sites
Guest 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?

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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).

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
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

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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. :)

Share this post


Link to post
Share on other sites
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. :)

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!