Docs 3D and Particles
ExpressionPOP
Per-point attribute expressions for POPs: write lines like P = P + N * 0.1 and they compile to a GLSL compute shader, with local variables carried between lines. An alternative for the Math Combine POP.
⁂ 3D and Particles OP Create menu entry
Why use it
Small per-point jobs come up all the time in POPs: push the points out along their normals, colour them by position, scale them by some attribute. With stock operators that is either a chain of Math Combine and Math Mix POPs, each set up through menus and attribute scopes, or a GLSL POP where you write the compute shader yourself, boilerplate and all.
ExpressionPOP lets you write the math the way you would say it. Each line is
one expression, like P = P + N * 0.1, and ExpressionPOP writes the GLSL
compute shader around your lines, so it runs on the GPU however many points
come in.
Features
- Point math in plain linesWrite one expression per line, such as
P = P + N * 0.1, and read any point attribute of the input by its name. - GPU compute shader from your linesThe lines compile into a GLSL compute shader on the GPU, so the math stays fast however many points come in.
- Local variablesTyped locals such as
vec3 offset = N * 0.2carry over to every later line, so a long calculation splits into readable steps. - GLSL code and compile errorsThe viewer switches between the points, the generated GLSL and the compile result, and the code and the result also come out as DATs.
- Replace a Math Combine POPOffered in place of a Math Combine POP, wired into the same spot, when you create one with the alternatives shortcut held.
How to use it
- Create it from the FNS tab of the OP Create dialog. Or create a Math Combine POP with the alternatives shortcut held, pick ExpressionPOP, and it lands in that spot with the wiring kept.
- Wire points into it: a Grid POP, a Sphere POP, the output of a particle system.
- Type a line into Attribute Expression, for example
P = P + N * 0.1. The left side is the attribute it writes, and on the right any point attribute of the input is read by its name. - Add more lines with the sequence's + button. They run in order, on every point.
- Check the result. Info shows the compile result, so a typo shows up there as a shader error. Set View to Code to see the GLSL your lines turned into, or to Info to read the compile result in the viewer.
Out Attrs lists every attribute the lines write, collected from their left sides, which is a quick check that a line writes what you meant.
Writing expressions
The right side of a line is GLSL, so vector types, swizzles and the built-in
functions all work: sin(), mix(), length(), normalize() and the rest.
P = P + N * 0.1
Color = vec4(P, 1)
The first line pushes every point along its normal, the second colours each point by its position.
To split a longer calculation into steps, use a local. Switch on OutAttr/Local for that line and give the left side a GLSL type; every later line can then use the name:
vec3 offset = N * 0.2, with OutAttr/Local on.P = P + offset * length(P), with it off.
A line is split at its = signs, so comparisons that contain one (==, >=,
<=, !=) do not work inside a line. <, > and step() still do.
Inputs and outputs
- in1 (POP): the points to process.
- out_pop (POP): the points with the expressions applied.
- out_code (DAT): the generated shader code.
- out_info (DAT): the compile result.
Get it
Tick it on the install page and it installs with the rest of your setup and stays up to date.
Download ExpressionPOP.tox Version 1.0.6, the tool on its own. It works in any project, and this copy never updates itself.
Where it appears
- OP Create menu entryposition 0
Parameters
Custom
| Control | Type / default | What it does |
|---|---|---|
ExprExpr |
sequence0 | One block per expression line, run in order on every point. |
Attribute ExpressionExpr0expression |
textempty | One line such as P = P + N * 0.1. The left side is an output attribute (or a local when OutAttr/Local is on); input attributes are read by name on the right. |
OutAttr/LocalExpr0leftmode |
on / offoff | local needs type declaration like vec3 etc, but then are reusable in consequent blocks |
InfoInforead-only |
textempty | Read-only: the compile result of the generated shader, so an error shows here. |
Out AttrsOutattrsread-only |
textempty | Read-only: the attributes the shader writes, collected from the left side of every line. |
ViewView |
menuPOP | What the node's viewer shows: the output points, the generated GLSL code, or the compile info. |