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 133 forks source link

Instancing using InstancedBufferGeometry? #188

Open kefon opened 2 years ago

kefon commented 2 years ago

Hi there, first, thanks a lot for this amazing project, I'm playing with it these days and I'm really impressed by the features!

I'm trying to create a scene with multiple cubes using InstancedBufferGeometry, and passing the size, position, rotation of each cubes using InstancedBufferAttribute. Then the instances are transformed on GPU thanks to a custom vertex function overiding MeshStandardMaterial. But for now it looks like my instances are not rendered, I'm only having 1 cubes instead of all the instances. On a "classic" renderer it works perfectly and is very efficient.

1) Is that even possible to do that using three-gpu-pathtracer? (sorry for the noob question, I'm not sure to fully understand how that works)

2) Do you thing a more "classic" approach with InstancedMesh should work?

Thanks a lot for your answer!

gkjohnson commented 2 years ago

Hello! Instancing using InstancedMesh is not supported at the moment and would require some significant reworking to get functioning including packing multiple BVHs into a single BVH texture and adding support for scene representation and scene BVH. That may be something that happens in the long run, though. I don't anticipate InstancedBufferAttribute will ever be supported since it relies on custom shaders to function.

Currently the best fallback approach would be to "bake" all the instanced geometry into a single mesh so a full BVH can be generated. You can see that someone else implemented that here:

https://twitter.com/edankwan/status/1517164139440967680

kefon commented 2 years ago

Thanks a lot for the fast answer! Yes I was thinking about something like that, and before scratching my head too much I wanted to know if there was a way I couldn't think of. For now I will stick with the "bake into a single mesh" approach, which works pretty well depending on what you want to achieve. And looking forward for a future InstancedMesh support!

Thanks again for this awesome project and for your work!