Package com.jme3.shader
Class Glsl100ShaderGenerator
java.lang.Object
com.jme3.shader.ShaderGenerator
com.jme3.shader.Glsl100ShaderGenerator
- Direct Known Subclasses:
- Glsl150ShaderGenerator
This shader Generator can generate Vertex and Fragment shaders from
 shadernodes for GLSL 1.0
- 
Field SummaryFieldsFields inherited from class com.jme3.shader.ShaderGeneratorassetManager, indent, NAME_SPACE_GLOBAL, NAME_SPACE_MAT_PARAM, NAME_SPACE_VERTEX_ATTRIBUTE, NAME_SPACE_WORLD_PARAM, techniqueDef
- 
Constructor SummaryConstructorsConstructorDescriptionGlsl100ShaderGenerator(AssetManager assetManager) creates a Glsl100ShaderGenerator
- 
Method SummaryModifier and TypeMethodDescriptionprotected voidappendIndent(StringBuilder source) appends indentation.protected voidappendOutput(StringBuilder source, String globalOutputName, ShaderNodeVariable var) Appends an output assignment to a shader globalOutputName = nameSpace_varName;protected voidcomment(StringBuilder source, ShaderNode shaderNode, String comment) Appends a comment to the generated codeprotected voiddeclareAttribute(StringBuilder source, ShaderNodeVariable var) Declares an attributeprotected voiddeclareGlobalPosition(ShaderGenerationInfo info, StringBuilder source) declare and assign the global position in the vertex shader.protected voiddeclareVariable(StringBuilder source, ShaderNodeVariable var) declares a variable, embed in a conditional block if needed.protected voiddeclareVariable(StringBuilder source, ShaderNodeVariable var, boolean appendNameSpace) declares a variable, embed in a conditional block if neededprotected voiddeclareVariable(StringBuilder source, ShaderNodeVariable var, boolean appendNameSpace, String modifier) declares a variable, embed in a conditional block if needed.protected voiddeclareVariable(StringBuilder source, ShaderNodeVariable var, String value) declares a variable, embed in a conditional block if needed.protected voiddeclareVariable(StringBuilder source, ShaderNodeVariable var, String value, boolean appendNameSpace, String modifier) declares a variable, embed in a conditional block if needed.protected voiddeclareVarying(StringBuilder source, ShaderNodeVariable var, boolean input) Declares a varyingprotected voidendCondition(String condition, StringBuilder source) Ends a conditional blockprotected voidmakes sure inPosition attribute is of type vec3 or vec4protected voidgenerateAttributes(StringBuilder source, ShaderGenerationInfo info) generates the attributes declaration for the vertex shader.protected voidgenerateDeclarativeSection(StringBuilder source, ShaderNode shaderNode, String nodeSource, ShaderGenerationInfo info) Appends the given shaderNode declarative part to the shader declarative part.protected voidgenerateEndOfMainSection(StringBuilder source, ShaderGenerationInfo info, Shader.ShaderType type) Generates the end of the shader main section.protected voidgenerateNodeMainSection(StringBuilder source, ShaderNode shaderNode, String nodeSource, ShaderGenerationInfo info) Appends the given shaderNode main part to the shader declarative part.protected voidgenerateStartOfMainSection(StringBuilder source, ShaderGenerationInfo info, Shader.ShaderType type) generates the start of the shader main section.protected voidgenerateUniforms(StringBuilder source, ShaderGenerationInfo info, Shader.ShaderType type) generates the uniforms declaration for a shader of the given type.protected voidgenerateUniforms(StringBuilder source, List<ShaderNodeVariable> uniforms) declare a list of uniformsprotected voidgenerateVaryings(StringBuilder source, ShaderGenerationInfo info, Shader.ShaderType type) generates the varyings for the given shader type shader.protected Stringreturns the name space to append for a variable.protected Stringreturns the language + version of the shader should be something like "GLSL100" for glsl 1.0 "GLSL150" for glsl 1.5.protected voidindent()increase indentation with a check so that indentation is never over 10protected booleanFinds if a variable is a varyingprotected booleanFinds if a variable is a world or a material parameterprotected voidmap(VariableMapping mapping, StringBuilder source, boolean declare) Appends a mapping to the source, embed in a conditional block if needed, with variables nameSpaces and swizzle.protected Stringreplace(String nodeSource, ShaderNodeVariable var, String newName) replaced a variable name in a source code with the given nameprotected StringreplaceVariableName(String nodeSource, ShaderNodeVariable var) replaces a variable name in a shaderNode source code by prefixing it with its nameSpace and "_" if needed.protected voidstartCondition(String condition, StringBuilder source) Starts a conditional blockprotected voidunIndent()Decrease indentation with a check so the indent is never negative.protected StringupdateDefinesName(String nodeSource, ShaderNode shaderNode) transforms defines name is the shader node code.Methods inherited from class com.jme3.shader.ShaderGeneratorappendNodeDeclarationAndMain, buildShader, findShaderIndexFromVersion, generateDeclarationAndMainBody, generateShader, initialize
- 
Field Details- 
inPosTmp
 
