PA Particle Field Manual

 About

 

PA Particle Field is an alternative particle system for Unity, specifically optimized for looping ambient effects with minimal CPU usage.

PAParticleField combines procedurally generated meshes with a specialized selection of shaders. Particles are positioned within the field bounds, and when a particle reaches one edge of the bounds it reappears on the opposite side. This way a constant number of particles exist at any time. Particles are inherently persistent, they have no “lifetime” or birth/death events, they exist forever only appear to die when they leave the bounds of the field and are recycled, and because of this its possible to emulate an infinite amount of particles simply by parenting the system to the camera.

 

 Getting Started

 

Creating A PA Particle Field in the Editor

To create a field, from the toolbar click “GameObject>Create Other>PA Particle Field”. Alternatively to create a PA Particle Field from scratch, create a new empty GameObject from the toolbar using “GameObject>Create Empty”.

Add a PA Particle Field component to the new GameObject, either by dragging the PAParticleField script from the project window onto the inspector or using the “Add Component” menu.

This will create a PAParticleField with the default settings

Creating a PA Particle Field through Script

There is a helper function to create a PAParticleField in C#

public static PAParticleField PAParticleField.Create(string name)

This will create a new GameObject with the specified name and a PAParticleField component attached.

 Field Properties

 

The Field Properties control the overall appearance and features of the shape of the system, including particle count, simulation space and defining how particles react when they reach the edge of the field.

 

Random Seed

The seed used when generating the random elements of the particle mesh, position, direction, speed, color size and spin speed. Changing this value will change the look of the system, and different seeds may provide nicer distribution of particles. The same seed value will always result in the same particle layout, this can be useful for overlaying particles.

Changing this value causes a complete mesh rebuild.

PLAY

 

Particle Count

The number of particles in the field, the maximum count per field is determined by the particle type, billboard particles are limited to 16250, mesh particles are limited to 65500/(input mesh vertex count) . If more particles are required then create a duplicate PAParticleField with a different seed.

Changing this value causes a partial mesh rebuild.

PLAY

 

Simulation Space

Particles can be simulated in either World, Local or Local with Deltas space. When simulating in world space, when the transform moves the individual particles maintain their world space position and are unaffected by rotation and scale.

In local space the particles move with the transform, the field can be rotated and scaled.

In Local with deltas, when the transform changes position the particles maintain their world space position, but when rotated or scaled the field acts like local space.

Using world space mode it can be made to appear that there are an infinite amount of unseen particles in all directions, with the field acting as a 3D window to view a section of them.

PLAY

 

Field Size

The bounds of the field in units. This determines the area where particles will be visible and the distance from the transform that particles will be recycled. Changing this value noticeably moves the particles, and if modified at runtime probably shouldn’t be changed when the field is on screen.

PLAY

 

Shape

The shape of the field can be set as Cube, Sphere or Cylinder. Particles fade by default when they reach the edge of the field defined by this shape.

PLAY

 

Edge Mode

Defines how particles are handled when they reach the bounds of the field. Particles can fade, scale or both to prevent a sudden disappearance.

PLAY

 

Edge Threshold

Vector3 that indicates how far from the fields edge the particles will be when the Edge Mode begins to affect them. The values should be in the [0-1] range, a value of 1 means the effect starts from the middle of the field. When the Cube shape is used all 3 values are relevant, for the Cylinder just the x and y are used and for a Sphere only the x.

PLAY

 

Rebuild At Runtime

Fields maintain a cache of mesh data which speeds up start up times but can increase scene and build size. By having this option enabled the cache will be cleared, reducing file size and build size but increasing the start up time.

 Exclusion Zones

 

Exclusion Zones allow you to mask out areas in a field, this can be useful to prevent particles passing through your main character, or to completely hide a rain field when the player moves indoors.

To use Exclusion zones first exclusion zones must be enabled on the field, then some exclusion zones must be created, this can be done using GameObject > Create Other > PA Exclusion Zone from the top menu, or creating a new GameObject and add the PAExclusionZone.cs script.

The exclusion zone will show a box gizmo in the scene view representing the zone, this can be scaled, moved and rotated using normal transform controls, when this intersects with the particle field the particles in the intersection will be excluded.

