Expression attributes

The @ values you read and write inside an Expression — and which ones exist depends on what you feed in.

An Expression runs your code once per element of whatever you wire into it. An @name is one of those per-element values: a point's position, a pixel's colour, a voxel's density. You read them to make decisions, and you assign to them to change the result.

// read @Cd, write @P.z — push each point up by its brightness
@P.z = luminance(@Cd) * 100.0;

What you feed in decides what you get

The kind of thing you plug into an Expression sets the "loop" it runs over and which @ values are on the table:

You don't pick the mode — it follows the input automatically. See Automatic conversion for how DNA converts between these.

An image or volume going into an Expression usually comes out as points (one per pixel/voxel). That's how you turn a depth image into a 3D point cloud — read @Cd, write @P.z. A Volume stays a Volume so you can keep processing it.

The common attributes

These are the ones you'll reach for most. Vectors support swizzles, so @P.z, @Cd.rgb, and @uv.x all work.

AttributeWhat it isWhere it lives
@PPositionpoints, mesh, volume, distance field
@CdColour (RGBA)points, image
@NNormal directionpoints, mesh
@pscalePer-element scale / sizepoints
@uvTexture coordinateimage, mesh
@densityVoxel valuevolume
@distDistance to surfacedistance field
@analyticWhether the shape stays an Analytic shapepoints
@idStable identity that survives across framespoints
@ptnumThe element's index in the looppoints

For the full picture of how attributes attach to data, see Attributes.

Reading vs writing

Reading is just mentioning the attribute. Writing is assigning to it on the left of an =.

@Cd = @P.y > 0 ? {1, 0, 0, 1} : {0, 0, 1, 1};   // read @P, write @Cd
@P += @N * noise(@P * 0.1 + $T) * 5.0;            // read @N and @P, write @P

A few worth calling out:

Not every attribute exists on every input. Reading @density on a point cloud, or @N on an image, won't give you anything useful — match the attribute to the input type from the table above.

See also