Extend particle input

Currently, there are two subclasses in the project that inherit from SSF_ParticleSource, namely SSF_LoadParticlesFromParticleSystem and SSF_LoadParticlesFromFile. SSF_ParticleSource represents the source of particle data required for rendering and is also the starting point for extension.

Considering that users may have their own source of particle data, such as a particle solution system running in parallel with the GPU, or imported pre-made particle data, here we will explain how to extend the input of particle data.

Particle Data Struct

The structure of particle data in SSF is as follows:

public struct SSF_particle
{
    public Vector3 position;
    public Color color;
    public float radius;
}

If you modify the particle’s data structure, you need to pay attention to replacing 32 in particleBuffer = new ComputeBuffer (getParticleNum (), 32); in SSF_ParticleSource.cs with the number of bytes of particle data. At the same time, corresponding changes should be made in DepthColorThickness.shader.

Explain SSF_ParticleSource

The input and update of extended data is to create a new class inheriting from SSF_ParticleSource and implement the corresponding virtual function.

The following two member variables exist in SSF_ParticleSource:

protected ComputeBuffer particleBuffer;// Buffer sent to GPU
protected SSF_particle[] particlesData;// Particle Data for above buffer

Where particleBuffer is used to provide data to generate related textures for rendering.

You can notice that the following member function modifiers in SSF_ParticleSource are public virtual:

  • SetupParticleBufferData ()

  • UpdateParticleBufferData ()

In SetupParticleBufferData , ParticlesData needs to be created and assigned, and updated in UpdateParticleBufferData () , neither of these operations need to involve particleBuffer.

You should also implement UpdateBounds() , the bounds is used for culling out of view particles, which saves a lot performance.

Example

You can also refer to SSF_LoadParticlesFromParticleSystem, this is a bit complicated and tedious.

Last updated