Each field can support 3 exclusion zones at once, meaning that if 4 exclusion zones are intersecting 1 field all at the same time, 1 will not be applied. To pick which three are applied the zones are sorted by ‘importance’ then by distance from the center of the field.

Sometimes sorting from the center of the field is not right for the effect, for example with a large field parented in front of the camera its likely the exclusion zones nearest the camera are more important than those at the center of the field. To sort them by distance from a position other than the center, a transform can be assigned as an anchor override, in this case the camera.

Lastly, because in some cases a particular exclusion zone always wants to be excluded it can be set as ‘important’, when the zones are sorted, ‘important’ zones are sorted first, then unimportant.

 

Use Exclusion Zones

When enabled the field will be affected by up to 3 exclusion zones

PLAY

 

Anchor Override

When exclusion zones are enabled the 3 zones closest to the centre of the field will be used, if a transform is assigned as an override the 3 closest to that transform will be used.

 Global Particle Properties

 

These properties define how the vertices of the particles will be positioned, their speed, size and rotation all contribute to the final particle position.

 

Particle Size

Sets the size of the particles in units, allowing different aspect ratios. For Mesh Particles only the X value is used

PLAY

 

Color

A color applied to all particles, multiplied over any per particle color variation. This is useful for simulating lighting in unlit or fading a field to completely transparency.

PLAY

 

Move Speed

Each particle has a random movement vector, this value indicates how fast all the particles should move along that vector, if particles have varying speed, this value also indicates the maximum speed.

PLAY

 

Speed Mask

Particles have a random 3D direction vector, this property allows this to by scaled or clamped along the x, y and z axis.

PLAY

 

Force

Applies a constant movement in a single direction to all particles, useful for simulating wind, flow or gravity.

PLAY

 

Stretched

When enabled particles orientation will align with the direction they are travelling and their y size will be multiplied by their velocity and the stretch multiplier. Enabling this overrides custom up direction and spin.

Stretch Multiplier

When Stretched is enabled the particles height will be multiplied by this value and the particles velocity. This is currently not applied on mesh particles.

PLAY

 

Spin

When enabled particles will rotate around forward axis of the camera on their pivot.

Spin Speed

The speed at which particles will rotate around their pivot when Spin is enabled.

PLAY

 

Face Direction

By default particles will face the camera, this is normally the desired behavior but sometimes it can be useful to specify the direction the particles should face. This is useful for 2D effects, and effects that depend on a flat surface, for example rain drop ripples on the floor would face up.

Mesh particles face along the Z axis by default.

PLAY

 

Up Direction

By default particles are oriented base on the world up (or in local space mode the transforms up), but this can be overwritten when needed, this is useful for effects like caustics/god rays where the Up Direction is oriented in the direction of the light.

PLAY

 

Soft Particles

Similar to Unity’s own soft particle feature, this effect fades particles to zero as they approach a surface or the camera.

If set to “Near Clip Only” the particles will fade near the camera.

If set to “Near Clip and Camera Depth” the particles will also fade as they approach a surface, to work the camera rendering the particles must render a depth pass, this is enabled by default when using Deferred rendering but in Forward rendering will require a script to change the camera’s depth rendering mode.

See http://docs.unity3d.com/Manual/SL-CameraDepthTexture.html for more information on this topic.

Soft particle values are not applied when a Custom Material is used and should be handled on the material.

 Turbulence

 

Particles can be affected by turbulence, moving them in a non linear way that can add realism to the effect. In the shader, Turbulence is applied after recycling at the bounds and before exclusion zones, this means that when using turbulence its possible for the particle to move outside the regular bounds.

Turbulence is a fairly costly effect and 2 modes are exposed, Simplex2D and Simplex, both modes provide very similar effects but on Simplex2D the z axis movement is reconstructed from the x and y axis movement, making it perform better. On lower end platforms Simplex will fallback to Simplex2D or Sine based depending on available instructions.

When Stretched particles is enabled, the performance hit of turbulence is doubled as the turbulence needs to be recalculated for the previous frame to calculate the direction the particle has moved.

 

Type

 

Sets the type of turbulence to be applied, Simplex2D or Simplex. Both provide similar effects but Simplex2D is faster as it reconstructs the Z axis turbulence from the x and y results.

Note: Currently only Sine based is supported on Unity 4.x

PLAY

 

Frequency

