Search in sources :

Example 1 with ShaderGenerationInfo

use of com.jme3.material.ShaderGenerationInfo in project jmonkeyengine by jMonkeyEngine.

the class ShaderGenerationInfo method clone.

@Override
protected ShaderGenerationInfo clone() throws CloneNotSupportedException {
    ShaderGenerationInfo clone = (ShaderGenerationInfo) super.clone();
    for (ShaderNodeVariable attribute : attributes) {
        clone.attributes.add(attribute.clone());
    }
    for (ShaderNodeVariable uniform : vertexUniforms) {
        clone.vertexUniforms.add(uniform.clone());
    }
    clone.vertexGlobal = vertexGlobal.clone();
    for (ShaderNodeVariable varying : varyings) {
        clone.varyings.add(varying.clone());
    }
    for (ShaderNodeVariable uniform : fragmentUniforms) {
        clone.fragmentUniforms.add(uniform.clone());
    }
    for (ShaderNodeVariable globals : fragmentGlobals) {
        clone.fragmentGlobals.add(globals.clone());
    }
    clone.unusedNodes.addAll(unusedNodes);
    return clone;
}
Also used : ShaderNodeVariable(com.jme3.shader.ShaderNodeVariable)

Example 2 with ShaderGenerationInfo

use of com.jme3.material.ShaderGenerationInfo in project jmonkeyengine by jMonkeyEngine.

the class ShaderGenerator method generateShader.

/**
     * Generate vertex and fragment shaders for the given technique
     *
     * @return a Shader program
     */
public Shader generateShader(String definesSourceCode) {
    if (techniqueDef == null) {
        throw new UnsupportedOperationException("The shaderGenerator was not " + "properly initialized, call " + "initialize(TechniqueDef) before any generation");
    }
    String techniqueName = techniqueDef.getName();
    ShaderGenerationInfo info = techniqueDef.getShaderGenerationInfo();
    Shader shader = new Shader();
    for (ShaderType type : ShaderType.values()) {
        String extension = type.getExtension();
        String language = getLanguageAndVersion(type);
        String shaderSourceCode = buildShader(techniqueDef.getShaderNodes(), info, type);
        if (shaderSourceCode != null) {
            String shaderSourceAssetName = techniqueName + "." + extension;
            shader.addSource(type, shaderSourceAssetName, shaderSourceCode, definesSourceCode, language);
        }
    }
    techniqueDef = null;
    return shader;
}
Also used : ShaderGenerationInfo(com.jme3.material.ShaderGenerationInfo) ShaderType(com.jme3.shader.Shader.ShaderType)

Example 3 with ShaderGenerationInfo

use of com.jme3.material.ShaderGenerationInfo in project jmonkeyengine by jMonkeyEngine.

the class ShaderNodeLoaderDelegate method readNodes.

/**
     * Reads a list of ShaderNodes
     *
     * @param statements the list of statements to read
     * @throws IOException
     */
public void readNodes(List<Statement> statements) throws IOException {
    if (techniqueDef.getShaderNodes() == null) {
        techniqueDef.setShaderNodes(new ArrayList<ShaderNode>());
        techniqueDef.setShaderGenerationInfo(new ShaderGenerationInfo());
    }
    for (Statement statement : statements) {
        String[] split = statement.getLine().split("[ \\{]");
        if (statement.getLine().startsWith("ShaderNode ")) {
            String name = statement.getLine().substring("ShaderNode".length()).trim();
            if (nodes == null) {
                nodes = new HashMap<String, ShaderNode>();
            }
            if (!nodes.containsKey(name)) {
                shaderNode = new ShaderNode();
                shaderNode.setName(name);
                techniqueDef.getShaderGenerationInfo().getUnusedNodes().add(name);
                readShaderNode(statement.getContents());
                nodes.put(name, shaderNode);
                techniqueDef.getShaderNodes().add(shaderNode);
            } else {
                throw new MatParseException("ShaderNode " + name + " is already defined", statement);
            }
        } else {
            throw new MatParseException("ShaderNode", split[0], statement);
        }
    }
}
Also used : ShaderGenerationInfo(com.jme3.material.ShaderGenerationInfo) ShaderNode(com.jme3.shader.ShaderNode) Statement(com.jme3.util.blockparser.Statement)

Aggregations

ShaderGenerationInfo (com.jme3.material.ShaderGenerationInfo)2 ShaderType (com.jme3.shader.Shader.ShaderType)1 ShaderNode (com.jme3.shader.ShaderNode)1 ShaderNodeVariable (com.jme3.shader.ShaderNodeVariable)1 Statement (com.jme3.util.blockparser.Statement)1