- 
- 
Constructor Details- 
Glsl100ShaderGeneratorcreates a Glsl100ShaderGenerator- Parameters:
- assetManager- the assetManager
 
 
- 
- 
Method Details- 
generateUniformsprotected void generateUniforms(StringBuilder source, ShaderGenerationInfo info, Shader.ShaderType type) Description copied from class:ShaderGeneratorgenerates the uniforms declaration for a shader of the given type.- Specified by:
- generateUniformsin class- ShaderGenerator
- Parameters:
- source- the source StringBuilder to append generated code.
- info- the ShaderGenerationInfo.
- type- the shader type the uniforms have to be generated for.
 
- 
generateUniformsdeclare a list of uniforms- Parameters:
- source- the source to append to
- uniforms- the list of uniforms
 
- 
generateAttributesgenerates the attributes declaration for the vertex shader. There is no Shader type passed here as attributes are only used in vertex shaders attributes are all declared, inPosition is declared even if it's not in the list and its condition is nulled.- Specified by:
- generateAttributesin class- ShaderGenerator
- Parameters:
- source- the source StringBuilder to append generated code.
- info- the ShaderGenerationInfo.
 
- 
generateVaryingsprotected void generateVaryings(StringBuilder source, ShaderGenerationInfo info, Shader.ShaderType type) Description copied from class:ShaderGeneratorgenerates the varyings for the given shader type shader. Note that varyings are deprecated in glsl 1.3, but this method will still be called to generate all non-global inputs and output of the shaders.- Specified by:
- generateVaryingsin class- ShaderGenerator
- Parameters:
- source- the source StringBuilder to append generated code.
- info- the ShaderGenerationInfo.
- type- the shader type the varyings have to be generated for.
 
- 
generateDeclarativeSectionprotected void generateDeclarativeSection(StringBuilder source, ShaderNode shaderNode, String nodeSource, ShaderGenerationInfo info) Appends the given shaderNode declarative part to the shader declarative part. If needed the shader type can be determined by fetching the shaderNode's definition type. if the declaration contains no code nothing is done, else it's appended- Specified by:
- generateDeclarativeSectionin class- ShaderGenerator
- Parameters:
- source- the StringBuilder to append generated code.
- shaderNode- the shaderNode.
- nodeSource- the declaration part of the node
- info- the ShaderGenerationInfo.
- See Also:
 
- 
generateStartOfMainSectionprotected void generateStartOfMainSection(StringBuilder source, ShaderGenerationInfo info, Shader.ShaderType type) generates the start of the shader main section. this method is responsible of appending the "void main(){" in the shader and declaring all global outputs of the shader Shader outputs are declared and initialized inside the main section- Specified by:
- generateStartOfMainSectionin class- ShaderGenerator
- Parameters:
- source- the StringBuilder to append generated code.
- info- the ShaderGenerationInfo.
- type- the shader type the section has to be generated for.
 
- 
generateEndOfMainSectionprotected void generateEndOfMainSection(StringBuilder source, ShaderGenerationInfo info, Shader.ShaderType type) Generates the end of the shader main section. This method is responsible for appending the last "}" in the shader and mapping all global outputs of the shader. outputs are assigned to built in glsl output. then the main section is closed This code accounts for multi render target and correctly output to gl_FragData if several output are declared for the fragment shader- Specified by:
- generateEndOfMainSectionin class- ShaderGenerator
- Parameters:
- source- the StringBuilder to append generated code.
- info- the ShaderGenerationInfo.
- type- the shader type the section has to be generated for.
 
- 
appendOutputAppends an output assignment to a shader globalOutputName = nameSpace_varName;- Parameters:
- source- the source StringBuilder to append the code.
- globalOutputName- the name of the global output (can be gl_Position or gl_FragColor etc...).
- var- the variable to assign to the output.
 
- 
generateNodeMainSectionprotected void generateNodeMainSection(StringBuilder source, ShaderNode shaderNode, String nodeSource, ShaderGenerationInfo info) Appends the given shaderNode main part to the shader declarative part. If needed the shader type can be determined by fetching the shaderNode's definition type. This method does things in the following order: 1. declaring and mapping input
 variables : variable replaced with MatParams or WorldParams that are Samplers are not declared and are replaced by the param actual name in the code. For others variables, the name space is appended with a "_" before the variable name in the code to avoid names collision between shaderNodes.
 2. declaring output variables :
 variables are declared if they were not already declared as input (inputs can also be outputs) or if they are not declared as varyings. The variable name is also prefixed with the s=name space and "_" in the shaderNode code
 3. append of the actual ShaderNode code
 4. mapping outputs to global output if needed
 
 All of this is embedded in a #if conditional statement if necessary.- Specified by:
- generateNodeMainSectionin class- ShaderGenerator
- Parameters:
- source- the StringBuilder to append generated code.
- shaderNode- the shaderNode.
- nodeSource- the declaration part of the loaded shaderNode source.
- info- the ShaderGenerationInfo.
- See Also:
 
