# Internals of nodes

This page describes how nodes are created so that you can understand what goes on internally or to create new nodes yourself using GLSL. Given that Hology's Typescript shaders already has support for all GLSL features, you normally don't need to create your own nodes like this.&#x20;

#### Structure of a node implementation

The class name (NODE\_NAME) can be anything you want and the parent class (BASE\_TYPE) is usually one of the built in types like FloatNode, Vec3Node, etc.

```ts
export class NODE_NAME extends BASE_TYPE {
  // Other nodes can be passed into the constructor.
  constructor(private diffuseColor: RgbNode) {
    super();
  }
  public compile(c: Compiler) {
    // Generate an incrementing number to use in variables. It helps with creating unique variables and makes it easier to debug generated code. 
    const k = c.variable() 
    // Extract the output of an input. This can now be inserted in the GLSL code below. 
    const diffuseColor: string = c.get(this.diffuseColor)
    
    return {
        // Code that exist outside the main function such as uniforms, structs and functions. This is optional.
       pars: `

       `,
       // Code that exist inside the main function. This is optional as the `out` can contain an expression. 
       // However, to avoid reevaluating the expression every time, assign it to a variable here and just refer to the variable in `out`. 
       chunk: `
          vec3 color_${k} = ${diffuseColor};
       `,
       // `out` should be a GLSL expression, which usually is one variable defined in the `chunk` above.
       out: `color_${k}`
    }
  }
}
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.hology.app/zh-tw/shaders/typescript-shaders/internals-of-nodes.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
