/**
  * updates a variable from the Attribute list
  *
  * @param right the variable
  * @param mapping the mapping
  */
 public void updateVarFromAttributes(ShaderNodeVariable right, VariableMapping mapping) {
   DeclaredVariable dv = attributes.get(right.getName());
   if (dv == null) {
     dv = new DeclaredVariable(right);
     attributes.put(right.getName(), dv);
     updateRightTypeFromLeftType(mapping);
   } else {
     mapping.setRightVariable(dv.var);
   }
   dv.addNode(shaderNode);
 }
 /**
  * updates the right variable of the given mapping from a MatParam (a WorldParam) it checks if the
  * unifrom hasn't already been loaded, add it to the maps if not.
  *
  * @param param the MatParam
  * @param mapping the mapping
  * @param map the map of uniforms to search into
  * @return true if the param was added to the map
  */
 public boolean updateRightFromUniforms(
     MatParam param,
     VariableMapping mapping,
     Map<String, DeclaredVariable> map,
     Statement statement)
     throws MatParseException {
   ShaderNodeVariable right = mapping.getRightVariable();
   DeclaredVariable dv = map.get(param.getPrefixedName());
   if (dv == null) {
     right.setType(param.getVarType().getGlslType());
     right.setName(param.getPrefixedName());
     if (mapping.getLeftVariable().getMultiplicity() != null) {
       if (!param.getVarType().name().endsWith("Array")) {
         throw new MatParseException(param.getName() + " is not of Array type", statement);
       }
       String multiplicity = mapping.getLeftVariable().getMultiplicity();
       try {
         Integer.parseInt(multiplicity);
       } catch (NumberFormatException nfe) {
         // multiplicity is not an int attempting to find for a material parameter.
         MatParam mp = findMatParam(multiplicity);
         if (mp != null) {
           addDefine(multiplicity, VarType.Int);
           multiplicity = multiplicity.toUpperCase();
         } else {
           throw new MatParseException(
               "Wrong multiplicity for variable"
                   + mapping.getLeftVariable().getName()
                   + ". "
                   + multiplicity
                   + " should be an int or a declared material parameter.",
               statement);
         }
       }
       right.setMultiplicity(multiplicity);
     }
     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;
 }
 /**
  * updates the right variable of the given mapping from a UniformBinding (a WorldParam) it checks
  * if the unifrom 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 = "g_" + param.toString();
   DeclaredVariable dv = map.get(name);
   if (dv == null) {
     right.setType(param.getGlslType());
     right.setName(name);
     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;
 }
  /**
   * store a varying
   *
   * @param node the shaderNode
   * @param variable the variable to store
   */
  public void storeVaryings(ShaderNode node, ShaderNodeVariable variable) {
    variable.setShaderOutput(true);
    if (node.getDefinition().getType() == Shader.ShaderType.Vertex
        && shaderNode.getDefinition().getType() == Shader.ShaderType.Fragment) {
      DeclaredVariable dv = varyings.get(variable.getName());
      if (dv == null) {
        techniqueDef.getShaderGenerationInfo().getVaryings().add(variable);
        dv = new DeclaredVariable(variable);

        varyings.put(variable.getName(), dv);
      }
      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);
        }
      }
    }
  }
 private void updateConditions(Map<String, DeclaredVariable> map) {
   for (DeclaredVariable declaredVariable : map.values()) {
     declaredVariable.makeCondition();
   }
 }