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

Changing camera positions on the fly #277

Open farhanrw opened 4 years ago

farhanrw commented 4 years ago

Is it possible to somehow change the camera position somehow to render mutliple images without setting up the scene all over again? The way I am doing it right now is calling pbrt by changing the input file using a small script. But it creates a huge bottleneck for large scenes, since the entire file has to parsed and the scene has to be setup. Is there any way I could load a camera lookat file, or maybe write like a dozen lookat matrices and pbrt would generate that many images at one go?

mmp commented 4 years ago

There's no built-in functionality for that, but it should be straightforward to modify the system to add that capability. I think it should just work to, for example, update SamplerIntegrator::camera and then call SamplerIntegrator::Render() again. (I suppose you'd need to be careful to change the filename in the film as well so that it writes out to a different file.)

farhanrw commented 4 years ago

Thanks Matt for the reply. I am still not very sound in my PBRT knowledge. So a few questions. I spent a few hours seeing the way you mentioned. However, will just changing the SamplerIntegrator::camera suffice? I tried doing that, by creating a new PerspectiveCamera and using that from the render loop, but could not make it work. Do I need to start from somewhere else which will change the camera for the entire scene and reflect it all places?

mmp commented 4 years ago

I believe that changing the camera (and updating the film's output filename) would suffice, but haven't tried it myself. What do you mean "could not make it work"? What happened when you tried?

farhanrw commented 4 years ago

I tried to come out with a very ugly solution just to see if it worked, if yes, then would rewrite a few lines of code neatly. So specifically, what I mean by that is I created a new PerspectiveCamera with arbitrary parameters and tried to assign that to std::shared_ptr<const Camera> camera. I did it on the first line of render. I wanted to check if it would overpower of what the lookat matrix was in the scene description file since I am hard coding the new perspectivecamera parameters in the new object. But this fails due to a memory issue. Am I looking at the right place?

Also, I know that during the scene creation pbrt initializes the renderer, the camera etc using the functions MakeCamera() etc. I am just a little lost in deciding where I should be changing the camera from. Like for me, I would want to take the eye, at and direction values, call lookat and use that values for the camera. Could you give a little hints as to which are the places I should be looking or chaning?

Sorry for my naive questions, I am still pretty new to this.