Class MergeVectorShaderNode

A shader node that merges vector components to create various vector outputs.

This node provides the capability to combine individual scalar components (x, y, z, w) or smaller vectors (xy, zw, xyz) into larger vector outputs (Vec2, Vec3, Vec4). It supports multiple input configurations and automatically selects the appropriate shader function based on which inputs are connected.

const mergeNode = new MergeVectorShaderNode();
// Connect scalar inputs x, y, z, w to create a Vec4 output
// Or connect Vec3 xyz and scalar w to create a Vec4 output

Hierarchy (view full)

Constructors

Properties

__commonPart?: CommonShaderPart
__inputConnections: ShaderNodeInputConnectionType[] = []
__inputs: Socket<string, CompositionTypeEnum, ComponentTypeEnum, SocketDefaultValue>[] = []
__outputs: Socket<string, CompositionTypeEnum, ComponentTypeEnum, SocketDefaultValue>[] = []
__shaderFunctionName: string
__shaderNodeUid: number
_tags: RnTags = {}

Collection of tags associated with this object

InvalidObjectUID: -1 = -1

Invalid object UID constant

_shaderNodes: AbstractShaderNode[] = []
currentMaxObjectCount: number = 0

Current maximum object count for UID generation

Accessors

  • get inputConnections(): ShaderNodeInputConnectionType[]
  • Gets all input connections for this node.

    Returns ShaderNodeInputConnectionType[]

    An array of input connection configurations

  • get objectUID(): number
  • Gets the unique object identifier

    Returns number

    The object's UID

  • get uniqueName(): string
  • Gets the unique name of this object

    Returns string

    The unique name string

Methods

  • Adds an input connection to this node from another shader node. This establishes a data flow connection between the output of one node and the input of this node.

    Type Parameters

    Parameters

    • inputShaderNode: AbstractShaderNode

      The source shader node to connect from

    • outputSocketOfInput: Socket<string, N, T, SocketDefaultValue>

      The output socket of the source node

    • inputSocketOfThis: Socket<string, N, T, SocketDefaultValue>

      The input socket of this node to connect to

    Returns void

  • Determines the appropriate shader function name based on connected inputs.

    This method analyzes which input connections are active and returns the corresponding shader function variant. Each combination of inputs requires a different shader function implementation to handle the vector merging logic.

    Supported input combinations:

    • XYZ + W: Vec3 input with scalar W component
    • XY + ZW: Two Vec2 inputs for XY and ZW components
    • XY + Z + W: Vec2 input with individual Z and W scalars
    • ZW + X + Y: Vec2 input with individual X and Y scalars
    • X + Y + Z + W: Four individual scalar components

    Returns string

    The derivative function name suffix for the shader

    When the input connection pattern is not supported

  • Retrieves the value associated with a specific tag name

    Parameters

    • tagName: string

      The name of the tag whose value to retrieve

    Returns any

    The tag value, or undefined if the tag doesn't exist

  • Checks whether this object has a tag with the specified name

    Parameters

    • tagName: string

      The name of the tag to check for

    Returns boolean

    True if the tag exists (value is not null/undefined), false otherwise

  • Generates the shader function call statement for the merge vector operation.

    This method creates the appropriate shader code to call the merge vector function with the correct input and output parameters. It handles both WebGL (GLSL) and WebGPU (WGSL) syntax differences and manages dummy variables for unused outputs.

    The method generates dummy output variables for each possible output (xyzw, xyz, xy, zw) and replaces them with actual output variable names when they are used. This ensures that the shader function signature remains consistent regardless of which outputs are actually connected.

    Parameters

    • i: number

      The node index in the shader graph

    • shaderNode: AbstractShaderNode

      The shader node instance (typically this node)

    • functionName: string

      The name of the shader function to call

    • varInputNames: string[][]

      Array of input variable names for each node

    • varOutputNames: string[][]

      Array of output variable names for each node

    Returns string

    The generated shader code string for the function call

  • Checks if this object has a tag with the specified name and value

    Parameters

    • tagName: string

      The tag name to match

    • tagValue: string

      The tag value to match

    Returns boolean

    True if the object has a matching tag, false otherwise

  • Checks if this object has all the specified tags with exactly matching values

    Parameters

    • tags: RnTags

      Object containing tag names as keys and expected values

    Returns boolean

    True if all specified tags exist with matching values, false otherwise

  • Checks if the object's combined tag string contains all the provided search strings. This allows for flexible searching within tag names and values.

    Parameters

    • stringArray: string[]

      Array of strings that must all be present in the combined tag string

    Returns boolean

    True if all strings are found in the combined tag string, false otherwise

  • Attempts to set a tag on this object. If the tag already exists, it will be replaced.

    Parameters

    • tag: Tag

      The tag object containing the name and value to set

    Returns boolean

    True if the tag was successfully set, false if the tag name contains invalid characters

  • Attempts to set a unique name for this object

    Parameters

    • name: string

      The desired unique name

    • toAddNameIfConflict: boolean

      If true, appends UID to make name unique when conflicts occur; if false, fails on conflict

    Returns boolean

    True if the name was successfully set, false if there was a conflict and toAddNameIfConflict was false

  • Validates that a tag string contains only allowed characters (alphanumeric and underscore)

    Parameters

    • val: string

      The string to validate

    Returns boolean

    True if the string contains only valid characters, false if it contains invalid characters

  • Searches for the first object that has a specific tag with the given value

    Parameters

    • tag: string

      The tag name to search for

    • value: string

      The tag value to match

    Returns undefined | WeakRef<RnObject>

    WeakRef to the first matching object, or undefined if not found