Search in sources :

Example 1 with ShaderType

use of com.jme3.shader.Shader.ShaderType in project jmonkeyengine by jMonkeyEngine.

the class TechniqueDef method setShaderFile.

/**
     * Sets the shaders that this technique definition will use.
     *
     * @param shaderNames EnumMap containing all shader names for this stage
     * @param shaderLanguages EnumMap containing all shader languages for this stage
     */
public void setShaderFile(EnumMap<Shader.ShaderType, String> shaderNames, EnumMap<Shader.ShaderType, String> shaderLanguages) {
    requiredCaps.clear();
    weight = 0;
    for (Shader.ShaderType shaderType : shaderNames.keySet()) {
        String language = shaderLanguages.get(shaderType);
        String shaderFile = shaderNames.get(shaderType);
        this.shaderLanguages.put(shaderType, language);
        this.shaderNames.put(shaderType, shaderFile);
        Caps cap = Caps.valueOf(language);
        requiredCaps.add(cap);
        weight = Math.max(weight, cap.ordinal());
        if (shaderType.equals(Shader.ShaderType.Geometry)) {
            requiredCaps.add(Caps.GeometryShader);
        } else if (shaderType.equals(Shader.ShaderType.TessellationControl)) {
            requiredCaps.add(Caps.TesselationShader);
        }
    }
}
Also used : ShaderType(com.jme3.shader.Shader.ShaderType) Caps(com.jme3.renderer.Caps)

Example 2 with ShaderType

use of com.jme3.shader.Shader.ShaderType 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 ShaderType

use of com.jme3.shader.Shader.ShaderType in project jmonkeyengine by jMonkeyEngine.

the class TechniqueDef method loadShader.

private Shader loadShader(AssetManager assetManager, EnumSet<Caps> rendererCaps, DefineList defines) {
    StringBuilder sb = new StringBuilder();
    sb.append(shaderPrologue);
    defines.generateSource(sb, defineNames, defineTypes);
    String definesSourceCode = sb.toString();
    Shader shader;
    if (isUsingShaderNodes()) {
        ShaderGenerator shaderGenerator = assetManager.getShaderGenerator(rendererCaps);
        if (shaderGenerator == null) {
            throw new UnsupportedOperationException("ShaderGenerator was not initialized, " + "make sure assetManager.getGenerator(caps) has been called");
        }
        shaderGenerator.initialize(this);
        shader = shaderGenerator.generateShader(definesSourceCode);
    } else {
        shader = new Shader();
        for (ShaderType type : ShaderType.values()) {
            String language = shaderLanguages.get(type);
            String shaderSourceAssetName = shaderNames.get(type);
            if (language == null || shaderSourceAssetName == null) {
                continue;
            }
            String shaderSourceCode = (String) assetManager.loadAsset(shaderSourceAssetName);
            shader.addSource(type, shaderSourceAssetName, shaderSourceCode, definesSourceCode, language);
        }
    }
    if (getWorldBindings() != null) {
        for (UniformBinding binding : getWorldBindings()) {
            shader.addUniformBinding(binding);
        }
    }
    return shader;
}
Also used : ShaderType(com.jme3.shader.Shader.ShaderType)

Aggregations

ShaderType (com.jme3.shader.Shader.ShaderType)3 ShaderGenerationInfo (com.jme3.material.ShaderGenerationInfo)1 Caps (com.jme3.renderer.Caps)1