How transformation works in Ray Tracing?

Started by
7 comments, last by cbenoi1 16 years, 5 months ago
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?
"A human being is a part of a whole, called by us,universe, a part limited in time and space. He experiences himself, his thoughts and feelings as something separated from the rest... a kind of optical delusion of his consciousness. This delusion is a kind of prison for us, restricting us to our personal desires and to affection for a few persons nearest to us. Our task must be to free ourselves from this prison by widening our circle of compassion to embrace all living creatures and the whole of nature in its beauty."A. Einstein
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 . . .
.
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.
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.
-----Quat
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 ?
"A human being is a part of a whole, called by us,universe, a part limited in time and space. He experiences himself, his thoughts and feelings as something separated from the rest... a kind of optical delusion of his consciousness. This delusion is a kind of prison for us, restricting us to our personal desires and to affection for a few persons nearest to us. Our task must be to free ourselves from this prison by widening our circle of compassion to embrace all living creatures and the whole of nature in its beauty."A. Einstein
That's correct.
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)...
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.
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

This topic is closed to new replies.

Advertisement