Help modularizing old shader explosion?

A minute ago (as the kids say) @yojimbo2000 made a cool shader that explodes a mesh into little shards.

I’m attaching the modification I’ve been working on, and if you run the project, you can see there are two spheres, and when you tap the screen, one of them shatters, and the other just vanishes.

I added the second sphere, and I’m trying to get it to also explode, but I must be doing it wrong, can anyone help?

so the second sphere isn’t disappearing but rather flying off screen, if you comment out line 77 you will see it is still there

so it’s not exploding, and we can see the thing that determines the explosion in the draw function is time but time is the same for both so why isn’t it working?

well if you look at the explosion code you will see there is a pseudo init call and there the trajectory buffer is only set for the first mesh m and in the explode vertex shader the pieces are calculated by time * trajectory.w

@skar thanks for helping!

So if I give the init function a parameter thisMesh, and replace all occurrences of m inside the init with thisMesh, I can pass in m from setup and it still works, so supposedly that function has been made modular,

But if I also pass in m2 to the init, its behavior doesn’t change; still only the first mesh explodes. What am I missing?

@UberGoober its working for me, set the grav of the other mesh to positive z and you’ll see the pieces fly up and down

you can’t use the translate call at 77 it completely displaces the shader code or interferes with the shader logic

@skar huh if I can’t use translate then how do I modularize this to be able to work on any icosphere? Is it just not possible with this code?

i think you would need to adjust the verts on the second mesh, it’s not something i’m really good at, the verts math always confuses me and i’m also not keen on using transform styling calls so it’s two area im weakest in

@skar me too!

@skar this is roughly working but I had to nix the gravity.

Gravity, apparently, is the part that got way out of whack after transform calls.

I might be totally wrong but AFAIK transforms are the only way to draw meshes in different places on screen, so if you’re trying to make something modular, then if it doesn’t play nice with transforms it’s got to go.

@skar over in this other thread I’ve figured out how to animate vertices on Craft models using custom Craft shaders.

That means that, in theory, I now know all I need to know to adapt this explosion for use by any Craft model that wants it, but in practice I have some math limitations and some coding limitations.

I think to make it work right I’d have to declare a lua array to hold the trajectories, and then access and manipulate it in the shader, and crossing over the two languages there (the shaders are written in C, right?) is a bit mystifying to me. Basically I wouldn’t know how to handle the arrays on the C side.