Search in sources :

Example 11 with ShaderNodeVariable

use of com.jme3.shader.ShaderNodeVariable in project jmonkeyengine by jMonkeyEngine.

the class ShaderNodeLoaderDelegate method storeVaryings.

/**
     * updates a variable condition form a mapping condition
     *
     * @param var the variable
     * @param mapping the mapping
     */
//    public void updateCondition(ShaderNodeVariable var, VariableMapping mapping) {
//
//        String condition = mergeConditions(shaderNode.getCondition(), mapping.getCondition(), "&&");
//
//        if (var.getCondition() == null) {
//            if (!nulledConditions.contains(var.getNameSpace() + "." + var.getName())) {
//                var.setCondition(condition);
//            }
//        } else {
//            var.setCondition(mergeConditions(var.getCondition(), condition, "||"));
//            if (var.getCondition() == null) {
//                nulledConditions.add(var.getNameSpace() + "." + var.getName());
//            }
//        }
//    }
/**
     * 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);
            }
        }
    }
}
Also used : VariableMapping(com.jme3.shader.VariableMapping)

Example 12 with ShaderNodeVariable

use of com.jme3.shader.ShaderNodeVariable in project jmonkeyengine by jMonkeyEngine.

the class ShaderGenerationInfo method read.

@Override
public void read(JmeImporter im) throws IOException {
    InputCapsule ic = im.getCapsule(this);
    attributes = ic.readSavableArrayList("attributes", new ArrayList<ShaderNodeVariable>());
    vertexUniforms = ic.readSavableArrayList("vertexUniforms", new ArrayList<ShaderNodeVariable>());
    varyings = ic.readSavableArrayList("varyings", new ArrayList<ShaderNodeVariable>());
    fragmentUniforms = ic.readSavableArrayList("fragmentUniforms", new ArrayList<ShaderNodeVariable>());
    fragmentGlobals = ic.readSavableArrayList("fragmentGlobals", new ArrayList<ShaderNodeVariable>());
    vertexGlobal = (ShaderNodeVariable) ic.readSavable("vertexGlobal", null);
}
Also used : InputCapsule(com.jme3.export.InputCapsule) ArrayList(java.util.ArrayList)

Example 13 with ShaderNodeVariable

use of com.jme3.shader.ShaderNodeVariable in project jmonkeyengine by jMonkeyEngine.

the class ShaderNodeLoaderDelegate method updateRightFromUniforms.

/**
     * updates the right variable of the given mapping from a MatParam (a
     * WorldParam) it checks if the uniform 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;
}
Also used : MatParam(com.jme3.material.MatParam) ShaderNodeVariable(com.jme3.shader.ShaderNodeVariable)

Aggregations

ShaderNodeVariable (com.jme3.shader.ShaderNodeVariable)8 VariableMapping (com.jme3.shader.VariableMapping)4 InputCapsule (com.jme3.export.InputCapsule)3 AssetNotFoundException (com.jme3.asset.AssetNotFoundException)2 OutputCapsule (com.jme3.export.OutputCapsule)2 MatParam (com.jme3.material.MatParam)2 IOException (java.io.IOException)2 ShaderType (com.jme3.shader.Shader.ShaderType)1 ShaderNode (com.jme3.shader.ShaderNode)1 UniformBinding (com.jme3.shader.UniformBinding)1 ArrayList (java.util.ArrayList)1