Tech/LxEngine/ShaderBuilder
From Athile
It may contain inaccurate, incorrect information. Use at your own risk.
This documentation is still under heavy construction. Documentation updates to address questions posted on the forum will be prioritized.
Overview
The ShaderBuilder is a system for dynamically generating a shader (and the parameters to that shader) from a JSON description of a shader graph. The ShaderBuilder is intended to work for multiple targets: e.g. GLSL as well as a native CPU ray-tracer.
The ShaderBuilder describes library only; it does not include any GUI for creating such shader graphs.
Contents |
Goal is for the shader graph compiler to be independent of LxEngine; such that other engines, following a minimal set of naming conventions (or possibly passing in a table of presets) can use the output shader source.
A Material is a hierarchy of parameters that describe how to render geometry.
- A shader program
- A set of parameters to that program
Internally, this set of parameters is parsed and mapped to shader and shader parameter pair. LxEngine will reuse the same shader program when possible.
The hierarchy of parameters creates a graph of connected nodes. These nodes have names which refer to "graph fragments".
Each node definition becomes a function. Each node in the graph becomes a call to a function. The result values are saved so they can be reused by multiple subsequent nodes. The tree is processed bottom-up.
Materials Library
Shading Nodes
solid
Returns the input "color" parameter directly. The default is gray.
Source: https://github.com/athile/lxengine/blob/master/lx0/dev/media/shaders/glsl/nodes/solid.node
phong
Source: https://github.com/athile/lxengine/blob/master/lx0/dev/media/shaders/glsl/nodes/phong.node
Pattern Nodes
checker
Source: https://github.com/athile/lxengine/blob/master/lx0/dev/media/shaders/glsl/nodes/checker.node
spot
Source: https://github.com/athile/lxengine/blob/master/lx0/dev/media/shaders/glsl/nodes/spot.node