GPU particles with Mesh and Col

ParticleswithMeshAndColour.zip (33.8 KB)

Using the example in preview 293 Example GPU Particle System with Mesh.vl, I’ve tried to add a compute shader into the PBR material so I can colour instances individually, I’ve hooked colour up to vel in the simulation shader for testing, but also tried setting it in a float4
And used Example Geometry Shader with PBR.vl as a base for the compute. But when I hook it up to the material, it hangs and quits, so I’m definitely doing it wrong :D
Going away for a couple of days, so thought I’d park this here and see if anyone can tell me where I’m messing up! Thanks :)

you can use the Value/ColorPerInstance node here.

you have two options if you want to read the color from the particle buffer:

you can do the same as you do with the transformations, write them into a ComputeBuffer and connect that buffer to the material. look into the ColorPerInstance node to see how you read a buffer value per instance.

or, if you want to write a ShaderFX that reads the color from the particle buffer and provides it to a material you can do it like that:

shader ColorPerParticle_ShaderFX : ComputeFloat4, ParticleStructPos4Vel4, ShaderBaseStream // for InstanceID
{
    rgroup PerMaterial
    {
        stage StructuredBuffer<ParticlePos4Vel4> ParticlesBuffer;
    }

    override float4 Compute()
    {
        uint id = streams.InstanceID;
        ParticlePos4Vel4 p = ParticlesBuffer[id];
        return float4(p.Vel.xyz, 1);
    }
};

in the shader in your screenshot, you are reading per VertexID.

1 Like

Ah! I’ll give that a shot when I’m back :) thanks

Particles with Mesh and Color.zip (36.3 KB)
It doesn’t crash when I connect the compute now, but I still dont get per instance colour (it should be getting the vel as colour set in the simulation shader). Is there something else I need to do in the compute?

yes, it works correctly, but you are using the PBR material node with the specular workflow. for that you need to set the specular map, otherwise, you only see the specular contribution to the pixel color.

if you switch to the metallic workflow you see the diffuse color without modification.

1 Like

Wow, yes it works, hurray!! Thanks for your help again :)

Particles.zip (159.7 KB)
Another slight hickup, from riot.
I’m having the shader break when I try and use another buffer input, is this something I’m doing wrong?

as I wrote in the chat, changing Buffer to StructuredBuffer works fine:

Particles.zip (320.6 KB)

1 Like

Cat_Particles.zip (75.7 KB)

Here is an updated particle system, I’ve got normal sprites working, and mesh, but can’t get the imposter particles working for some reason. Any ideas? (all in the draw patch)
I do have interframe particle emision though which has been on my list for ages, ie multiple particles per frame get spread between previous emiter postion and the latest rather than just clumping together (kind of like motion blur). Need to get colour over life working for the mesh particles too and the curl in a separate shader. But pretty functional for now.

1 Like

Upcoming preview will contain a NullMesh that you should use for particle systems that use a geometry shader and a stride material. it fixes an issue found in the FUSE sphere imposters. there was a problem with topology and instances.

have a look into the GPU particle system with PBR example patch to see how to use it.

1 Like

the reason was that when you renamed the file, you forgot to rename the shader inside. so it wasn’t found. i’ve fixed that and added the proper imposter implementation from the FUSE repo.

also some minor fixes:

  • sphere imposters get the color from the particle, same as the meshes
  • static random values is now an immutable buffer
  • the quantized count wasn’t use consistently
  • you can get the TimeStep by including Global, no need to pass it into the shader

Cat_Particles2.zip (75.3 KB)

1 Like

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