Search in sources :

Example 6 with ShaderNode

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

the class ShaderNodeLoaderDelegate method computeConditions.

protected void computeConditions() {
    updateConditions(vertexDeclaredUniforms);
    updateConditions(fragmentDeclaredUniforms);
    updateConditions(varyings);
    for (DeclaredVariable v : varyings.values()) {
        for (ShaderNode sn : techniqueDef.getShaderNodes()) {
            if (sn.getDefinition().getType() == Shader.ShaderType.Vertex) {
                for (VariableMapping mapping : sn.getInputMapping()) {
                    if (mapping.getLeftVariable().equals(v.var)) {
                        if (mapping.getCondition() == null || v.var.getCondition() == null) {
                            mapping.setCondition(v.var.getCondition());
                        } else {
                            mapping.setCondition("(" + mapping.getCondition() + ") || (" + v.var.getCondition() + ")");
                        }
                    }
                }
            }
        }
    }
    updateConditions(attributes);
//        updateConditions(fragmentGlobals);
//        vertexGlobal.makeCondition();
}
Also used : ShaderNode(com.jme3.shader.ShaderNode) VariableMapping(com.jme3.shader.VariableMapping)

Example 7 with ShaderNode

use of com.jme3.shader.ShaderNode 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 8 with ShaderNode

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

the class ShaderNodeLoaderDelegate method readShaderNode.

/**
     * reads a list of ShaderNode{} blocks
     *
     * @param statements the list of statements to parse
     * @throws IOException
     */
protected void readShaderNode(List<Statement> statements) throws IOException {
    for (Statement statement : statements) {
        String line = statement.getLine();
        String[] split = statement.getLine().split("[ \\{]");
        if (line.startsWith("Definition")) {
            ShaderNodeDefinition def = findDefinition(statement);
            shaderNode.setDefinition(def);
            if (def.isNoOutput()) {
                techniqueDef.getShaderGenerationInfo().getUnusedNodes().remove(shaderNode.getName());
            }
        } else if (line.startsWith("Condition")) {
            String condition = line.substring(line.lastIndexOf(":") + 1).trim();
            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);
            }
        } else if (line.startsWith("OutputMapping")) {
            for (Statement statement1 : statement.getContents()) {
                VariableMapping mapping = readOutputMapping(statement1);
                techniqueDef.getShaderGenerationInfo().getUnusedNodes().remove(shaderNode.getName());
                shaderNode.getOutputMapping().add(mapping);
            }
        } else {
            throw new MatParseException("ShaderNodeDefinition", split[0], statement);
        }
    }
}
Also used : Statement(com.jme3.util.blockparser.Statement) VariableMapping(com.jme3.shader.VariableMapping) ShaderNodeDefinition(com.jme3.shader.ShaderNodeDefinition)

Aggregations

VariableMapping (com.jme3.shader.VariableMapping)4 ShaderNode (com.jme3.shader.ShaderNode)3 ShaderNodeVariable (com.jme3.shader.ShaderNodeVariable)3 MatParam (com.jme3.material.MatParam)2 Statement (com.jme3.util.blockparser.Statement)2 AssetNotFoundException (com.jme3.asset.AssetNotFoundException)1 ShaderGenerationInfo (com.jme3.material.ShaderGenerationInfo)1 ConditionParser (com.jme3.material.plugins.ConditionParser)1 ShaderNodeDefinition (com.jme3.shader.ShaderNodeDefinition)1 UniformBinding (com.jme3.shader.UniformBinding)1 IOException (java.io.IOException)1