Changes the how radically the turbulence changes from one position to another. Low values mean that particles that are close to each other will have similar amounts of turbulence applied to them so they will appear to move together, high values will make particles act very independent of one another.

Offset Speed

The turbulence can be made to move through the field as well as having the particle move through the turbulence, this value controls the movement of the turbulence in world space.

Combinations of these values can produce many effects, the fish example uses low frequency with a moderate offset speed, and the particles move speed is set to 0. This means that the particles will never move to the edge of the bounds and be recycled, and their movement will be entirely dictated by turbulence. Using a low frequency value all the fish appear to move together in a school.

PLAY

 

Amplitude

Changes how far the particles will move from their pre-turbulence position, a value of 0 would be the equivalent of having no turbulence. This value also determines how far a particle may move outside the bounds.

PLAY

 Per Particle Properties

 

These properties affect values for individual particles, per particle data is encoded into the vertex data and changes will cause a partial mesh rebuild.

 

Color Variation

This is a Gradient value, when the particle mesh is generated particles will sample a random color from the gradient. This allows powerful color customization and weighting, by specifying larger regions of color in the gradient a particle has a greater probability of receiving that color.

Changing this value causes a partial mesh rebuild so should be avoided at runtime if possible.

PLAY

 

Size Variation

Indicates the minimum size a particle will be, as a percentage of the Particle Size. Particles randomly choose a size between this fraction and the main Particle Size. When accessed through scripts this value should be assigned in the [0-1] range.

Changing this value causes a partial mesh rebuild so should be avoided at runtime if possible.

PLAY

 

Speed Variation

Indicates the minimum speed a particle will have, as a percentage of the Move Speed. Particles randomly choose a speed between this fraction and the main Move Speed. When accessed through scripts this value should be assigned in the [0-1] range.

Changing this value causes a partial mesh rebuild so should be avoided at runtime if possible.

 

PLAY

 

Spin Variation

Indicates the minimum spin speed a particle will have, as a percentage of the Spin Speed. When accessed through scripts this value should be assigned in the [0-1] range.

Changing this value causes a partial mesh rebuild so should be avoided at runtime if possible.

PLAY

 Sprite Properties

 

These properties affect the surface of the particle, how its textured and rendered.

 

Material

The material type to be applied to the field, there are several built in shaders including;

  • Transparent
  • Transparent Lit
  • Additive
  • Additive Lit
  • Cutoff
  • Cutoff Lit
  • Mesh Default
  • Mesh Unlit

The material can also be set to Custom, allowing custom materials and shaders to be used for advanced effects. Selecting Custom opens a material slot to drop the desired material. It is assumed that the custom material uses a compatible shader.

Note: Currently all types are shown in the dropdown regardless of particle type, but only shaders prefixed with “Mesh” are compatible with mesh particles, and the mesh shaders are not compatible with billboard particles.

 

Cut Off

When the Blend Mode is set to Cut Off, this value controls the materials Cut Off value.

If a Custom Material is used this has no effect, and should be handled on the material.

 
PLAY

 

Texture Type

The arrangement of the texture can be either Simple, SpriteGrid or AnimatedRows. By default its expected to be a single image, however if SpriteGrid is selected and the Columns and Rows properties are defined, each particle will be randomly assigned a section of the texture. If AnimatedRows is selected each particle will be assigned a row, then at runtime will increment along that row by the Framerate, providing sprite based animation.

 

Texture

The texture applied to the particles.

If a Custom Material is used this has no effect, and should be handled on the material.

 

Pivot Offset

This is the position away from the particles center that the particle will be drawn. This is useful for offsetting rotation and scale.

Examples of unorthodox usage of this is the caustic effect demo, it has its pivot moved to the top of the particle to make the particle scale in a downwards direction, and the snow demo has its pivot offset off the particle completely to add extra cheap turbulence.

Changing this value causes a partial mesh rebuild so should be avoided at runtime if possible (this may change in future versions).

 

Rows

When the Texture Type is SpriteGrid or AnimatedRows, this indicates the number of rows in the texture.

 

Columns

When the Texture Type is SpriteGrid or AnimatedRows, this indicates the number of columns in the texture.

 

Framerate

When the Texture Type is AnimatedRows this value controls the frame rate the animation will play in. The animation will play from left to right when a positive value is used, and right to left when a negative value is used.