gkjohnson / three-gpu-pathtracer

Path tracing renderer and utilities for three.js built on top of three-mesh-bvh.
https://gkjohnson.github.io/three-gpu-pathtracer/example/bundle/index.html
MIT License
1.33k stars 132 forks source link

Allow the pathtracer to filter certain objects before rendering the scene #204

Closed joewhatkins closed 2 years ago

joewhatkins commented 2 years ago

Different from #99, as I'd like to just exclude certain meshes from the rendering instead of certain areas.

We're working on a use case where users can switch between conventional rendering for editing a scene and the pathtracer for nice visualizations of the scene.

There are a ton of edit gizmos and widgets we want to include in the edit view but exclude from the pathtracing view.

The easiest way to implement this would probably be to pass a method to (PathTracingSceneGenerator|DynamicPathTracingSceneGenerator) that would filter each of the scene's meshes before building the BVH and generating the scene. This seems to work well implementing it locally.

This sound good? If so I can have a PR out pretty quickly.

gkjohnson commented 2 years ago

I'm thinking it might be simplest to just afford passing in an array of Object3Ds or a single Scene in order to support this use case. Then the end user can perform whatever filtering strategy they want and pass in the result. Then each object is included recursively in the processing. That would mean changing the APIs to the following:

const dynamicGenerator = new DynamicPathTracingSceneGenerator( Object3D | Array<Object3D> );
dynamicGenerator.generate();

const generator = new PathTracingSceneGenerator();
generator.generate( Object3D | Array<Object3D> );

How does that sound?

joewhatkins commented 2 years ago

SGTM - to be clear, we still want users to be able to pass in a scene after this change, right? Just also support single Objects and arrays?

joewhatkins commented 2 years ago

Fat fingered and accidentally closed this, reopening

gkjohnson commented 2 years ago

There would be no change for single objects. A Scene is just an instance of an Object3D which is what's currently supported by the generation functions.