mmp / pbrt-v3

Source code for pbrt, the renderer described in the third edition of "Physically Based Rendering: From Theory To Implementation", by Matt Pharr, Wenzel Jakob, and Greg Humphreys.
http://pbrt.org
BSD 2-Clause "Simplified" License
4.86k stars 1.18k forks source link

how to access animatedTransform for shape/primitive from integrator #240

Closed davidSedlacek closed 4 years ago

davidSedlacek commented 5 years ago

Thanks to the author for the great book and pbrt code :)

I am implementing own integrator and I would like to evaluate primitive (or shape) animation after an intersection. I am a little bit lost with it.

I do not see (and can't find it in any classes) where the animated transform is applied on primitive and how I can get it from the intersection.

I can get isect.shape->WorldToObject - but it is a transform in concrete time or I can get isect.primitive - but there is not a transform at all.

Would you recommend me to extend shape with AnimatedTransform or is there some way how to get to TransformedPrimitive from intersection info?

Thanks in advance for help david

mmp commented 5 years ago

There's no built-in way to do that, but it's doable with a little hacking. :-)

Shapes with animated transforms are stored in TransformedPrimitives. You could use a dynamic_cast on isect.primitive to get the TransformedPrimitive *, when there is one. Then if you make TransformedPrimitive::PrimitiveToWorld public (or otherwise accessible), you should be able to get at that information.

(A cleaner option might be to add a method to the Primitive interface that does what you want, make it a no-op for GeometricPrimitive, and then do what you want in the TransformedPrimitive implementation of it.)