Class AbstractShaderNodeAbstract

AbstractShaderNode is an abstract class that represents a shader node in a node-based shader system. It provides the foundation for creating custom shader nodes with inputs, outputs, and connections.

Hierarchy (view full)

Constructors

  • Creates a new AbstractShaderNode instance.

    Parameters

    • shaderNodeName: string

      The name identifier for this shader node

    • shader: {
          codeGLSL?: string;
          codeWGSL?: string;
          commonPart?: CommonShaderPart;
      }

      The shader configuration object containing GLSL/WGSL code or common shader parts

      • OptionalcodeGLSL?: string

        Optional GLSL shader code for this node

      • OptionalcodeWGSL?: string

        Optional WGSL shader code for this node

      • OptionalcommonPart?: CommonShaderPart

        Optional common shader part containing reusable shader definitions

    Returns AbstractShaderNode

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 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

  • Retrieves the shader code for the specified shader stage. Returns appropriate code based on the current rendering approach (WebGL/WebGPU).

    Parameters

    • shaderStage: EnumIO

      The shader stage (vertex or fragment) to get code for

    Returns string

    The shader code string for the specified stage

  • Gets the derivative shader function name for this node. By default, returns the same as the regular function name.

    Returns string

    The derivative function name used in shader code

  • Retrieves a complete tag object (name and value) for the specified tag name

    Parameters

    • tagName: string

      The name of the tag to retrieve

    Returns Tag

    A Tag object containing the name and value

  • 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 a function call statement for this shader node in the final shader code. This method constructs the appropriate function call syntax with proper parameter passing for both WebGL and WebGPU rendering approaches.

    Parameters

    • i: number

      The index of this node in the execution order

    • shaderNode: AbstractShaderNode

      The shader node to generate the call for

    • functionName: string

      The name of the 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 function call statement string

  • 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

  • Retrieves an RnObject instance by its unique identifier

    Parameters

    • objectUid: number

      The unique identifier of the object to retrieve

    Returns undefined | RnObject

    The RnObject instance or undefined if not found or garbage collected

  • 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