class

FParticleExpression

A per-particle script, the Niagara scratch-pad analogue: statements of the form vel.y = vel.y - 9.8 * dt (also += -= *= /=), separated by newlines or semicolons, compiled once into stack bytecode and run for every particle — on the CPU by Run, on the GPU by Particles/GPUParticleExpression.comp.hlsl, which interprets the same bytecode (AppendGpuProgram packs it).

Module
Particles
Header
#include "Particles/ParticleExpression.h"
Namespace
Mowo

Writable: pos.x/y/z, vel.x/y/z, size.x/y, rot, spin, col.r/g/b/a, life, and up to four custom attributes attr.<name> that live on the particle for its whole life (zero at spawn). Read-only: age, nage (0..1), dt, time, emitter.x/y/z, param1..param4, pi, rand (a fresh uniform [0,1) per read). Any other name assigned before it is read is a local. Functions: sin cos tan abs sign floor frac sqrt exp min max pow atan2 mod step clamp lerp smoothstep. Operators: + - * / < > <= >= == != && || ! and the ternary c ? a : b.

Properties

TypeNameDescription
static constexpr int32_tkFirstCustomSlotSlot layout, shared with the GPU interpreter: the writable block first (so the write mask is its low bits) with the custom attributes at its end, then the read-only inputs, then locals. Default 15.
static constexpr int32_tkCustomAttributesDefault 4.
static constexpr int32_tkWritableSlotsDefault 19.
static constexpr int32_tkBuiltinSlotsDefault 30.
static constexpr int32_tkMaxLocalsDefault 16.
static constexpr int32_tkStackDepthDefault 32.
static constexpr uint32_tkGpuProgramHeaderWordsWords before the bytecode in a packed GPU program block. Default 12.

Public functions

ReturnsNameDescription
boolCompileFalse with Error() naming the problem and where (1-based column).
boolCompile
voidCollectAttributesAppends to inOutAttributes, in order of first appearance, every attr.<name> the script mentions that the table does not hold yet.
voidRun
boolIsValid
const std::string&Error
size_tInstructionCount
const std::vector<FInstr>&Code
const std::vector<float>&Constants
uint32_tWriteMaskBit per writable slot the script assigns, so Run writes back only those.
uint32_tAppendGpuProgramPacks the program for the GPU interpreter: a 12-word header (instruction count, constant count, write mask, random seed, param1..4, time, three spare), the instructions as op | arg << 16, then the constants' bits.
floatNextRandom

Function details

Compile

C++
bool Compile(const std::string& source)

False with Error() naming the problem and where (1-based column). The one-argument form takes its custom attributes from the script itself; an emitter whose scripts share attributes passes the table every script of the emitter agreed on, so attr.heat names the same slot in all of them.

Compile

C++
bool Compile(const std::string& source, const std::vector<std::string>& attributes)

CollectAttributes

C++
static void CollectAttributes(const std::string& source, std::vector<std::string>& inOutAttributes)

Appends to inOutAttributes, in order of first appearance, every attr.<name> the script mentions that the table does not hold yet.

Run

C++
void Run(Particle& particle, const FContext& context, uint32_t& randomState) const

IsValid

C++
bool IsValid() const

Error

C++
const std::string& Error() const

InstructionCount

C++
size_t InstructionCount() const

Code

C++
const std::vector<FInstr>& Code() const

Constants

C++
const std::vector<float>& Constants() const

WriteMask

C++
uint32_t WriteMask() const

Bit per writable slot the script assigns, so Run writes back only those.

AppendGpuProgram

C++
uint32_t AppendGpuProgram(const float params[4], float time, uint32_t seed, std::vector<uint32_t>& words) const

Packs the program for the GPU interpreter: a 12-word header (instruction count, constant count, write mask, random seed, param1..4, time, three spare), the instructions as op | arg << 16, then the constants' bits. Returns the block's offset in words.

NextRandom

C++
static float NextRandom(uint32_t& state)
Generated from Particles/ParticleExpression.h via particles.json · Oct 31, 2026Version 1.0.0