Typescript shaders

With Hology Engine, you can write your shaders directly in Typescript, the same programming languages as the rest of your game play code. You can express any logic that you can do in a lower level language as GLSL while enjoying the benefits of using a higher level language like Typescript.

Internally, typescript code will build up a graph of nodes representing the calculations, which explains the use of the word node. These nodes are then converted to the code that is compiled to run on the GPU so it has no negative effect on performance.

See Creating shaders for how to create a new Typescript shaders that can be used to create materials in the editor.

You can also use this shader library to create shaders for materials that are created directly in code instead of in the editor.

import { rgb, standardMaterial, translateY, sin, float, NodeShaderMaterial, timeUniforms } from "@hology/core/shader-nodes"
import { SphereGeometry, Mesh } from "three"


const time = timeUniforms.elapsed
const diffuse = rgb(0x00ff00)
const color = standardMaterial({ color: diffuse })
const bounce = translateY(sin(time.multiply(float(5))))

const material = new NodeShaderMaterial({
  color,
  transform: bounce
})

const sphere = new SphereGeometry(5, 30, 15)
const mesh = new Mesh(sphere, material)

Last updated