rhodonite
    Preparing search index...

    Class ShaderGraphResolver

    ShaderGraphResolver is a class that resolves the shader node graph and generates shader code. It provides functionality to convert a graph of shader nodes into complete vertex and fragment shaders.

    Index

    Constructors

    Methods

    • Creates a complete fragment/pixel shader code from the given pixel nodes. This method performs topological sorting, generates function definitions, and constructs the main shader body for fragment processing.

      Parameters

      • engine: Engine

        The engine instance

      • pixelNodes: AbstractShaderNode[]

        Array of shader nodes that contribute to fragment processing

      • commonShaderPart: CommonShaderPart

        The CommonShaderPart instance for shader code generation

      Returns string | undefined

      Complete fragment shader code as a string, or undefined if generation fails

    • Creates a complete vertex shader code from the given vertex and varying nodes. This method performs topological sorting of nodes, generates function definitions, and constructs the main shader body with proper variable declarations and connections.

      Parameters

      • engine: Engine

        The engine instance

      • vertexNodes: AbstractShaderNode[]

        Array of shader nodes that contribute to vertex processing

      • varyingNodes: AbstractShaderNode[]

        Array of shader nodes that pass data from vertex to fragment stage

      • commonShaderPart: CommonShaderPart

        The CommonShaderPart instance for shader code generation

      Returns string | undefined

      Complete vertex shader code as a string, or undefined if generation fails

    • Generates complete vertex and fragment shader code from a JSON shader node graph definition. This is the main entry point for converting a serialized shader graph into executable shader code. The method performs the full pipeline: node construction, dependency resolution, stage assignment, and final code generation.

      Parameters

      • engine: Engine

        The engine instance

      • json: ShaderNodeJson

        JSON representation of the shader node graph containing nodes and connections

      • commonShaderPart: CommonShaderPart

        StandardShaderPart instance to use for shader code generation

      Returns
          | {
              pixelShader: string;
              textureInfos: { defaultTexture: string; name: string; stage: string }[];
              vertexShader: string;
          }
          | undefined

      Object containing both vertex and fragment shader code, texture names used, or undefined if generation fails

      const commonShaderPart = new StandardShaderPart();
      const shaderCode = ShaderGraphResolver.generateShaderCodeFromJson(engine, graphJson, commonShaderPart);
      if (shaderCode) {
      const { vertexShader, pixelShader, textureNames } = shaderCode;
      // Use the generated shaders...
      }