How to set color/material per vertex in the "Write into a VertexBuffer in a compute shader" example?

Hi guys,

Im following the example patch “Write into a VertexBuffer in a compute shader” is there a way to assign a different color/material to each vertex?

thanks in advance,
joao

you have a few options:

  • use custom rendering with a MeshRenderer and the ConstantColorShader that expects the color to be packed as Float32 (see RGBAToFloat node) into the w component of the vertex.

  • Set the vertex declaration to something that includes vertex color and adjust the buffer element size, the materials should pick that up and use the vertex color as diffuse color (never tested that, though)

  • Don’t use this compute buffer to vertex buffer technique and just use the positions of the compute buffer in a fuse patch and color the particles the fusy way…

Hi @tonfilm,

I already tried the second option, but looks like the material is not picking up the vertex color, unless im missing something. this would be my favorite option but cant get the material to pick up the color. Do you have an idea? What material should i use? i added my project here maybe you spot the mistake

Ill give a try into to the other options…

vl-compute-shaders.zip (86.5 KB)

you can use any material. I believe the help patch set you on the wrong track, you only need a vertex buffer if you actually need a vertex buffer… which means that you want to generate the actual geometry triangles in the compute shader.

but in your example, you seem to only want to draw particles, which you can do with a material extension. the material extension takes the particle buffer and uses the data in the particle to set the vertex position. the mesh is only a NullMesh, which is only used to set the vertex count but doesn’t actually contain any vertex buffer data.

then you can also use the particle buffer to set the color of the material.

vl-compute-shaders2.zip (86.5 KB)

EDIT: forgot to set the bounding box size. the simulation produces values in the 10-20 range, the bounding box must reflect that.

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.