GParticles Resources - tiagodinis/GParticles GitHub Wiki
A particle system can be viewed as a large collection of data that is processed following certain rules. In GParticles, this data can be stored in 3 different types of resources:
-
Buffers - fixed size arrays of a certain element type. Their main use case is the representation of one property of the system particles (e.g., their lifetimes or velocity), each buffer index refering to a different particle. Buffers are also commonly used as a way to communicate between different particle systems;
-
Atomics - unsigned integer hardware counters that can only be incremented, decremented and have its value read. Although their functionality is limited, atomics are very useful on such a parallel environment as the GPU is. We can use atomics to count processing iterations, alive particles or keep track of a buffer index, assuming its data is tightly packed;
-
Uniforms - global variables on the programs that process particle data, and have immutable value during the execution of one of such programs;
To load our projects with resources we declare their corresponding tags, buffer, atomic and uniform, inside domain tags that tell GParticles how they should be initialized.
An [instance](https://github.com/tiagoddinis/GParticles/wiki/instance-tag) resource refers to a property every particle of the project should have, and so, a new instance is created for every particle system. For example, if we define an [instance]() buffer named "_positions_" and 2 particle systems named "_ps1_" and "_ps2_", GParticles will load 2 buffers with names "_ps1_positions_" and "_ps2_positions_", each belonging to their corresponding system. A [global](https://github.com/tiagoddinis/GParticles/wiki/global-tag) resource does not belong to a particular system, can be accessed by all of them, and as such, has only one global instance.Below is the resource configuration file used in every GParticles tutorial (located in the "prefabs/resources/" folder), a good example of how everything just described comes together:
<resources>
<instance>
<buffer name="lifetimes" elements=512 type="float" />
<buffer name="lineLifetime" elements=512 type="float" />
<buffer name="positions" elements=512 type="vec4" />
<buffer name="lastPositions" elements=512 type="vec4" />
<buffer name="velocities" elements=512 type="vec4" />
<buffer name="colors" elements=512 type="vec4" />
<buffer name="texCoords" elements=512 type="vec2"/>
<buffer name="size" elements=512 type="float" />
<atomic name="aliveParticles" />
<atomic name="emissionAttempts" />
<uniform name="maxParticles" type="float" value=10 />
<uniform name="toCreate" type="float" value=500 />
<uniform name="deltaTime" type="float" />
</instance>
<global>
<atomic name="randomCounter" value=0 />
<uniform name="mouseXY" type="vec2" />
</global>
</resources>None of the above resources is required a priori by a GParticles project, with the exception of the maxParticles uniform, which must be present to set instance buffer sizes in an uniform way. Also, when using modules and templates (introduced in Tutorial 2), we'll need to guarantee the resources they reference are available.