FluidRenderer, customParticles, how to add colors from VertexBuffer


I’m having problems with the new FluidRenderer and how to setup colors using custom particles. The particles are comming from an external 3d software, but I can easily shape the VertexBuffer I need.

I’m fetching the data to Babylon as an object that looks like this:

   pscale: number,
   ptCount: number,
   buffers: number[]

And the Vertex Buffer looks like this:

buffers = [
   pt0.pos.x, pt0.pos.y, pt0.pos.z, pt0.col.R, pt0.col.G, pt0.col.B,
   pt1.pos.x, pt1.pos.y, pt1.pos.z, pt1.col.R, pt1.col.G, pt1.col.B,
   ptn.pos.x, ptn.pos.y, ptn.pos.z, ptn.col.R, ptn.col.G, ptn.col.B,

So first, not all the particles are rendered. It looks like I reached some limit? Not sure what happened there… I can increase the number of particles to double what I have with data['ptCount'] * 2. Then the whole object is being rendered, but no colors.

And the second thing is, that the colors are all wrong. They all look very random, and green for some reason.

What am I doing wrong here…

The positions buffer should hold only positions, and you should pass a separate colors buffer.

You can do it like this:


Thank you!

So at first I was trying out using colors as a separate buffer, but it also got me weird errors. But now I know why. I was actually using RGB instead of RGBA.