mmp / pbrt-v4

Source code to pbrt, the ray tracer described in the forthcoming 4th edition of the "Physically Based Rendering: From Theory to Implementation" book.
https://pbrt.org
Apache License 2.0
2.81k stars 433 forks source link

How do you generate a scene using C++ code? #320

Closed mmmovania closed 1 year ago

mmmovania commented 1 year ago

I was wondering how one would go about setting up pbrt v4 through code without using the scene file? I tried looking at the documentation and user guide and https://pbrt.org/fileformat-v4 but I only saw pbrt scene file examples. I did find out by peeking into the pbrt v4 code that we can use the BasicScene/BasicSceneBuilder class to help in setting up the code as shown here: https://github.com/mmmovania/PBRTv4_Tests/blob/main/SimpleScene/SimpleScene/AdvancedScene.cpp but shouldnt there be a better way? Asking as I could not find anything in the docs or on the internet.

pbrt4bounty commented 1 year ago

Yes.. this way seems not very optimized. I think a best approach are write any kinda of small 'API' interface to export some create scene functions. I can see that the 'api.cc' and 'api.h' files aren't update for this version. Maybe @mmp can add some comment or tip here about this.. :)

pbrt4bounty commented 1 year ago

Meanwhile you have a few options to optimize a bit your code:

void ParamsSetFloat(ParsedParameter& param, std::string name, Float value) {
    //-
    param.name = name;
    param.type = "float";
    param.AddFloat(value);
}
void ParamsSetInt(ParsedParameter& param, std::string name, int value) {
    //
    param.name = name;
    param.type = "integer";
    param.AddInt(value);
}

Then you can use some like this to set each param per-type

    ParsedParameterVector parsed; // reusable container after 'clear()'
    //Camera params
    std::unique_ptr< ParsedParameter> params(new ParsedParameter(loc)); // smart pointer to forget use 'delete'?
    ParamsSetFloat(*params, "fov", 39.60);
    parsed.push_back(params.get());
    builder.Camera("perspective", parsed, loc);
    parsed.clear();

I hope this help you a bit.. Cheers..

mmmovania commented 1 year ago

Thanks for your response @pbrt4bounty. Awaiting response from @mmp.

raymond-chetty commented 1 year ago

Sort of off topic, but possibly related... It might be worth linking to the user manual and scene description language definition in the README.md for this project.

Project: https://github.com/mmp/pbrt-v4

There is also the appendix

Also,

  1. I haven't thoroughly reviewed the book, but it might be worth translating the slide course material, projects etc. into pbrt and maybe add a translator for scene descriptions written in slide. If it hasn't been created already.

You might wish to just create a few polygon examples in the pbrt scenes page in order to provide some "training wheels" for new bees still getting started. Or suggest creating some as a prerequisite for your materials.

  1. I think there is a broken link in the Disney cloud rendering example. The data looks like it still exists through another route. Here is the link. https://disney-animation.s3.amazonaws.com/uploads/production/data_set_asset/1/asset/Cloud_Readme.pdf

This comment is not necessarily an endorsement of any person place or thing in particular :)

mmp commented 1 year ago

@raymond-chetty good suggestion about the README and thanks for the heads up about the Disney cloud link--done.

The scene description interfaces aren't really designed to be used directly so they're a little clunky. You can go ahead and make your own parameter vectors and SceneEntity objects, or you can also create the underlying objects directly (i.e., if you want a sphere, call new Sphere and pass the desired arguments to the constructor. That's used in some of the pbrt unit tests, for example.