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
| Type | Name | Description |
|---|---|---|
static constexpr int32_t | kFirstCustomSlot | Slot 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_t | kCustomAttributes | Default 4. |
static constexpr int32_t | kWritableSlots | Default 19. |
static constexpr int32_t | kBuiltinSlots | Default 30. |
static constexpr int32_t | kMaxLocals | Default 16. |
static constexpr int32_t | kStackDepth | Default 32. |
static constexpr uint32_t | kGpuProgramHeaderWords | Words before the bytecode in a packed GPU program block. Default 12. |
Public functions
| Returns | Name | Description |
|---|---|---|
bool | Compile | False with Error() naming the problem and where (1-based column). |
bool | Compile | |
void | CollectAttributes | Appends to inOutAttributes, in order of first appearance, every attr.<name> the script mentions that the table does not hold yet. |
void | Run | |
bool | IsValid | |
const std::string& | Error | |
size_t | InstructionCount | |
const std::vector<FInstr>& | Code | |
const std::vector<float>& | Constants | |
uint32_t | WriteMask | Bit per writable slot the script assigns, so Run writes back only those. |
uint32_t | AppendGpuProgram | 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. |
float | NextRandom |
Function details
Compile
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
bool Compile(const std::string& source, const std::vector<std::string>& attributes)CollectAttributes
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
void Run(Particle& particle, const FContext& context, uint32_t& randomState) constIsValid
bool IsValid() constError
const std::string& Error() constInstructionCount
size_t InstructionCount() constCode
const std::vector<FInstr>& Code() constConstants
const std::vector<float>& Constants() constWriteMask
uint32_t WriteMask() constBit per writable slot the script assigns, so Run writes back only those.
AppendGpuProgram
uint32_t AppendGpuProgram(const float params[4], float time, uint32_t seed, std::vector<uint32_t>& words) constPacks 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
static float NextRandom(uint32_t& state)