A Pirate Playset Part1: Thin Instances

Hey All!

Super pumped to share the latest 2-part video series I’ve been working on. For anyone who doesn’t already know, I’m sorta obsessed with Pirates! This series takes me back to my childhood to explore the origin of the obsession through Babylon.js.

Part 1 is here and focuses on using Thin Instances and a shared Node Material to create a fun Lego stud ocean surface.

Hope you enjoy.

Starting Playground: Babylon.js Playground

Ending Playground: https://playground.babylonjs.com/#TWQZAU#1

Cardinal directions in the node material editor: Custom Nodes in the Node Material Editor: Part 2 - YouTube


I’m really excited to use this feature in my projects. Can the position/rotation be updated after they’re set, without the nme stuff? For example, can you make the studs move up and down by setting the y position each frame based on a timer variable and shifted by x and z position?

Adding @Evgeni_Popov for detailed clarity on that answer.

I could totally be wrong, but I think it’s theoretically possible, but probably not smart performance-wise.

I think what you’d have to do is manually update the array of positions/rotations for each instance, remove all of the instances and then recreate them each frame.

That’s a lot of tax on the CPU to recalculate and hand all of that off to the GPU each frame.

The whole point of Thin Instances is you can tell the GPU to render a single object a ton of times.

Again, I could totally be wrong about that so we’ll let @Evgeni_Popov guide us with a more official answer.

1 Like

@PirateJC is right, you should avoid modifying the thin instance matrix list too often as it will tax the CPU. Or try to update only a subset of the thin instances each frame.

You can indeed modify the thin instances position/rotation/scaling without a node material by simply calling mesh.thinInstanceSetMatrixAt(index, matrix, [refresh]) and overwrite the matrix of the “index-nth” thin instance. See Thin Instances | Babylon.js Documentation for more information.

1 Like

Ah so an SPS might be a better choice for my situation.

Basically only GPU updates on the thin instances via the NME would make sense.