Capítulo 610 de 859

Chapter 610: Transpiler

Core Idea

A class that transpiles shader code from one language into another.

Transpiler can only be used to convert GLSL into TSL right now. It is intended to support developers when they want to migrate their custom materials from the current to the new node-based material system.

Key Concepts

  • decoder : GLSLDecoder: The GLSL decoder. This component parse GLSL and produces a language-independent AST for further processing.
  • encoder : TSLEncoder: The TSL encoder. It takes the AST and emits TSL code.
  • linker : Linker: The linker. It processes the AST and resolves variable and function references, ensuring that all dependencies are properly linked.

Code Examples

import Transpiler from 'three/addons/transpiler/Transpiler.js';
  • What it demonstrates: Typical usage of Transpiler.

Reference Tables

Constructor

Signature
new Transpiler( decoder : GLSLDecoder, encoder : TSLEncoder )

Properties

PropertyDescription
.decoder : GLSLDecoderThe GLSL decoder. This component parse GLSL and produces a language-independent AST for further processing.
.encoder : TSLEncoderThe TSL encoder. It takes the AST and emits TSL code.
.linker : LinkerThe linker. It processes the AST and resolves variable and function references, ensuring that all dependencies are properly linked.

Methods

MethodDescription
.parse( source : string ) : stringParses the given GLSL source and returns TSL syntax.

Key Takeaways

  1. Most relevant properties: decoder, encoder, linker.
  2. Key methods: parse.

Connects To