1.
Preparation
This is the effect we are going to make in this tutorial.
Note: The main content of this tutorial comes from the Content Examples
that come with Unreal Engine
Tip: Use ⬆️ ⬇️ to turn the page up and down. We recommend browsing with a large screen for a better reading experience.
3.
Introduction
Expressions are small snippets of HLSL that can be used to create micro behaviors inline in the stack without needing to create new modules.
In this example, no modules are used to influence the simulation, only direct setting of variables in conjunction with expressions and dynamic inputs.
4.
Sim Target
Select Emitter Properties
, set Sim Target
to GPUCompute Sim
, and check Fixed Bounds
.
5.
Spawn Rate
Click on the +
sign to the right of the Emitter Update
to add the Spawn Rate
module.
Spawn Rate
: Number of particles per second to spawn.
6.
Spawn Rate
Set the Spawn Rate
value to 1000.0
.
Spawn 1000.0 particle per second.
7.
Emitter Update Parameter
Add Set new or existing parameter directly
module to the Emitter Update
section.
8.
Emitter Update Parameter
Add a Vector
parameter.
9.
Emitter Update Parameter
Rename this parameter to InitialPosition
and set its value to Simulation Position
.
10.
Emitter Update Parameter
Add a Float
parameter.
11.
Emitter Update Parameter
Rename this parameter to ZOffset
and set its value type to New Expression
.
12.
Emitter Update Parameter
Set ZOffset
to sin(Emitter.Age)*56
.
13.
Remove Initialize Particles
Delete Initialize Particles
module.
14.
Set Parameter
Add Set new or existing parameter directly
module to the Particle Spawn
section.
15.
Particle Spawn Parameter
Add a Vector
parameter.
16.
Particle Spawn Parameter
Rename this parameter to RandomVector
and set its value type to New Expression
, then set its value to normalize(((( rand(float3(1.0,1.0,1.0) ))) * 2 ) -1 )
17.
Particle Spawn Parameter
With the same operation, adds a number of parameters to Particle Spawn
:
Name: Lifetime
Type:float
expression: rand(1.5f) + 2.2f
Name:Position
Type: vector
Expression: Emitter.InitialPosition + Particles.RandomVector *rand(145.0f)
18.
Particle Spawn Parameter
Name: SpriteRotation
Type: float - NormalizedAngle
Expression: rand(1.0f)
Name: SpriteSize
Type: Vector 2d - float
Expression: rand(2.5f) + 0.5f
19.
Particle Spawn Parameter
Name: Velocity
Type: Vector
Expression: cross(Particles.RandomVector, float3(0,8,0)) * (float3(0.0f, 0.0f, Emitter.ZOffset) *0.2f) + (-1.0f * normalize(Emitter.InitialPosition - Particles.Position)*20)
20.
Set Parameter
Add Set new or existing parameter directly
module to the Particle Update
section.
21.
Particle Update Parameter
Name: Color
Type: Linear Color
Expression: Particles.NormalizedAge < 0.333 ? float4(1,0.1,0.1,1) : Particles.NormalizedAge < 0.575 ? float4(0.1,1,0.1,1) : float4(0.1,0.1,1,1)
Name: Position
Type: Vector
Expression: Particles.Position + float3(0, 0, ( sin(Engine.Time) * 0.3f ))
22.
Particle Update Parameter
Name: SpriteSize
Type:Vector 2D
Expression: (1.0f - abs(Particles.NormalizedAge * 2.0f - 1.0f)) * 2.0f
Name: PhysicsForce
Type: Vector
Expression: 1-Particles.RandomVector * (length(Particles.Position - Emitter.InitialPosition)*0.25)
23.
Particle Update Parameter
Note that the namespace for PhysicsForce needs to be located in Transient
24.
Particle Update Parameter
With the same operation, adds a parameter to Particle Update
:
Name: Position
Type: Vector
Expression: Particles.Position.z > Emitter.InitialPosition.z - Emitter.ZOffset ? Particles.Position : float3(Particles.Position.x, Particles.Position.y, Emitter.InitialPosition.z - Emitter.ZOffset)
25.
Solve Forces and Velocity
Add Solve Forces and Velocity
module to the Particle Update
section.