# Raytracing and transformation

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?

• 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 Feb 22, 2022 at 10:51
• 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.
– Wyck
Feb 22, 2022 at 14:50
• 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. Feb 23, 2022 at 7:36