Class ShaderEmitter
Prints ShaderNode graphs as statements of one shading language. This is
the part of a backend's shader generator that custom materials need;
applications do not call it.
A backend creates one emitter per shader stage, calls emit for each hook
it splices in, and uses the returned expression where the engine's own
value would have gone. Every node that is not a constant or an input
becomes one temporary, so a node shared by several hooks is computed once.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enumThe shading languages a graph prints as.static interfaceSupplies the backend's spelling of the inputs a graph reads. -
Constructor Summary
ConstructorsConstructorDescriptionShaderEmitter(ShaderEmitter.Dialect dialect, ShaderMaterial material, ShaderEmitter.Inputs inputs, StringBuilder out, String indent, String prefix) Creates an emitter that appends statements toout. -
Method Summary
Modifier and TypeMethodDescriptionstatic voiddescribe(ShaderNode root, StringBuilder sb) Appends a structural description of a graph: equal for two graphs that print the same program.emit(ShaderNode node) Declares whatever temporariesnodeneeds and returns the expression that holds its value.static Stringliteral(float v) Returns a float literal every dialect reads the same way.static StringReturns a dialect's name of a type.Returns the dialect's name of a type.static booleanuses(ShaderMaterial material, boolean fragment, String builtin) Returns true if any hook of the given stage reads the built-in input.static booleanuses(ShaderMaterial material, String builtin) Returns true if any hook of either stage reads the built-in input.
-
Constructor Details
-
ShaderEmitter
public ShaderEmitter(ShaderEmitter.Dialect dialect, ShaderMaterial material, ShaderEmitter.Inputs inputs, StringBuilder out, String indent, String prefix) Creates an emitter that appends statements to
out.Parameters
-
dialect: the language to print -
material: the material whose uniforms and textures the graphs read -
inputs: the backend's spelling of the inputs -
out: where the temporaries are declared -
indent: the indentation of each statement -
prefix: a prefix for temporary names, distinct per stage
-
-
-
Method Details
-
emit
Declares whatever temporaries
nodeneeds and returns the expression that holds its value.Parameters
node: the graph
Returns
an expression of the node's type
-
literal
Returns a float literal every dialect reads the same way.
Parameters
v: a finite value
Returns
the literal
-
typeName
Returns the dialect's name of a type.
Parameters
t: the type
Returns
the type name
-
typeName
Returns a dialect's name of a type.
Parameters
-
d: the dialect -
t: the type
Returns
the type name
-
-
uses
Returns true if any hook of the given stage reads the built-in input.
Parameters
-
material: the material, or null -
fragment: true for the fragment stage -
builtin: the built-in's name, such asworldPos
Returns
true if it is read
-
-
uses
Returns true if any hook of either stage reads the built-in input.
Parameters
-
material: the material, or null -
builtin: the built-in's name
Returns
true if it is read
-
-
describe
Appends a structural description of a graph: equal for two graphs that print the same program. Shared nodes are written once and then referred to by number.
Parameters
-
root: the graph -
sb: where to append
-
-