Package com.jme3.material.plugins
Class ShaderNodeLoaderDelegate
java.lang.Object
com.jme3.material.plugins.ShaderNodeLoaderDelegate
This class is here to be able to load shaderNodeDefinition from both the
J3MLoader and ShaderNodeDefinitionLoader.
It also allows loading shader nodes from a j3md file and building the
ShaderNodes list of each technique and the ShaderGenerationInfo needed to
generate shaders.
-
Nested Class Summary
Nested Classes -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected AssetManagerprotected Map<String,ShaderNodeLoaderDelegate.DeclaredVariable> protected ConditionParserprotected Map<String,ShaderNodeLoaderDelegate.DeclaredVariable> protected MaterialDefprotected Map<String,ShaderNodeDefinition> protected Map<String,ShaderNode> protected Stringprotected Stringprotected ShaderNodeprotected ShaderNodeDefinitionprotected TechniqueDefprotected Map<String,ShaderNodeLoaderDelegate.DeclaredVariable> protected Map<String,ShaderNodeLoaderDelegate.DeclaredVariable> -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidAdds a define to the technique defprotected voidcheckMappingFormat(String[] vars, Statement statement) Checks if once a mapping expression is split by "=" the resulting array have 2 elements.protected voidcheckTypes(VariableMapping mapping, Statement statement1) check the types of a mapping, left type must match right type take the swizzle into accountvoidclear()voidextractCondition(String condition, Statement statement) Extracts and checks a condition expression.findDefinition(Statement statement) Find the definition from this statement (loads it if necessary)protected MatParamfindMatParam(String varName) Finds aMatParamin theMaterialDeffrom the given name.findNodeOutput(List<ShaderNodeVariable> vars, String rightVarName) Finds a variable with the given name from the list of variable.protected UniformBindingfindWorldParam(String varName) finds an UniformBinding representing a WorldParam from the techniqueDeffixSamplerType(String leftType, String rightType) retrieve the leftType corresponding sampler type from the rightTypemergeConditions(String condition1, String condition2, String operator) Merges 2 conditions with the given operatorprotected VariableMappingparseMapping(Statement statement, boolean[] hasNameSpace) Reads a mapping statement.voidreadFragmentShaderNodes(List<Statement> statements) reads the FragmentShaderNodes{} blockreadInputMapping(Statement statement) Reads an input mapping.voidReads a list of ShaderNodesvoidreadNodesDefinitions(List<Statement> statements) Read the ShaderNodesDefinitions block and internally stores a map of ShaderNodesDefinition This method is used by the j3m loader.readNodesDefinitions(List<Statement> statements, ShaderNodeDefinitionKey key) Read the ShaderNodesDefinitions block and returns a list of ShaderNodesDefinition This method is used by the j3sn loader note that the order of the definitions in the list is not guaranteed.readOutputMapping(Statement statement) Reads an output mapping.protected voidreadShaderNode(List<Statement> statements) reads a list of ShaderNode{} blocksprotected voidreadShaderNodeDefinition(List<Statement> statements, ShaderNodeDefinitionKey key) effectively reads the ShaderNodesDefinitions blockprotected voidreadShaderStatement(Statement statement) Reads a Shader statement of the form TYPE LANG : SOURCEprotected ShaderNodeVariablereadVariable(Statement statement) reads a variable declaration statement <glslType> <varName>voidreadVertexShaderNodes(List<Statement> statements) reads the VertexShaderNodes{} blockvoidsetAssetManager(AssetManager assetManager) sets the assetManagervoidsetMaterialDef(MaterialDef materialDef) sets the material def currently being loadedvoidsetTechniqueDef(TechniqueDef techniqueDef) Sets the technique definition currently being loadedvoidStores an attribute.voidstore a fragment uniformvoidstoreGlobal(ShaderNodeVariable var, Statement varStatement) Stores a global output.voidstoreVariable(ShaderNodeVariable variable, List<ShaderNodeVariable> varList) Searches a variable in a list from its name and merges the conditions of the variables.voidstoreVaryings(ShaderNode node, ShaderNodeVariable variable) store a varyingvoidStores a vertex uniform.booleanupdateRightFromUniforms(MatParam param, VariableMapping mapping, Map<String, ShaderNodeLoaderDelegate.DeclaredVariable> map, Statement statement) Updates the right variable of the given mapping from aMatParam(a WorldParam) it checks if the uniform hasn't already been loaded, add it to the maps if not.protected booleanupdateRightFromUniforms(UniformBinding param, VariableMapping mapping, Map<String, ShaderNodeLoaderDelegate.DeclaredVariable> map) updates the right variable of the given mapping from a UniformBinding (a WorldParam) it checks if the uniform hasn't already been loaded, add it to the maps if not.protected voidUpdates the type of the right variable of a mapping from the type of the left variable.voidupdateVarFromAttributes(ShaderNodeVariable right, VariableMapping mapping) Updates a variable from the attribute list.protected booleanSearches a variable in the given list and updates its type and namespace.
-
Field Details
-
nodeDefinitions
-
nodes
-
shaderNodeDefinition
-
shaderNode
-
techniqueDef
-
attributes
-
vertexDeclaredUniforms
-
fragmentDeclaredUniforms
-
varyings
-
materialDef
-
shaderLanguage
-
shaderName
-
varNames
-
assetManager
-
conditionParser
-
nulledConditions
-
-
Constructor Details
-
ShaderNodeLoaderDelegate
public ShaderNodeLoaderDelegate()
-
-
Method Details
-
readNodesDefinitions
public List<ShaderNodeDefinition> readNodesDefinitions(List<Statement> statements, ShaderNodeDefinitionKey key) throws IOException Read the ShaderNodesDefinitions block and returns a list of ShaderNodesDefinition This method is used by the j3sn loader note that the order of the definitions in the list is not guaranteed.- Parameters:
statements- the list statements to parsekey- the ShaderNodeDefinitionKey- Returns:
- a list of ShaderNodesDefinition
- Throws:
IOException- if an I/O error occurs
-
readNodesDefinitions
Read the ShaderNodesDefinitions block and internally stores a map of ShaderNodesDefinition This method is used by the j3m loader. When loaded in a material, the definitions are not stored as a list, but they are stored in shader nodes based on this definition. The map is here to map the definition to the nodes, and ovoid reloading already loaded definitions- Parameters:
statements- the list of statements to parse- Throws:
IOException- if an I/O error occurs
-
readShaderNodeDefinition
protected void readShaderNodeDefinition(List<Statement> statements, ShaderNodeDefinitionKey key) throws IOException effectively reads the ShaderNodesDefinitions block- Parameters:
statements- the list of statements to parsekey- the ShaderNodeDefinitionKey- Throws:
IOException- if an I/O error occurs
-
readVariable
reads a variable declaration statement <glslType> <varName>- Parameters:
statement- the statement to parse- Returns:
- a ShaderNodeVariable extracted from the statement
- Throws:
IOException- if an I/O error occurs
-
readVertexShaderNodes
reads the VertexShaderNodes{} block- Parameters:
statements- the list of statements to parse- Throws:
IOException- if an I/O error occurs
-
readShaderNode
reads a list of ShaderNode{} blocks- Parameters:
statements- the list of statements to parse- Throws:
IOException- if an I/O error occurs
-
parseMapping
protected VariableMapping parseMapping(Statement statement, boolean[] hasNameSpace) throws MatParseException Reads a mapping statement. Sets the nameSpace, name and swizzling of the left variable. Sets the name, nameSpace and swizzling of the right variable types will be determined later. Also, we can have the right part as expression.Format variable to variable: <nameSpace>.<varName>[.<swizzling>] = <nameSpace>.<varName>[.<swizzling>][:Condition] Format expression to variable: <nameSpace>.<varName>[.<swizzling>] = %% expression %% [:Condition]
- Parameters:
statement- the statement to read.hasNameSpace- indicate which vars have namespaces- Returns:
- the read mapping.
- Throws:
MatParseException- if the statement isn't valid.
-
readFragmentShaderNodes
reads the FragmentShaderNodes{} block- Parameters:
statements- the list of statements to parse- Throws:
IOException- if an I/O error occurs
-
readShaderStatement
Reads a Shader statement of the form TYPE LANG : SOURCE- Parameters:
statement- the shader statement (not null)- Throws:
IOException- if an I/O error occurs
-
setTechniqueDef
Sets the technique definition currently being loaded- Parameters:
techniqueDef- the technique def
-
setMaterialDef
sets the material def currently being loaded- Parameters:
materialDef- (alias created)
-
updateVariableFromList
Searches a variable in the given list and updates its type and namespace.- Parameters:
var- the variable to update.list- the variables list.- Returns:
- true if the variable has been found and updated.
-
updateRightTypeFromLeftType
Updates the type of the right variable of a mapping from the type of the left variable.- Parameters:
mapping- the mapping to consider.
-
checkMappingFormat
Checks if once a mapping expression is split by "=" the resulting array have 2 elements.- Parameters:
vars- the array.statement- the statement.- Throws:
MatParseException- if the array isn't correct.
-
findMatParam
Finds aMatParamin theMaterialDeffrom the given name.- Parameters:
varName- the material param name.- Returns:
- the found
MatParamor null.
-
findWorldParam
finds an UniformBinding representing a WorldParam from the techniqueDef- Parameters:
varName- the name of the WorldParam- Returns:
- the corresponding UniformBinding to the WorldParam
-
updateRightFromUniforms
protected boolean updateRightFromUniforms(UniformBinding param, VariableMapping mapping, Map<String, ShaderNodeLoaderDelegate.DeclaredVariable> map) updates the right variable of the given mapping from a UniformBinding (a WorldParam) it checks if the uniform hasn't already been loaded, add it to the maps if not.- Parameters:
param- the WorldParam UniformBindingmapping- the mappingmap- the map of uniforms to search into- Returns:
- true if the param was added to the map
-
updateRightFromUniforms
public boolean updateRightFromUniforms(MatParam param, VariableMapping mapping, Map<String, ShaderNodeLoaderDelegate.DeclaredVariable> map, Statement statement) throws MatParseExceptionUpdates the right variable of the given mapping from aMatParam(a WorldParam) it checks if the uniform hasn't already been loaded, add it to the maps if not.- Parameters:
param- the mat param.mapping- the mapping.map- the map of uniforms to search into.statement- the statement being read- Returns:
- true if the param was added to the map.
- Throws:
MatParseException- in case of a syntax error
-
updateVarFromAttributes
Updates a variable from the attribute list.- Parameters:
right- the variablemapping- the mapping
-
addDefine
Adds a define to the technique def- Parameters:
paramName- the name of the material parameterparamType- the type of the material parameter
-
findNodeOutput
Finds a variable with the given name from the list of variable.- Parameters:
vars- the list of shader node variables.rightVarName- the variable name to search for.- Returns:
- the found variable or null is not found.
-
extractCondition
Extracts and checks a condition expression.- Parameters:
condition- the condition expression.statement- the statement being read.- Throws:
MatParseException- if the condition isn't valid.
-
readInputMapping
Reads an input mapping.- Parameters:
statement- the statement being read.- Returns:
- the variable mapping.
- Throws:
MatParseException- if we have a problem with parsing input mapping statement.
-
readOutputMapping
Reads an output mapping.- Parameters:
statement- the statement being read.- Returns:
- the mapping
- Throws:
MatParseException- if we have a problem with parsing the statement.
-
readNodes
Reads a list of ShaderNodes- Parameters:
statements- the list of statements to read- Throws:
IOException- if an I/O error occurs
-
fixSamplerType
retrieve the leftType corresponding sampler type from the rightType- Parameters:
leftType- the left samplerTyperightType- the right sampler type (can be multiple types separated by "|"- Returns:
- the type or null if not found
-
storeGlobal
Stores a global output.- Parameters:
var- the variable to store.varStatement- the statement being read.- Throws:
MatParseException- if we have duplicates of a global vertex output variable.
-
storeAttribute
Stores an attribute.- Parameters:
var- the variable to store.
-
storeVertexUniform
Stores a vertex uniform.- Parameters:
var- the variable to store.
-
storeFragmentUniform
store a fragment uniform- Parameters:
var- the variable to store
-
setAssetManager
sets the assetManager- Parameters:
assetManager- for loading assets (alias created)
-
findDefinition
Find the definition from this statement (loads it if necessary)- Parameters:
statement- the statement being read- Returns:
- the definition
- Throws:
IOException- if an I/O error occurs
-
storeVaryings
store a varying- Parameters:
node- the shaderNodevariable- the variable to store
-
mergeConditions
Merges 2 conditions with the given operator- Parameters:
condition1- the first conditioncondition2- the second conditionoperator- the operator ("&&" or "||&)- Returns:
- the merged condition
-
storeVariable
Searches a variable in a list from its name and merges the conditions of the variables.- Parameters:
variable- the variable.varList- the variable list.
-
checkTypes
check the types of a mapping, left type must match right type take the swizzle into account- Parameters:
mapping- the mappingstatement1- the statement being read- Throws:
MatParseException- in case of a syntax error
-
clear
public void clear()
-