@ -217,11 +217,15 @@ public class ShaderNodeLoaderDelegate {
* @throws IOException
* /
protected ShaderNodeVariable readVariable ( Statement statement ) throws IOException {
String line = statement . getLine ( ) . trim ( ) . replaceAll ( "\\s*\\[" , "[" ) ;
String [ ] splitVar = line . split ( "\\s" ) ;
if ( splitVar . length ! = 2 ) {
throw new MatParseException ( "2 arguments" , splitVar . length + "" , statement ) ;
if ( splitVar . length > 3 ) {
throw new MatParseException ( "More than 3 arguments" , splitVar . length + "" , statement ) ;
}
String defaultValue = splitVar . length > 2 ? splitVar [ 2 ] : null ;
String varName = splitVar [ 1 ] ;
String varType = splitVar [ 0 ] ;
String multiplicity = null ;
@ -230,13 +234,19 @@ public class ShaderNodeLoaderDelegate {
//we have an array
String [ ] arr = splitVar [ 1 ] . split ( "\\[" ) ;
varName = arr [ 0 ] . trim ( ) ;
multiplicity = arr [ 1 ] . replaceAll ( "\\]" , "" ) . trim ( ) ;
multiplicity = arr [ 1 ] . replaceAll ( "\\]" , "" ) . trim ( ) ;
}
if ( varNames . contains ( varName + ";" ) ) {
throw new MatParseException ( "Duplicate variable name " + varName , statement ) ;
}
varNames + = varName + ";" ;
return new ShaderNodeVariable ( varType , "" , varName , multiplicity ) ;
final ShaderNodeVariable variable = new ShaderNodeVariable ( varType , "" , varName , multiplicity ) ;
variable . setDefaultValue ( defaultValue ) ;
return variable ;
}
/ * *
@ -262,7 +272,7 @@ public class ShaderNodeLoaderDelegate {
String [ ] split = statement . getLine ( ) . split ( "[ \\{]" ) ;
if ( line . startsWith ( "Definition" ) ) {
ShaderNodeDefinition def = findDefinition ( statement ) ;
shaderNode . setDefinition ( def ) ;
shaderNode . setDefinition ( def ) ;
if ( def . isNoOutput ( ) ) {
techniqueDef . getShaderGenerationInfo ( ) . getUnusedNodes ( ) . remove ( shaderNode . getName ( ) ) ;
}
@ -276,12 +286,12 @@ public class ShaderNodeLoaderDelegate {
techniqueDef . getShaderGenerationInfo ( ) . getUnusedNodes ( ) . remove ( mapping . getRightVariable ( ) . getNameSpace ( ) ) ;
shaderNode . getInputMapping ( ) . add ( mapping ) ;
}
} else if ( line . startsWith ( "OutputMapping" ) ) {
} else if ( line . startsWith ( "OutputMapping" ) ) {
for ( Statement statement1 : statement . getContents ( ) ) {
VariableMapping mapping = readOutputMapping ( statement1 ) ;
techniqueDef . getShaderGenerationInfo ( ) . getUnusedNodes ( ) . remove ( shaderNode . getName ( ) ) ;
shaderNode . getOutputMapping ( ) . add ( mapping ) ;
}
}
} else {
throw new MatParseException ( "ShaderNodeDefinition" , split [ 0 ] , statement ) ;
}
@ -298,7 +308,7 @@ public class ShaderNodeLoaderDelegate {
* Format : < nameSpace > . < varName > [ . < swizzling > ] =
* < nameSpace > . < varName > [ . < swizzling > ] [ : Condition ]
* < / code >
*
*
* @param statement the statement to read
* @return the read mapping
* /
@ -660,19 +670,13 @@ public class ShaderNodeLoaderDelegate {
throw new MatParseException ( "Could not find a Material Parameter named " + right . getName ( ) , statement1 ) ;
}
if ( shaderNode . getDefinition ( ) . getType ( ) = = Shader . ShaderType . Vertex ) {
if ( updateRightFromUniforms ( param , mapping , vertexDeclaredUniforms , statement1 ) ) {
if ( updateRightFromUniforms ( param , mapping , vertexDeclaredUniforms , statement1 ) ) {
updateMaterialTextureType ( statement1 , mapping , left , param ) ;
storeVertexUniform ( mapping . getRightVariable ( ) ) ;
}
} else {
if ( updateRightFromUniforms ( param , mapping , fragmentDeclaredUniforms , statement1 ) ) {
if ( mapping . getRightVariable ( ) . getType ( ) . contains ( "|" ) ) {
String type = fixSamplerType ( left . getType ( ) , mapping . getRightVariable ( ) . getType ( ) ) ;
if ( type ! = null ) {
mapping . getRightVariable ( ) . setType ( type ) ;
} else {
throw new MatParseException ( param . getVarType ( ) . toString ( ) + " can only be matched to one of " + param . getVarType ( ) . getGlslType ( ) . replaceAll ( "\\|" , "," ) + " found " + left . getType ( ) , statement1 ) ;
}
}
updateMaterialTextureType ( statement1 , mapping , left , param ) ;
storeFragmentUniform ( mapping . getRightVariable ( ) ) ;
}
}
@ -683,11 +687,11 @@ public class ShaderNodeLoaderDelegate {
throw new MatParseException ( "Could not find a World Parameter named " + right . getName ( ) , statement1 ) ;
}
if ( shaderNode . getDefinition ( ) . getType ( ) = = Shader . ShaderType . Vertex ) {
if ( updateRightFromUniforms ( worldParam , mapping , vertexDeclaredUniforms ) ) {
if ( updateRightFromUniforms ( worldParam , mapping , vertexDeclaredUniforms ) ) {
storeVertexUniform ( mapping . getRightVariable ( ) ) ;
}
} else {
if ( updateRightFromUniforms ( worldParam , mapping , fragmentDeclaredUniforms ) ) {
if ( updateRightFromUniforms ( worldParam , mapping , fragmentDeclaredUniforms ) ) {
storeFragmentUniform ( mapping . getRightVariable ( ) ) ;
}
}
@ -704,7 +708,7 @@ public class ShaderNodeLoaderDelegate {
right . setNameSpace ( node . getName ( ) ) ;
right . setType ( var . getType ( ) ) ;
right . setMultiplicity ( var . getMultiplicity ( ) ) ;
mapping . setRightVariable ( right ) ;
mapping . setRightVariable ( right ) ;
storeVaryings ( node , mapping . getRightVariable ( ) ) ;
}
@ -714,6 +718,32 @@ public class ShaderNodeLoaderDelegate {
return mapping ;
}
/ * *
* Updated the material texture type of the variable mapping .
*
* @param statement the statement .
* @param mapping the variable mapping .
* @param left the left variable .
* @param param the material parameter .
* @throws MatParseException
* /
private void updateMaterialTextureType ( final Statement statement , final VariableMapping mapping ,
final ShaderNodeVariable left , final MatParam param ) throws MatParseException {
if ( ! mapping . getRightVariable ( ) . getType ( ) . contains ( "|" ) ) {
return ;
}
final String type = fixSamplerType ( left . getType ( ) , mapping . getRightVariable ( ) . getType ( ) ) ;
if ( type ! = null ) {
mapping . getRightVariable ( ) . setType ( type ) ;
} else {
throw new MatParseException ( param . getVarType ( ) . toString ( ) + " can only be matched to one of " +
param . getVarType ( ) . getGlslType ( ) . replaceAll ( "\\|" , "," ) + " found " + left . getType ( ) , statement ) ;
}
}
/ * *
* reads an output mapping
*
@ -924,12 +954,12 @@ public class ShaderNodeLoaderDelegate {
dv . addNode ( shaderNode ) ;
//if a variable is declared with the same name as an input and an output and is a varying, set it as a shader output so it's declared as a varying only once.
for ( VariableMapping variableMapping : node . getInputMapping ( ) ) {
if ( variableMapping . getLeftVariable ( ) . getName ( ) . equals ( variable . getName ( ) ) ) {
variableMapping . getLeftVariable ( ) . setShaderOutput ( true ) ;
final ShaderNodeVariable leftVariable = variableMapping . getLeftVariable ( ) ;
if ( leftVariable . getName ( ) . equals ( variable . getName ( ) ) ) {
leftVariable . setShaderOutput ( true ) ;
}
}
}
}
/ * *