Skip to main content

Node

Enum Node 

Source
#[non_exhaustive]
pub enum Node {
Show 54 variants Const { ty: Type, values: Vec<f64>, }, ConstArray { element_ty: Type, values: Vec<f64>, }, ArrayVar { element_ty: Type, values: Vec<f64>, }, Uniform(Rc<UniformNode>), BufferElement { buffer: Rc<BufferNode>, index: NodeRef, }, Attribute { name: &'static str, ty: Type, }, InstancedAttribute { buffer: Rc<InstanceBuffer>, offset: usize, ty: Type, }, Builtin(Builtin), Compute { flow: Rc<ComputeFlow>, output: NodeRef, }, Var(Rc<VarDef>), VarIntent(Rc<VarDef>), Let(Rc<VarDef>), Varying(Rc<VaryingDef>), Property { name: &'static str, ty: Type, }, Param { name: &'static str, ty: Type, }, Assign { target: NodeRef, value: NodeRef, }, Op { op: &'static str, a: NodeRef, b: NodeRef, ty: Type, }, Math { name: &'static str, args: Vec<NodeRef>, ty: Type, }, Swizzle { node: NodeRef, components: &'static str, ty: Type, }, Cast { node: NodeRef, ty: Type, }, Neg { node: NodeRef, ty: Type, }, Join { args: Vec<NodeRef>, ty: Type, }, Element { node: NodeRef, index: NodeRef, ty: Type, }, Texture { texture: Rc<TextureSource>, uv: NodeRef, mode: SampleMode, ty: Type, }, TextureSize { texture: Rc<TextureSource>, level: NodeRef, }, VaryingProperty { name: &'static str, ty: Type, flat: bool, }, Call { def: Rc<FnDef>, args: Vec<NodeRef>, }, Code(Rc<CodeDef>), CodeCall { def: Rc<CodeDef>, args: Vec<NodeRef>, }, Block { statements: Vec<NodeRef>, result: NodeRef, }, Loop { start: Option<NodeRef>, count: NodeRef, index: NodeRef, condition: &'static str, update: Option<NodeRef>, body: Vec<NodeRef>, }, Break, Continue, TextureStore { texture: Rc<TextureSource>, coord: NodeRef, value: NodeRef, }, If { cond: NodeRef, body: Vec<NodeRef>, else_body: Vec<NodeRef>, }, IfVar { pre: Vec<NodeRef>, result: NodeRef, cond: NodeRef, body: Vec<NodeRef>, }, Discard, Return { value: NodeRef, }, Not { node: NodeRef, }, BitNot { node: NodeRef, ty: Type, }, Select { cond: NodeRef, a: NodeRef, b: NodeRef, ty: Type, }, StructMember { buffer: Rc<BufferNode>, member: usize, }, Atomic { method: &'static str, pointer: NodeRef, value: Option<NodeRef>, }, Workgroup(Rc<WorkgroupArrayDef>), Barrier { scope: &'static str, }, Subgroup { method: &'static str, a: Option<NodeRef>, b: Option<NodeRef>, }, Custom(Rc<dyn CustomNode>), Context { node: NodeRef, value: Rc<ContextValue>, }, Isolate { node: NodeRef, }, Expression { snippet: Rc<str>, ty: Type, }, Debug { node: NodeRef, callback: Option<DebugCallback>, }, StructNew { layout: Rc<StructLayout>, values: Vec<NodeRef>, }, OutputStruct { members: Vec<NodeRef>, }, StructGet { value: NodeRef, layout: Rc<StructLayout>, member: usize, },
}
Expand description

The node set. Closed on purpose: an exhaustive match in the builder is what tells the next rung it has added something the generator cannot emit. Node::Custom is the one opening, and it can only compose the others.

Variants (Non-exhaustive)§

This enum is marked as non-exhaustive
Non-exhaustive enums could have additional variants added in future. Therefore, when matching against variants of non-exhaustive enums, an extra wildcard arm must be added to account for any future variants.
§

Const

A literal. values holds one entry per component.

Fields

§ty: Type

The literal’s WGSL type.

§values: Vec<f64>

One entry per component.

§

ConstArray

array< f32, N >( … ) — QuadMesh’s vertexNode.

Fields

§element_ty: Type

The array’s element type.

§values: Vec<f64>

The array’s contents, one entry per component of each element.

§

ArrayVar

The same literal array held in a var<private> nodeVarN : array< T, N > rather than written out at each use — three.js’ TempNode promotion of an array() that the flow reads more than once, which BloomNode’s composite does five times (dump/m11).

Fields

§element_ty: Type

The array’s element type.

§values: Vec<f64>

The array’s contents, one entry per component of each element.

§

Uniform(Rc<UniformNode>)

UniformNode.

§

BufferElement

BufferNode element access: NodeBuffer_N.value[ index ].

Fields

§buffer: Rc<BufferNode>

The buffer being indexed.

§index: NodeRef

The element index.

§

Attribute

A geometry attribute.

Fields

§name: &'static str

The attribute’s name in WGSL.

§ty: Type

The attribute’s WGSL type.

§

InstancedAttribute

instancedBufferAttribute( buffer, type, stride, offset ): a vertex attribute whose buffer steps once per instance. offset is in floats from the start of the instance; the stride is the buffer’s item_size, which is all three.js’ own call sites use.

Fields

§buffer: Rc<InstanceBuffer>

The per-instance buffer.

§offset: usize

The offset into one instance’s data, in floats.

§ty: Type

The attribute’s WGSL type.

§

Builtin(Builtin)

A WGSL builtin input.

§

Compute

ComputeNode used as a value — Fn( () => { …; return x } )().compute( count ) set as a material’s positionNode. Outside the compute stage it generates output (properties.outputComputeNode); the kernel itself runs from updateBefore() (NodeUpdateType.FRAME), which the builder records in NodeProgram::update_before for the renderer to dispatch. See docs/nodes.md §44 and §57.

Fields

§flow: Rc<ComputeFlow>

The compute kernel’s statements and dispatch size.

§output: NodeRef

The value read outside the compute stage.

§

Var(Rc<VarDef>)

VarNode — a cached var<private>.

§

VarIntent(Rc<VarDef>)

VarNode with intent set, as it ends up when something assigns to it — see to_var_intent. A WGSL function-scope var, declared with its value where it is first built (var nodeVar0 : vec3<f32> = …;) instead of hoisted into the // vars block.

§

Let(Rc<VarDef>)

VarNode with readOnly set — node.toConst(). A WGSL let, so it is declared where it is assigned and, unlike a var<private>, cannot be written again.

§

Varying(Rc<VaryingDef>)

VaryingNode.

§

Property

A var<private> with a fixed name that the setup code assigns explicitly — PropertyNode (DiffuseColor, Output, …).

Fields

§name: &'static str

The property’s name in WGSL.

§ty: Type

The property’s WGSL type.

§

Param

A parameter of an emitted fn — a name that is already in scope.

Fields

§name: &'static str

The parameter’s name in WGSL.

§ty: Type

The parameter’s WGSL type.

§

Assign

A statement: target = value.

Fields

§target: NodeRef

The assignment’s left-hand side.

§value: NodeRef

The assignment’s right-hand side.

§

Op

OperatorNode.

Fields

§op: &'static str

The WGSL operator, e.g. "+".

§a: NodeRef

The left operand.

§b: NodeRef

The right operand.

§ty: Type

The result’s WGSL type.

§

Math

MathNode — a WGSL builtin call.

Fields

§name: &'static str

The WGSL builtin’s name, e.g. "sin".

§args: Vec<NodeRef>

The call’s arguments.

§ty: Type

The result’s WGSL type.

§

Swizzle

SplitNode.

Fields

§node: NodeRef

The node being swizzled.

§components: &'static str

The swizzle mask, e.g. "xyz".

§ty: Type

The result’s WGSL type.

§

Cast

ConvertNode / a single-argument constructor: vec4<f32>( x ).

Fields

§node: NodeRef

The node being converted.

§ty: Type

The target WGSL type.

§

Neg

OperatorNode with one operand: ( - x ).

Fields

§node: NodeRef

The negated node.

§ty: Type

The result’s WGSL type.

§

Join

JoinNode — vec4<f32>( a, b, c, d ).

Fields

§args: Vec<NodeRef>

The joined components.

§ty: Type

The result’s WGSL type.

§

Element

ArrayElementNode: m[ 3u ], array< f32, 3 >( … )[ vertexIndex ].

Fields

§node: NodeRef

The array or vector being indexed.

§index: NodeRef

The element index.

§ty: Type

The element’s WGSL type.

§

Texture

TextureNode — a texture sample.

Fields

§texture: Rc<TextureSource>

The texture being sampled.

§uv: NodeRef

The sample coordinate.

§mode: SampleMode

How the texture is read.

§ty: Type

The result’s WGSL type.

§

TextureSize

TextureSizeNode — textureDimensions( t, level ), a vec2<u32>.

Fields

§texture: Rc<TextureSource>

The texture being measured.

§level: NodeRef

The mip level.

§

VaryingProperty

varyingProperty( type, name ) — a named varying assigned to by statement rather than built from a value. Unlike Node::Varying it is declared as soon as either stage mentions it, so a varying the fragment stage never reads still appears in VaryingsStruct, exactly as vBatchIndirectId does in Three’s dump.

Fields

§name: &'static str

The varying’s name in WGSL.

§ty: Type

The varying’s WGSL type.

§flat: bool

Whether the varying needs @interpolate(flat, either).

§

Call

A call into a Node::Code / inlined Fn().

Fields

§def: Rc<FnDef>

The function being called.

§args: Vec<NodeRef>

The call’s arguments.

§

Code(Rc<CodeDef>)

CodeNode itself — a wgslFn() as a node rather than as a call, which is the shape another wgslFn’s includes list needs it in. Building one emits its declaration into // codes and nothing else; it has no value, so nothing but an includes list may hold one.

§

CodeCall

FunctionCallNode over a wgslFn() — a call into hand-written WGSL the node system copies through verbatim. See crate::nodes::code.

Fields

§def: Rc<CodeDef>

The hand-written WGSL function being called.

§args: Vec<NodeRef>

The call’s arguments.

§

Block

A sequence of statements followed by the value they produce — the shape an inlined Fn() body with toVar() statements has. Three has no node for it: its ShaderNode call simply flows its body’s statements into the current stage and returns the last expression, which is what this does.

Fields

§statements: Vec<NodeRef>

The statements built ahead of result.

§result: NodeRef

The block’s value.

§

Loop

Loop( count, ( { i } ) => { … } ) — for ( var i : i32 = 0; i < n; i ++ ).

Fields

§start: Option<NodeRef>

Loop( { start, end }, … )‘s start. None is three.js’ Loop( count, … ) shorthand, whose start is the literal 0; a node start is written out as it stands, so webgpu_postprocessing_anamorphic’s negated half-sample count reaches the loop header as i32( ( - nodeVar1 ) ).

§count: NodeRef

Loop( { start, end }, … )’s end, or Loop( count, … )’s count — the loop’s exclusive upper bound.

§index: NodeRef

The loop index, as it appears inside body (Node::Param). Its type is Loop( { type } ): i32, or f32 for hashBlur’s type: 'float', which also changes the step to i += 1..

§condition: &'static str

Loop( { condition } ) — "<" unless the caller asked for another comparison (boxBlur’s "<=").

§update: Option<NodeRef>

Loop( { update } ) — i += update in place of the default step.

§body: Vec<NodeRef>

The loop body’s statements.

§

Break

Break() — a bare break; out of the innermost Loop.

§

Continue

Continue() — a bare continue; to the next iteration of the innermost Loop.

§

TextureStore

textureStore( storageTexture, coord, value ) — a statement.

StorageTextureNode.generateStore() writes the coordinate as vec2<u32>( … ) (vec3<u32> for a 3D texture) around whatever the caller passed, so a uvec2 coordinate is wrapped once more, exactly as three’s dump shows.

Fields

§texture: Rc<TextureSource>

The storage texture being written.

§coord: NodeRef

The texel coordinate.

§value: NodeRef

The value stored.

§

If

If( cond, () => { … } ) as a bare statement (setupDiscard), optionally with the .Else( … ) / .ElseIf( … ) arm StackNode adds.

ElseIf is not a shape of its own: StackNode.ElseIf() puts a whole nested If inside the else block, so If( a ).ElseIf( b ) is else_body: vec![ if_then( b, … ) ] and generates as a nested if/else, which is exactly what three emits.

Fields

§cond: NodeRef

The branch condition.

§body: Vec<NodeRef>

The if block’s statements.

§else_body: Vec<NodeRef>

Empty for a one-armed If, in which case no else is emitted and the generated text is byte-identical to what it was before the arm existed.

§

IfVar

If( cond, () => { … } ) — a one-armed conditional over a result var that was initialised before it. pre holds the statements three.js emits ahead of the result var (its toConst lines), result is the var itself and body the statements inside the block, the last of which assigns result. The node’s value is the result var.

Fields

§pre: Vec<NodeRef>

The statements built ahead of result.

§result: NodeRef

The initialised result variable.

§cond: NodeRef

The branch condition.

§body: Vec<NodeRef>

The block’s statements, the last of which assigns result.

§

Discard

Discard() — a bare discard;.

§

Return

return value; inside an emitted fn — what an If( cond, () => { return x; } ) in a Fn() body compiles to (neutralToneMapping’s early out).

Fields

§value: NodeRef

The returned value.

§

Not

x.not() — ( ! x ). A bool, or a bvecN for an N-vector operand (OperatorNode.getNodeType()’s '!' arm).

Fields

§node: NodeRef

The negated node.

§

BitNot

x.bitNot() — ( ~ x ), typed getIntegerType( typeA ).

Fields

§node: NodeRef

The negated node.

§ty: Type

The result’s WGSL type.

§

Select

cond.select( a, b ) — lowered to an if/else writing a result var, exactly as Three does.

Fields

§cond: NodeRef

The branch condition.

§a: NodeRef

The value when cond is true.

§b: NodeRef

The value when cond is false.

§ty: Type

The result’s WGSL type.

§

StructMember

storageStruct.get( 'member' ) — MemberNode on a BufferSource::Struct storage buffer: NodeBuffer_N.member.

Fields

§buffer: Rc<BufferNode>

The struct buffer.

§member: usize

The member’s index in the struct’s layout.

§

Atomic

AtomicFunctionNode — atomicStore( &pointer, value ) and the rest of the family. pointer is a struct member or buffer element declared atomic< T >. As a bare statement it is one atomicX( … ); line; read as a value as well, its result is held in a let first.

Fields

§method: &'static str

The WGSL atomic function’s name, e.g. "atomicAdd".

§pointer: NodeRef

The atomic value being operated on.

§value: Option<NodeRef>

The operand, when the method takes one.

§

Workgroup(Rc<WorkgroupArrayDef>)

WorkgroupInfoNode — the array itself. Read through Node::Element, which is how .element( i ) reaches it.

§

Barrier

BarrierNode — workgroupBarrier() / storageBarrier() / textureBarrier(), scope being the prefix.

Fields

§scope: &'static str

The barrier’s WGSL prefix, e.g. "workgroup".

§

Subgroup

SubgroupFunctionNode — subgroupAdd( e ), subgroupShuffle( e, id ), quadSwapX( e ) and the rest of the family (src/nodes/gpgpu/SubgroupFunctionNode.js). Reaching one enables subgroups in the stage that builds it.

Fields

§method: &'static str

The WGSL builtin’s name, e.g. "subgroupAdd" — three’s SubgroupFunctionNode.SUBGROUP_ADD and friends.

§a: Option<NodeRef>

aNode; None only for subgroupElect().

§b: Option<NodeRef>

bNode: the lane id, shuffle mask or delta of the two-input forms.

§

Custom(Rc<dyn CustomNode>)

A node type defined outside the crate; see CustomNode. Built by building what its setup returns.

§

Context

ContextNode — node.context( { … } ). Builds node with value’s keys merged into builder.context, and restores the previous context afterwards.

Fields

§node: NodeRef

The node built under the merged context.

§value: Rc<ContextValue>

The context entries merged in.

§

Isolate

IsolateNode — isolate( node ). Builds node in a NodeCache of its own, whose parent is the cache in force where the isolate is built: what node’s subgraph sets up, counts or declares for the first time stays inside it.

Fields

§node: NodeRef

The node built in its own cache.

§

Expression

ExpressionNode — expression( snippet, type ): raw WGSL. A value type prints snippet where the node is read; void writes it to the flow as a statement. Not cacheable: each read prints it again.

Fields

§snippet: Rc<str>

The WGSL, verbatim.

§ty: Type

Its type, Void for a statement.

§

Debug

DebugNode — debug( node, callback ): node’s snippet, passed through after callback (or a log of the flow so far) has seen it.

Fields

§node: NodeRef

The node debugged.

§callback: Option<DebugCallback>

null logs the stage’s flow code to stderr, as three’s log() does to the console.

§

StructNew

structType( values ) — StructNode: a value of a struct_type (StructTypeNode) built from one value per member, in member order. Always held in a var of the struct’s type, which is where three’s StructNode lands too (nodeVar31 = StructType0( … ) in the TRAA dump); its ty is Type::Void because the port’s Type has no struct case, and only Node::StructGet reads it.

Fields

§layout: Rc<StructLayout>

The struct’s layout.

§values: Vec<NodeRef>

One value per member.

§

OutputStruct

outputStruct( ...members ) — OutputStructNode, a fragment stage’s whole result as one @location( i ) member per value, each of its own type. It is only ever a material’s outputNode (DepthOfFieldNode’s CoC pass writes its near and far fields this way); the builder turns it into the OutputType struct and its output.mN = … lines, as it does an MrtNode’s members, and it has no value of its own.

Fields

§members: Vec<NodeRef>

The members, by location.

§

StructGet

structNode.get( name ) — MemberNode over a Node::StructNew (or over a block or Fn() whose result is one): { var }.{ member }.

Fields

§value: NodeRef

The struct value read.

§layout: Rc<StructLayout>

Its layout.

§member: usize

The member’s index in the layout.

Trait Implementations§

Source§

impl Debug for Node

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl !RefUnwindSafe for Node

§

impl !Send for Node

§

impl !Sync for Node

§

impl !UnwindSafe for Node

§

impl Freeze for Node

§

impl Unpin for Node

§

impl UnsafeUnpin for Node

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.