@ -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 ;
@ -232,11 +236,17 @@ public class ShaderNodeLoaderDelegate {
varName = arr [ 0 ] . 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 ;
}
/ * *
@ -661,18 +671,12 @@ public class ShaderNodeLoaderDelegate {
}
if ( shaderNode . getDefinition ( ) . getType ( ) = = Shader . ShaderType . Vertex ) {
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 ( ) ) ;
}
}
@ -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 ) ;
}
}
}
}
/ * *