Particle effect attributes

From Popcorn FX
Jump to: navigation, search

See also: Particle system overview


Contents

Overview

Particle effect attributes are vector values that can be accessed from scripts anywhere inside any layer of an effect. Particle attributes are useful to allow gameplay code to control particle effects behavior on a per-instance scale.


To access the particle effect attributes panel, select the 'Particle system' node in the treeview:


ParticleSystem Highlight.png


The attributes will appear inside the node properties panel.
Here are the attributes of the 'FlameThrower.hfx' effect, in the default sample effects package:


ParticleAttributes 03.png

Full mode

ParticleAttributes 01.png

Intermediate mode

ParticleAttributes 02.png

Compact mode

You can switch between three viewing modes:

1- Compact
you just see the attribute name
2- Intermediate
you see the attribute name, and a slider to quickly control the attribute value (actually between 1 and 4 sliders, depending on the attribute's type)
3- Full
every property of the attribute is displayed, as well as the current value's slider.

By default, you see attributes in intermediate mode.


Something to note about the quick-tweaking sliders is that they are not saved in the effect file. When opening the effect, they are set to the 'DefaultValue' of the attribute. Their sole purpose is to quickly check how the effect behaves when the attribute changes. It allows you to emulate in the editor attribute modification that would normally be done by the gameplay code.
The slider allows you to change the attribute of all spawned instances, between 'MinValue' and 'MaxValue'.


The editor uses the min and max values, wether or not 'HasMin' or 'HasMax' is checked, to setup the slider's range, so if your attribute requires no min and max, but you want to test its value between, say, -10 and 10, you'll have to temporarily activate the min/max clamping, set the values to -10 and 10, and deactivate the minmax again.

If 'MinValue' is equal to 'MaxValue', The slider will effectively have a 0-wide range, and you will not be able to move it. that's normal behavior.

Attribute Properties

1- AttributeName
Name of the attribute, published to the scripts
2- AttributeType
Type of the attribute, can be any of the following types:
1- float
2- float2
3- float3
4- float4
5- int
6- int2
7- int3
8- int4
by default, it is set to 'float'
3- AttributeScope
Scope of the attribute, can be any of the following scopes:
1- global : the same values are used for all the instances of the effect. ex: a value telling if it's the day or the night, or a value telling if it's raining or not, or a global air temperature, or uniform wind speed.
2- instance : each effect instance has its own copy of the attribute, and the gameplay code can set different values on a per-instance basis. ex: the strength of a flamethrower, the intensity of a fire...
by default, it is set to 'instance'
4- DefaultValue
Initial value of the attribute, of type 'AttributeType', if untouched at effect instantiation time.
by default, set to 0.0
5- HasMin
checked if the attribute has a min value below witch it cannot go
6- HasMax
checked if the attribute has a max value above witch it cannot go
7- MinValue
min value of the slider, of type 'AttributeType', used only if 'HasMin' is checked.
by default, set to 0.0
8- MaxValue
max value of the slider, of type 'AttributeType', used only if 'HasMax' is checked.
by default, set to 1.0

Publishing to scripts

Attributes are automatically accessible from all the scripts of the particle system. They appear as a variable of type 'AttributeType', named 'AttributeName'.

For example, if we create a 'float2' attribute named 'TeamColor', containing the red and blue values of a team color, we can write inside a script:

Color = float4(TeamColor.x, 0, TeamColor.y, 1);

or:

Color = TeamColor.x0y1;

(see swizzling) This will set the particle color to whatever the gameplay sets the 'TeamColor' attribute to.


! WARNING ! Please note that in the current version of the runtime, the evolve scripts cannot yet access the attributes whose scope is set to 'instance'. Instance Attributes can only be used in the spawn scripts. This will be changed in a later version.
If you need an instance attribute value in an evolve script, you'll need to create a particle field to store the spawn-time value of the attribute.

Example

Here is an example of the 'Throttle' attribute being moved around in the effect 'FlameThrower.hfx' coming in the base samples package.
The attribute is primarily used to control the spawn velocity of the tracer particles that spawn the flame trails:

	Velocity *= Throttle;

Note that the Velocity is initialized with a stream function (which is a shape sampler) before the spawn script is run, and we're just scaling the sampled velocity


Throttle = 1.0
Attributes Flamethrower 0.png
Throttle = 0.8
Attributes Flamethrower 1.png
Throttle = 0.6
Attributes Flamethrower 2.png
Throttle = 0.4
Attributes Flamethrower 3.png
Throttle = 0.2
Attributes Flamethrower 4.png
Throttle = 0.0
Attributes Flamethrower 5.png
Personal tools
Namespaces

Variants
Actions
Navigation
Toolbox