Back to Nexara

Shader scripting

Material node graphs that compile to GLSL for the pixel and vertex stages.

The Liquid Gold material graph in the Nexara Shader Editor, with Map Range, Math and Vector Math nodes.

Each material is a node graph. glsl_compiler.cpp follows the graph from the Material Output node and writes GLSL.

Compiling a graph

Stages: the compiler generates code for the pixel shader, and a separate pass generates nx_world_offset() for the vertex shader from the World Position Offset input. Nodes that need derivatives are not available in the vertex stage.

Inputs: each input socket compiles to its link, its typed value, or a default. An unlinked Normal uses the surface normal and an unlinked Vector uses the UV, as in Blender. An unlinked Time uses scene time, as in Unreal.

Order: a node's inputs compile first, because they can emit other nodes.

Muted nodes: a muted node passes its first matching input to its output, or outputs defaults.

Groups: a group node compiles its inner graph in a new scope, and group inputs read from the parent graph.

Parameters and instances

Texture parameters take the first sampler slots, which lets material instances swap images. The Liquid Gold material in the screenshot has Metal Color, Flow Speed and Wobble as parameters. Two Noise Texture nodes read World Position and Time. One connects to Bump for the surface normal and one connects to Roughness through Map Range. Vertex Normal and Vector Math connect the wobble to World Position Offset.

Viewing the result

Material Preview lights the compiled shader with a studio rig, using GGX specular and sky and ground ambient. Materials can also set a blend mode, backface culling and a tessellation level, and the viewport has separate tessellation shaders for that.