protected void initNodesLoader() { if (!isUseNodes) { isUseNodes = shaderNames.get(Shader.ShaderType.Vertex) == null && shaderNames.get(Shader.ShaderType.Fragment) == null; if (isUseNodes) { if (nodesLoaderDelegate == null) { nodesLoaderDelegate = new ShaderNodeLoaderDelegate(); }else{ nodesLoaderDelegate.clear(); } nodesLoaderDelegate.setTechniqueDef(technique); nodesLoaderDelegate.setMaterialDef(materialDef); nodesLoaderDelegate.setAssetManager(assetManager); } } }
/** * Extracts and checks a condition expression. * * @param condition the condition expression. * @param statement the statement being read. * @throws MatParseException if the condition isn't valid. */ public void extractCondition(String condition, Statement statement) throws MatParseException { List<String> defines = conditionParser.extractDefines(condition); for (String string : defines) { MatParam param = findMatParam(string); if (param != null) { addDefine(param.getName(), param.getVarType()); } else { throw new MatParseException("Invalid condition, condition must match a Material Parameter named " + condition, statement); } } }
String[] vars = cond[0].split("="); checkMappingFormat(vars, statement); extractCondition(cond[1], statement); mapping.setCondition(conditionParser.getFormattedExpression());
@Override public Object load(AssetInfo assetInfo) throws IOException { AssetKey k = assetInfo.getKey(); if (!(k instanceof ShaderNodeDefinitionKey)) { throw new IOException("ShaderNodeDefinition file must be loaded via ShaderNodeDefinitionKey"); } ShaderNodeDefinitionKey key = (ShaderNodeDefinitionKey) k; loaderDelegate = new ShaderNodeLoaderDelegate(); InputStream in = assetInfo.openStream(); List<Statement> roots = BlockLanguageParser.parse(in); if (roots.size() == 2) { Statement exception = roots.get(0); String line = exception.getLine(); if (line.startsWith("Exception")) { throw new AssetLoadException(line.substring("Exception ".length())); } else { throw new MatParseException("In multiroot shader node definition, expected first statement to be 'Exception'", exception); } } else if (roots.size() != 1) { throw new MatParseException("Too many roots in J3SN file", roots.get(0)); } return loaderDelegate.readNodesDefinitions(roots.get(0).getContents(), key); } }
mapping = parseMapping(statement, IM_HAS_NAME_SPACE); } catch (final Exception e) { throw new MatParseException("Unexpected mapping format", statement, e); if (!updateVariableFromList(left, definition.getInputs())) { throw new MatParseException(left.getName() + " is not an input variable of " + definition.getName(), statement); } else if (left.getType().startsWith("sampler") && (right == null || !right.getNameSpace().equals(ShaderGenerator.NAME_SPACE_MAT_PARAM))) { storeGlobal(right, statement); } else if (right.getNameSpace().equals(ShaderGenerator.NAME_SPACE_VERTEX_ATTRIBUTE)) { if (definition.getType() == ShaderType.Fragment) { throw new MatParseException("Cannot have an attribute as input in a fragment shader" + right.getName(), statement); updateVarFromAttributes(mapping.getRightVariable(), mapping); storeAttribute(mapping.getRightVariable()); } else if (right.getNameSpace().equals(ShaderGenerator.NAME_SPACE_MAT_PARAM)) { MatParam param = findMatParam(right.getName()); if (param == null) { throw new MatParseException("Could not find a Material Parameter named " + right.getName(), statement); if (updateRightFromUniforms(param, mapping, vertexDeclaredUniforms, statement)) { updateMaterialTextureType(statement, mapping, left, param); storeVertexUniform(mapping.getRightVariable()); if (updateRightFromUniforms(param, mapping, fragmentDeclaredUniforms, statement)) { updateMaterialTextureType(statement, mapping, left, param); storeFragmentUniform(mapping.getRightVariable());
mapping = parseMapping(statement, OM_HAS_NAME_SPACE); } catch (final Exception e) { throw new MatParseException("Unexpected mapping format", statement, e); storeGlobal(left, statement); } else { throw new MatParseException("Only Global nameSpace is allowed for outputMapping, got" + left.getNameSpace(), statement); if (!updateVariableFromList(right, definition.getOutputs())) { throw new MatParseException(right.getName() + " is not an output variable of " + definition.getName(), statement); checkTypes(mapping, statement);
ShaderNodeDefinition def = findDefinition(statement); shaderNode.setDefinition(def); if(def.isNoOutput()){ extractCondition(condition, statement); shaderNode.setCondition(conditionParser.getFormattedExpression()); } else if (line.startsWith("InputMappings")) { for (final Statement subStatement : statement.getContents()) { VariableMapping mapping = readInputMapping(subStatement); VariableMapping mapping = readOutputMapping(statement1); unusedNodes.remove(shaderNode.getName()); shaderNode.getOutputMapping().add(mapping);
} catch (final NumberFormatException nfe) { MatParam mp = findMatParam(multiplicity); if (mp != null) { addDefine(multiplicity, VarType.Int); multiplicity = multiplicity.toUpperCase(); left.setMultiplicity(multiplicity); left.setCondition(mergeConditions(left.getCondition(), "defined(" + multiplicity + ")", "||")); } else { throw new MatParseException("Wrong multiplicity for variable" + left.getName() + ". " +
VariableMapping mapping = null; try { mapping = parseMapping(statement1, new boolean[]{false, true}); } catch (Exception e) { throw new MatParseException("Unexpected mapping format", statement1, e); if (!updateVariableFromList(left, shaderNode.getDefinition().getInputs())) { throw new MatParseException(left.getName() + " is not an input variable of " + shaderNode.getDefinition().getName(), statement1); storeGlobal(right, statement1); updateVarFromAttributes(mapping.getRightVariable(), mapping); storeAttribute(mapping.getRightVariable()); } else if (right.getNameSpace().equals("MatParam")) { MatParam param = findMatParam(right.getName()); if (param == null) { throw new MatParseException("Could not find a Material Parameter named " + right.getName(), statement1); if (updateRightFromUniforms(param, mapping, vertexDeclaredUniforms, statement1)) { updateMaterialTextureType(statement1, mapping, left, param); storeVertexUniform(mapping.getRightVariable()); if (updateRightFromUniforms(param, mapping, fragmentDeclaredUniforms, statement1)) { updateMaterialTextureType(statement1, mapping, left, param); storeFragmentUniform(mapping.getRightVariable()); UniformBinding worldParam = findWorldParam(right.getName()); if (worldParam == null) { throw new MatParseException("Could not find a World Parameter named " + right.getName(), statement1);
VariableMapping mapping = null; try { mapping = parseMapping(statement1, new boolean[]{true, false}); } catch (Exception e) { throw new MatParseException("Unexpected mapping format", statement1, e); storeGlobal(left, statement1); } else { throw new MatParseException("Only Global nameSpace is allowed for outputMapping, got" + left.getNameSpace(), statement1); if (!updateVariableFromList(right, shaderNode.getDefinition().getOutputs())) { throw new MatParseException(right.getName() + " is not an output variable of " + shaderNode.getDefinition().getName(), statement1); checkTypes(mapping, statement1);
String[] split = statement.getLine().split("[ \\{]"); if (line.startsWith("Definition")) { ShaderNodeDefinition def = findDefinition(statement); shaderNode.setDefinition(def); if(def.isNoOutput()){ extractCondition(condition, statement); shaderNode.setCondition(conditionParser.getFormattedExpression()); } else if (line.startsWith("InputMapping")) { for (Statement statement1 : statement.getContents()) { VariableMapping mapping = readInputMapping(statement1); techniqueDef.getShaderGenerationInfo().getUnusedNodes().remove(mapping.getRightVariable().getNameSpace()); shaderNode.getInputMapping().add(mapping); VariableMapping mapping = readOutputMapping(statement1); techniqueDef.getShaderGenerationInfo().getUnusedNodes().remove(shaderNode.getName()); shaderNode.getOutputMapping().add(mapping);
} catch (NumberFormatException nfe) { MatParam mp = findMatParam(multiplicity); if (mp != null) { addDefine(multiplicity, VarType.Int); multiplicity = multiplicity.toUpperCase(); mapping.getLeftVariable().setMultiplicity(multiplicity); mapping.getLeftVariable().setCondition(mergeConditions(mapping.getLeftVariable().getCondition(), "defined(" + multiplicity + ")", "||")); } else { throw new MatParseException("Wrong multiplicity for variable" + mapping.getLeftVariable().getName() + ". " + multiplicity + " should be an int or a declared material parameter.", statement);
@Override public Object load(AssetInfo assetInfo) throws IOException { AssetKey k = assetInfo.getKey(); if (!(k instanceof ShaderNodeDefinitionKey)) { throw new IOException("ShaderNodeDefinition file must be loaded via ShaderNodeDefinitionKey"); } ShaderNodeDefinitionKey key = (ShaderNodeDefinitionKey) k; loaderDelegate = new ShaderNodeLoaderDelegate(); InputStream in = assetInfo.openStream(); List<Statement> roots = BlockLanguageParser.parse(in); if (roots.size() == 2) { Statement exception = roots.get(0); String line = exception.getLine(); if (line.startsWith("Exception")) { throw new AssetLoadException(line.substring("Exception ".length())); } else { throw new MatParseException("In multiroot shader node definition, expected first statement to be 'Exception'", exception); } } else if (roots.size() != 1) { throw new MatParseException("Too many roots in J3SN file", roots.get(0)); } return loaderDelegate.readNodesDefinitions(roots.get(0).getContents(), key); } }
protected void initNodesLoader() { if (!isUseNodes) { isUseNodes = shaderNames.get(Shader.ShaderType.Vertex) == null && shaderNames.get(Shader.ShaderType.Fragment) == null; if (isUseNodes) { if (nodesLoaderDelegate == null) { nodesLoaderDelegate = new ShaderNodeLoaderDelegate(); }else{ nodesLoaderDelegate.clear(); } nodesLoaderDelegate.setTechniqueDef(technique); nodesLoaderDelegate.setMaterialDef(materialDef); nodesLoaderDelegate.setAssetManager(assetManager); } } }
/** * extract and check a condition expression * * @param cond the condition expression * @param statement the statement being read * @throws IOException */ public void extractCondition(String cond, Statement statement) throws IOException { List<String> defines = conditionParser.extractDefines(cond); for (String string : defines) { MatParam param = findMatParam(string); if (param != null) { addDefine(param.getName(), param.getVarType()); } else { throw new MatParseException("Invalid condition, condition must match a Material Parameter named " + cond, statement); } } }
checkMappingFormat(vars, statement); ShaderNodeVariable[] variables = new ShaderNodeVariable[2]; String[] swizzle = new String[2]; extractCondition(cond[1], statement); mapping.setCondition(conditionParser.getFormattedExpression());