<p>So I'm looking at incorporating instancing to my ray tracer. However what I would like some insight on is what to apply the transformation to?. Most suggest to apply the inverse transformation to the ray then proceed to check for detection. However this would require me to then transform the hit point and the direction of scattered ray back into world space. Whereas if I applied the transformation to the object space all is required is to apply the matrix transformation to a pair of pints in the form of a box primitive or just the centre of my sphere in the case of a sphere primitive. Could anyone tell me if I'm looking at this the wrong way?</p>

CC BY-SA 4.0
2022-02-22T10:51:01.463Z
By transforming the ray into object space the many ray-vs-triangle calculations that are going to follow are going to be cheaper, because you don't need to transform  potentially dozens triangles into world space
PaulHK
CC BY-SA 4.0
2022-02-22T14:50:04.407Z
Axis-aligned, origin-centered primitives are usually much simpler to perform ray intersection math on, hence the desire to transform the rays rather than the surface geometry.  The math for intersection of an arbitrary ray and a translated, rotated, non-uniformly scaled ellipsoid or conic is quite ugly, for example.  Even just an arbitrary 2D ellipse in this form is [ugly](https://math.stackexchange.com/a/434482/204468).
Wyck
CC BY-SA 4.0
2022-02-23T07:36:49.027Z
Totally depends on your setup. If your geometry consists of triangles and not simple primitives and you need to apply a transformation matrix to your geometry to bring them into world-space then as @PaulHK said, it's better to transform the ray to object space. Reason being you need to apply the matrix to all the triangles or some of them in a local area (if you are using data structures) vs to the ray once.  If it's only primitives, then it's better to apply that on the primitives.
gallickgunner
<raytracing><transformations>
Raytracing and transformation
Sina Dasht
# Raytracing and transformation

(Asked by: username_0 on 2022-02-20)

So I'm looking at incorporating instancing to my ray tracer. However what I would like some insight on is what to apply the transformation to?. Most suggest to apply the inverse transformation to the ray then proceed to check for detection. However this would require me to then transform the hit point and the direction of scattered ray back into world space. Whereas if I applied the transformation to the object space all is required is to apply the matrix transformation to a pair of pints in the form of a box primitive or just the centre of my sphere in the case of a sphere primitive. Could anyone tell me if I'm looking at this the wrong way?

**Tags:** raytracing, transformations

> **Comments:**
> **username_1**: By transforming the ray into object space the many ray-vs-triangle calculations that are going to follow are going to be cheaper, because you don't need to transform  potentially dozens triangles into world space  
> **username_2**: Axis-aligned, origin-centered primitives are usually much simpler to perform ray intersection math on, hence the desire to transform the rays rather than the surface geometry.  The math for intersection of an arbitrary ray and a translated, rotated, non-uniformly scaled ellipsoid or conic is quite ugly, for example.  Even just an arbitrary 2D ellipse in this form is [ugly](https://math.stackexchange.com/a/434482/204468).  
> **username_3**: Totally depends on your setup. If your geometry consists of triangles and not simple primitives and you need to apply a transformation matrix to your geometry to bring them into world-space then as @username_1 said, it's better to transform the ray to object space. Reason being you need to apply the matrix to all the triangles or some of them in a local area (if you are using data structures) vs to the ray once.  If it's only primitives, then it's better to apply that on the primitives.  

---

## 0 answers

