Skip to content

Shader nodes

zeganstyl edited this page Sep 18, 2020 · 1 revision

Thelema hava ability to generate GLSL code from nodes.

Simple using of nodes:

val vertexNode = VertexNode()
vertexNode.aPositionName = "POSITION"

val cameraDataNode = CameraDataNode(vertexNode.position)

val outputNode = OutputNode(cameraDataNode.clipSpacePosition, vertexNode.position)

val shader = Shader()
shader.addNode(vertexNode)
shader.addNode(cameraDataNode)
shader.addNode(outputNode)
shader.build()

Here we define that in shader must be input attribute "POSITION" that will be used by vertex node as input vertex position attribute. Vertex node gives, transformed by world matrix, vertex output position vertexNode.position, which we can use in camera node. Camera node requires world space vertex position to apply view projection matrix and gives output cameraDataNode.clipSpacePosition. Clip space vertex position we can pass to output node. And finally output node will setup gl_Position and gl_FragColor.

After calling build, you can get generated GLSL source code with line numbers by calling shader.getSources(). After successful build, you can use the shader. If shader has errors, it will print errors to console.

You can look in shader.node package to see what nodes are available.

Some nodes have uniforms or other data that must be calculated and passed to shader in render loop at realtime. For this purpose there is methods in IShader: prepareToDrawMesh, prepareObjectData and prepareSceneData which are respectively called by objects: Mesh, Object3D and Scene. For example, camera uniforms are passed inside prepareSceneData, world matrix passed inside prepareObjectData and texture binding is done inside prepareToDrawMesh.

Simple vertex node test

Clone this wiki locally