kenjinp / hello-worlds

Virtual javascript worlds at planetary scales for your threejs or react-three-fiber scene 👋🌐
https://worlds.kenny.wtf
137 stars 8 forks source link

Instanced-based Terrain Chunk implementation #23

Open kenjinp opened 2 years ago

kenjinp commented 2 years ago

Flatten CPU draw-calls of terrain chunks by implementing them as instance geometries. Then, pass the vertex buffer to a shader that uses per-instance uniforms so that each individual mesh can get it's own vertex displacement.

https://protectwise.github.io/troika/three-instanced-uniforms-mesh/

"You can set per-vertex attributes with the usual BufferAttribute and per-instance attributes with InstancedBufferAttribute, the latter using gl.vertexAttribDivisor."

CAVEAT: will only work with geometries with the same number of vertices all the way down. This probably won't work on the #11 RingWorld implementation, which allows for irregular subdivisions.

kenjinp commented 1 year ago

Apparently I forgot this, so here's a stack overflow that I found while trying to figure out ways to do this https://stackoverflow.com/questions/41880864/how-to-use-three-js-instancedbuffergeometry-instancedbufferattribute