Search in sources :

Example 1 with Statement

use of com.jme3.util.blockparser.Statement in project jmonkeyengine by jMonkeyEngine.

the class J3MLoader method readShadowMode.

// ShadowMode <MODE>
private void readShadowMode(String statement) throws IOException {
    String[] split = statement.split(whitespacePattern);
    if (split.length != 2) {
        throw new IOException("ShadowMode statement syntax incorrect");
    }
    ShadowMode sm = ShadowMode.valueOf(split[1]);
    technique.setShadowMode(sm);
}
Also used : ShadowMode(com.jme3.material.TechniqueDef.ShadowMode) IOException(java.io.IOException)

Example 2 with Statement

use of com.jme3.util.blockparser.Statement in project jmonkeyengine by jMonkeyEngine.

the class J3MLoader method readForcedRenderState.

private void readForcedRenderState(List<Statement> renderStates) throws IOException {
    renderState = new RenderState();
    for (Statement statement : renderStates) {
        readRenderStateStatement(statement);
    }
    technique.setForcedRenderState(renderState);
    renderState = null;
}
Also used : Statement(com.jme3.util.blockparser.Statement)

Example 3 with Statement

use of com.jme3.util.blockparser.Statement in project jmonkeyengine by jMonkeyEngine.

the class J3MLoader method readLightMode.

// LightMode <MODE>
private void readLightMode(String statement) throws IOException {
    String[] split = statement.split(whitespacePattern);
    if (split.length != 2) {
        throw new IOException("LightMode statement syntax incorrect");
    }
    LightMode lm = LightMode.valueOf(split[1]);
    technique.setLightMode(lm);
}
Also used : LightMode(com.jme3.material.TechniqueDef.LightMode) IOException(java.io.IOException)

Example 4 with Statement

use of com.jme3.util.blockparser.Statement in project jmonkeyengine by jMonkeyEngine.

the class J3MLoader method readTechnique.

private void readTechnique(Statement techStat) throws IOException {
    isUseNodes = false;
    String[] split = techStat.getLine().split(whitespacePattern);
    Cloner cloner = new Cloner();
    String name;
    if (split.length == 1) {
        name = TechniqueDef.DEFAULT_TECHNIQUE_NAME;
    } else if (split.length == 2) {
        name = split[1];
    } else {
        throw new IOException("Technique statement syntax incorrect");
    }
    String techniqueUniqueName = materialDef.getAssetName() + "@" + name;
    technique = new TechniqueDef(name, techniqueUniqueName.hashCode());
    for (Statement statement : techStat.getContents()) {
        readTechniqueStatement(statement);
    }
    technique.setShaderPrologue(createShaderPrologue(presetDefines));
    switch(technique.getLightMode()) {
        case Disable:
            technique.setLogic(new DefaultTechniqueDefLogic(technique));
            break;
        case MultiPass:
            technique.setLogic(new MultiPassLightingLogic(technique));
            break;
        case SinglePass:
            technique.setLogic(new SinglePassLightingLogic(technique));
            break;
        case StaticPass:
            technique.setLogic(new StaticPassLightingLogic(technique));
            break;
        case SinglePassAndImageBased:
            technique.setLogic(new SinglePassAndImageBasedLightingLogic(technique));
            break;
        default:
            throw new UnsupportedOperationException();
    }
    List<TechniqueDef> techniqueDefs = new ArrayList<>();
    if (isUseNodes) {
        nodesLoaderDelegate.computeConditions();
        //used for caching later, the shader here is not a file.
        // KIRILL 9/19/2015
        // Not sure if this is needed anymore, since shader caching
        // is now done by TechniqueDef.
        technique.setShaderFile(technique.hashCode() + "", technique.hashCode() + "", "GLSL100", "GLSL100");
        techniqueDefs.add(technique);
    } else if (shaderNames.containsKey(Shader.ShaderType.Vertex) && shaderNames.containsKey(Shader.ShaderType.Fragment)) {
        if (shaderLanguages.size() > 1) {
            for (int i = 1; i < shaderLanguages.size(); i++) {
                cloner.clearIndex();
                TechniqueDef td = cloner.clone(technique);
                td.setShaderFile(shaderNames, shaderLanguages.get(i));
                techniqueDefs.add(td);
            }
        }
        technique.setShaderFile(shaderNames, shaderLanguages.get(0));
        techniqueDefs.add(technique);
    } else {
        technique = null;
        shaderLanguages.clear();
        shaderNames.clear();
        presetDefines.clear();
        langSize = 0;
        logger.log(Level.WARNING, "Fixed function technique was ignored");
        logger.log(Level.WARNING, "Fixed function technique ''{0}'' was ignored for material {1}", new Object[] { name, key });
        return;
    }
    for (TechniqueDef techniqueDef : techniqueDefs) {
        materialDef.addTechniqueDef(techniqueDef);
    }
    technique = null;
    langSize = 0;
    shaderLanguages.clear();
    shaderNames.clear();
    presetDefines.clear();
}
Also used : Statement(com.jme3.util.blockparser.Statement) IOException(java.io.IOException) StaticPassLightingLogic(com.jme3.material.logic.StaticPassLightingLogic) Cloner(com.jme3.util.clone.Cloner)

