/** * makes sure inPosition attribute is of type vec3 or vec4 * @param var the inPosition attribute */ protected void fixInPositionType(ShaderNodeVariable var) { if(!var.getType().equals("vec3") || !var.getType().equals("vec4")){ var.setType("vec3"); } }
/** * Searches a variable in the given list and updates its type and namespace. * * @param var the variable to update. * @param list the variables list. * @return true if the variable has been found and updated. */ protected boolean updateVariableFromList(ShaderNodeVariable var, List<ShaderNodeVariable> list) { for (ShaderNodeVariable shaderNodeVariable : list) { if (shaderNodeVariable.getName().equals(var.getName())) { var.setType(shaderNodeVariable.getType()); var.setMultiplicity(shaderNodeVariable.getMultiplicity()); var.setNameSpace(shaderNode.getName()); return true; } } return false; }
/** * Updates the type of the right variable of a mapping from the type of the * left variable. * * @param mapping the mapping to consider. */ protected void updateRightTypeFromLeftType(VariableMapping mapping) { String type = mapping.getLeftVariable().getType(); int card = ShaderUtils.getCardinality(type, mapping.getRightSwizzling()); if (card > 0) { if (card == 1) { type = "float"; } else { type = "vec" + card; } } mapping.getRightVariable().setType(type); }
/** * Updates 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 if the texture type isn't valid. */ 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); } }
/** * 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. * * @param param the WorldParam UniformBinding * @param mapping the mapping * @param map the map of uniforms to search into * @return true if the param was added to the map */ protected boolean updateRightFromUniforms(UniformBinding param, VariableMapping mapping, Map<String, DeclaredVariable> map) { ShaderNodeVariable right = mapping.getRightVariable(); String name = param.toString(); DeclaredVariable dv = map.get(name); if (dv == null) { right.setType(param.getGlslType()); right.setName(name); right.setPrefix("g_"); dv = new DeclaredVariable(right); map.put(right.getName(), dv); dv.addNode(shaderNode); mapping.setRightVariable(right); return true; } dv.addNode(shaderNode); mapping.setRightVariable(dv.var); return false; }
left.setType("vec4"); // Globals are all vec4 for now (maybe forever...) storeGlobal(left, statement); } else {
right.setType(param.getVarType().getGlslType()); right.setName(param.getName()); right.setPrefix("m_");
/** * makes sure inPosition attribute is of type vec3 or vec4 * @param var the inPosition attribute */ protected void fixInPositionType(ShaderNodeVariable var) { if(!var.getType().equals("vec3") || !var.getType().equals("vec4")){ var.setType("vec3"); } }
/** * updates the type of the right variable of a mapping from the type of the * left variable * * @param mapping the mapping to consider */ protected void updateRightTypeFromLeftType(VariableMapping mapping) { String type = mapping.getLeftVariable().getType(); int card = ShaderUtils.getCardinality(type, mapping.getRightSwizzling()); if (card > 0) { if (card == 1) { type = "float"; } else { type = "vec" + card; } } mapping.getRightVariable().setType(type); }
/** * search a variable in the given list and updates its type and namespace * * @param var the variable to update * @param list the variables list * @return true if the variable has been found and updated */ protected boolean updateVariableFromList(ShaderNodeVariable var, List<ShaderNodeVariable> list) { for (ShaderNodeVariable shaderNodeVariable : list) { if (shaderNodeVariable.getName().equals(var.getName())) { var.setType(shaderNodeVariable.getType()); var.setMultiplicity(shaderNodeVariable.getMultiplicity()); var.setNameSpace(shaderNode.getName()); return true; } } return false; }
/** * 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. * * @param param the WorldParam UniformBinding * @param mapping the mapping * @param map the map of uniforms to search into * @return true if the param was added to the map */ protected boolean updateRightFromUniforms(UniformBinding param, VariableMapping mapping, Map<String, DeclaredVariable> map) { ShaderNodeVariable right = mapping.getRightVariable(); String name = param.toString(); DeclaredVariable dv = map.get(name); if (dv == null) { right.setType(param.getGlslType()); right.setName(name); right.setPrefix("g_"); dv = new DeclaredVariable(right); map.put(right.getName(), dv); dv.addNode(shaderNode); mapping.setRightVariable(right); return true; } dv.addNode(shaderNode); mapping.setRightVariable(dv.var); return false; }
/** * 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); } }
left.setType("vec4");//Globals are all vec4 for now (maybe forever...) storeGlobal(left, statement1); } else {
DeclaredVariable dv = map.get(param.getName()); if (dv == null) { right.setType(param.getVarType().getGlslType()); right.setName(param.getName()); right.setPrefix("m_");