- 
declareVariableprotected void declareVariable(StringBuilder source, ShaderNodeVariable var, boolean appendNameSpace) declares a variable, embed in a conditional block if needed- Parameters:
- source- the StringBuilder to use
- var- the variable to declare
- appendNameSpace- true to append the nameSpace + "_"
 
- 
declareVariabledeclares a variable, embed in a conditional block if needed. the namespace is appended with "_"- Parameters:
- source- the StringBuilder to use
- var- the variable to declare
 
- 
declareVariabledeclares a variable, embed in a conditional block if needed. the namespace is appended with "_"- Parameters:
- source- the StringBuilder to use
- var- the variable to declare
- value- the initialization value to assign the variable
 
- 
declareVariableprotected void declareVariable(StringBuilder source, ShaderNodeVariable var, boolean appendNameSpace, String modifier) declares a variable, embed in a conditional block if needed.- Parameters:
- source- the StringBuilder to use
- var- the variable to declare
- appendNameSpace- true to append the nameSpace + "_"
- modifier- the modifier of the variable (attribute, varying, in , out,...)
 
- 
declareVariableprotected void declareVariable(StringBuilder source, ShaderNodeVariable var, String value, boolean appendNameSpace, String modifier) declares a variable, embed in a conditional block if needed.- Parameters:
- source- the StringBuilder to use
- var- the variable to declare
- value- the initialization value to assign the variable
- appendNameSpace- true to append the nameSpace + "_"
- modifier- the modifier of the variable (attribute, varying, in , out,...)
 
- 
startConditionStarts a conditional block- Parameters:
- condition- the block condition
- source- the StringBuilder to use
 
- 
endConditionEnds a conditional block- Parameters:
- condition- the block condition
- source- the StringBuilder to use
 
- 
mapAppends a mapping to the source, embed in a conditional block if needed, with variables nameSpaces and swizzle.- Parameters:
- mapping- the VariableMapping to append
- source- the StringBuilder to use
- declare- true to declare the variable, false if already declared
 
- 
replaceVariableNamereplaces a variable name in a shaderNode source code by prefixing it with its nameSpace and "_" if needed.- Parameters:
- nodeSource- the source to modify
- var- the variable to replace
- Returns:
- the modified source
 
- 
isVaryingFinds if a variable is a varying- Parameters:
- info- the ShaderGenerationInfo
- v- the variable
- Returns:
- true is the given variable is a varying
 
- 
commentAppends a comment to the generated code- Parameters:
- source- the StringBuilder to use
- shaderNode- the shader node being processed (to append its name)
- comment- the comment to append
 
- 
getAppendableNameSpacereturns the name space to append for a variable. Attributes, WorldParam and MatParam names space must not be appended- Parameters:
- var- the variable
- Returns:
- the namespace to append for this variable
 
- 
updateDefinesNametransforms defines name is the shader node code. One can use a #if defined(inputVariableName) in a shaderNode code. This method is responsible for changing the variable name with the appropriate defined based on the mapping condition of this variable. Complex condition syntax are handled.- Parameters:
- nodeSource- the shaderNode source code
- shaderNode- the ShaderNode being processed
- Returns:
- the modified shaderNode source.
 
- 
replacereplaced a variable name in a source code with the given name- Parameters:
- nodeSource- the source to use
- var- the variable
- newName- the new name of the variable
- Returns:
- the modified source code
 
- 
isWorldOrMaterialParamFinds if a variable is a world or a material parameter- Parameters:
- var- the variable
- Returns:
- true if the variable is a Word or material parameter
 
- 
getLanguageAndVersionDescription copied from class:ShaderGeneratorreturns the language + version of the shader should be something like "GLSL100" for glsl 1.0 "GLSL150" for glsl 1.5.- Specified by:
- getLanguageAndVersionin class- ShaderGenerator
- Parameters:
- type- the shader type for which the version should be returned.
- Returns:
- the shaderLanguage and version.
 
- 
appendIndentappends indentation.- Parameters:
- source- the builder to append to
 
- 
declareAttributeDeclares an attribute- Parameters:
- source- the StringBuilder to use
- var- the variable to declare as an attribute
 
- 
declareVaryingDeclares a varying- Parameters:
- source- the StringBuilder to use
- var- the variable to declare as a varying
- input- a boolean set to true if the varying is an input. This in not used in this implementation, but can be used in overriding implementations.
 
- 
unIndentprotected void unIndent()Decrease indentation with a check so the indent is never negative.
- 
indentprotected void indent()increase indentation with a check so that indentation is never over 10
- 
fixInPositionTypemakes sure inPosition attribute is of type vec3 or vec4- Parameters:
- var- the inPosition attribute
 
- 
declareGlobalPositiondeclare and assign the global position in the vertex shader.- Parameters:
- info- the shader generation info
- source- the shader source being generated
 
 
-