Example 5 with Statement

use of com.jme3.util.blockparser.Statement in project jmonkeyengine by jMonkeyEngine.

the class ShaderNodeDefinitionLoader method load.

@Override
public Object load(AssetInfo assetInfo) throws IOException {
    AssetKey k = assetInfo.getKey();
    if (!(k instanceof ShaderNodeDefinitionKey)) {
        throw new IOException("ShaderNodeDefinition file must be loaded via ShaderNodeDefinitionKey");
    }
    ShaderNodeDefinitionKey key = (ShaderNodeDefinitionKey) k;
    loaderDelegate = new ShaderNodeLoaderDelegate();
    InputStream in = assetInfo.openStream();
    List<Statement> roots = BlockLanguageParser.parse(in);
    if (roots.size() == 2) {
        Statement exception = roots.get(0);
        String line = exception.getLine();
        if (line.startsWith("Exception")) {
            throw new AssetLoadException(line.substring("Exception ".length()));
        } else {
            throw new MatParseException("In multiroot shader node definition, expected first statement to be 'Exception'", exception);
        }
    } else if (roots.size() != 1) {
        throw new MatParseException("Too many roots in J3SN file", roots.get(0));
    }
    return loaderDelegate.readNodesDefinitions(roots.get(0).getContents(), key);
}
Also used : AssetKey(com.jme3.asset.AssetKey) ShaderNodeDefinitionKey(com.jme3.asset.ShaderNodeDefinitionKey) InputStream(java.io.InputStream) Statement(com.jme3.util.blockparser.Statement) IOException(java.io.IOException) AssetLoadException(com.jme3.asset.AssetLoadException)

Aggregations

Statement (com.jme3.util.blockparser.Statement)16 IOException (java.io.IOException)10 AssetNotFoundException (com.jme3.asset.AssetNotFoundException)4 ShaderNodeVariable (com.jme3.shader.ShaderNodeVariable)4 VariableMapping (com.jme3.shader.VariableMapping)4 ShaderNodeDefinitionKey (com.jme3.asset.ShaderNodeDefinitionKey)3 Material (com.jme3.material.Material)3 MaterialList (com.jme3.material.MaterialList)3 ShaderNodeDefinition (com.jme3.shader.ShaderNodeDefinition)3 MatParam (com.jme3.material.MatParam)2 ShaderNode (com.jme3.shader.ShaderNode)2 Image (com.jme3.texture.Image)2 Texture2D (com.jme3.texture.Texture2D)2 InputStream (java.io.InputStream)2 AssetKey (com.jme3.asset.AssetKey)1 AssetLoadException (com.jme3.asset.AssetLoadException)1 TextureKey (com.jme3.asset.TextureKey)1 ShaderGenerationInfo (com.jme3.material.ShaderGenerationInfo)1 LightMode (com.jme3.material.TechniqueDef.LightMode)1 ShadowMode (com.jme3.material.TechniqueDef.ShadowMode)1