Jump to content
  • Advertisement
Sign in to follow this  
Great_White

How transformation works in Ray Tracing?

This topic is 3997 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

Hi I'm a beginner in Ray Tracing. I'm wondering how transformations like rotations, scaling, translating works in ray tracing a scene. For example if I have a 4x4 transformation matrix of an object(i.e a sphere ) how can I position my objects with this transform in a ray traced scene?

Share this post


Link to post
Share on other sites
Advertisement
Just transform all the vertices of the object before rendering. You multiply the transformation matrix(a 4x4 mat) by the vertex position(a 4x1 mat) and get the transformed position. Then, its just render . . .

Share this post


Link to post
Share on other sites
If your scene consists entirely of triangle meshes it is best to generate one big mesh containing all transformed objects and then use an optimization data structure like an octree to trace this big mesh.

But supposing you have geometry that is not composed of triangles but simple objects likes planes, spheres, boxes etc. you would simply code the intersection routine for a generic case (e.g. sphere at (0,0,0) with radius 1) and then apply a transform to that sphere. In ray tracing you would then transform the ray by the inverse of the object transformation matrix and then do the intersection test instead of transforming the object itself. This is how I did it in my own raytracer which can be found on my homepage.

Share this post


Link to post
Share on other sites
Quote:

Hi
I'm a beginner in Ray Tracing. I'm wondering how transformations like rotations, scaling, translating works in ray tracing a scene. For example if I have a 4x4 transformation matrix of an object(i.e a sphere ) how can I position my objects with this transform in a ray traced scene?


Well, for a sphere you would just translate its center point. Mathematically, rotation of a sphere does not change anything; if you have textures, I guess you could consider rotating the texture coordinates.

Things get more complicated, what if you apply a nonuniform scaling? Then your sphere becomes an ellipsoid, and the ray/ellipsoid intersections are more complicated. Also, an ellipsoid can be rotated.

I think the most elegant solution in the long run, is to transform the ray into the local space of the object. Then you just have to worry about transforming rays, instead of transforming objects. Also, the ray/object intersection formulas are much nicer in local space.

Share this post


Link to post
Share on other sites
Quote:
Original post by Quat
Quote:

Hi
I'm a beginner in Ray Tracing. I'm wondering how transformations like rotations, scaling, translating works in ray tracing a scene. For example if I have a 4x4 transformation matrix of an object(i.e a sphere ) how can I position my objects with this transform in a ray traced scene?


Well, for a sphere you would just translate its center point. Mathematically, rotation of a sphere does not change anything; if you have textures, I guess you could consider rotating the texture coordinates.

Things get more complicated, what if you apply a nonuniform scaling? Then your sphere becomes an ellipsoid, and the ray/ellipsoid intersections are more complicated. Also, an ellipsoid can be rotated.

I think the most elegant solution in the long run, is to transform the ray into the local space of the object. Then you just have to worry about transforming rays, instead of transforming objects. Also, the ray/object intersection formulas are much nicer in local space.


So, I first need to transform ray's origin&direction with the inverse transform of the object into the object space, then I perform an intersection test and based on the results of this test, transform the intersected surface point back into the world space. Is this correct ?

Share this post


Link to post
Share on other sites
Quote:
Original post by Great_White
Quote:
Original post by Quat
Quote:

Hi
I'm a beginner in Ray Tracing. I'm wondering how transformations like rotations, scaling, translating works in ray tracing a scene. For example if I have a 4x4 transformation matrix of an object(i.e a sphere ) how can I position my objects with this transform in a ray traced scene?


Well, for a sphere you would just translate its center point. Mathematically, rotation of a sphere does not change anything; if you have textures, I guess you could consider rotating the texture coordinates.

Things get more complicated, what if you apply a nonuniform scaling? Then your sphere becomes an ellipsoid, and the ray/ellipsoid intersections are more complicated. Also, an ellipsoid can be rotated.

I think the most elegant solution in the long run, is to transform the ray into the local space of the object. Then you just have to worry about transforming rays, instead of transforming objects. Also, the ray/object intersection formulas are much nicer in local space.


So, I first need to transform ray's origin&direction with the inverse transform of the object into the object space, then I perform an intersection test and based on the results of this test, transform the intersected surface point back into the world space. Is this correct ?


Many people use the inverse to transform rays only for some kind of objects. For triangles, I usually see transformation of vertices to be used more.
This is how they do it in the pbrt system (the RT developed for the book Physically based rendering, from theory to implementation) and IIRC the same used by both blender and Yafray (don't quote me on that though)...

Share this post


Link to post
Share on other sites
Quote:
So, I first need to transform ray's origin&direction with the inverse transform of the object into the object space, then I perform an intersection test and based on the results of this test, transform the intersected surface point back into the world space. Is this correct ?


No, that would work but it would be a ton of wasted computations. In orderr to do efficient ray tracing you need to do binary space partitioning on the transformed positions, so what you need to do is transform all the vertices into world space, then build a BSP tree of some sort, then do ray testing. I suggest making your raytracer handle triangles meshes only but if you want you can also incorporate some mathematical shapes like "sphere" which do not use vertices.

Share this post


Link to post
Share on other sites
Check out:

http://www.amazon.com/Jim-Blinns-Corner/dp/1558603875/ref=pd_bxgy_b_text_b/103-5106136-1898259

and

http://www.amazon.com/Jim-Blinns-Corner/dp/1558603875/ref=pd_bxgy_b_text_b/103-5106136-1898259

Try to loan them from your faculty's library. The articles are pretty old, but there are very relevent for designing a ray-tracer, and there are tricks in there that are not found anywhere else.

-cb

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!