Search in sources :

Example 1 with Technique

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

the class AbstractShadowRendererVR method postFrame.

public void postFrame(FrameBuffer out) {
    if (skipPostPass) {
        return;
    }
    if (debug) {
        displayShadowMap(renderManager.getRenderer());
    }
    getReceivers(lightReceivers);
    if (lightReceivers.size() != 0) {
        //setting params to recieving geometry list
        setMatParams(lightReceivers);
        Camera cam = viewPort.getCamera();
        //some materials in the scene does not have a post shadow technique so we're using the fall back material
        if (needsfallBackMaterial) {
            renderManager.setForcedMaterial(postshadowMat);
        }
        //forcing the post shadow technique and render state
        renderManager.setForcedTechnique(postTechniqueName);
        //rendering the post shadow pass
        viewPort.getQueue().renderShadowQueue(lightReceivers, renderManager, cam, false);
        //resetting renderManager settings
        renderManager.setForcedTechnique(null);
        renderManager.setForcedMaterial(null);
        renderManager.setCamera(cam, false);
        //clearing the params in case there are some other shadow renderers
        clearMatParams();
    }
}
Also used : Camera(com.jme3.renderer.Camera)

Example 2 with Technique

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

the class PssmShadowRenderer method setMatParams.

private void setMatParams() {
    GeometryList l = lightReceivers;
    //iteration throught all the geometries of the list to gather the materials
    matCache.clear();
    for (int i = 0; i < l.size(); i++) {
        Material mat = l.get(i).getMaterial();
        //checking if the material has the post technique and adding it to the material cache
        if (mat.getMaterialDef().getTechniqueDefs(postTechniqueName) != null) {
            if (!matCache.contains(mat)) {
                matCache.add(mat);
            }
        } else {
            needsfallBackMaterial = true;
        }
    }
    //iterating through the mat cache and setting the parameters
    for (Material mat : matCache) {
        mat.setColor("Splits", splits);
        mat.setFloat("ShadowMapSize", shadowMapSize);
        for (int j = 0; j < nbSplits; j++) {
            mat.setMatrix4("LightViewProjectionMatrix" + j, lightViewProjectionsMatrices[j]);
        }
        for (int j = 0; j < nbSplits; j++) {
            mat.setTexture("ShadowMap" + j, shadowMaps[j]);
        }
        mat.setBoolean("HardwareShadows", compareMode == CompareMode.Hardware);
        mat.setInt("FilterMode", filterMode.ordinal());
        mat.setFloat("PCFEdge", edgesThickness);
        mat.setFloat("ShadowIntensity", shadowIntensity);
        if (fadeInfo != null) {
            mat.setVector2("FadeInfo", fadeInfo);
        }
    }
    applyHWShadows = false;
    applyFilterMode = false;
    applyPCFEdge = false;
    applyShadowIntensity = false;
    applyFadeInfo = false;
    //so we fall back to the forced material solution (transparent shadows won't be supported for these objects)
    if (needsfallBackMaterial) {
        setPostShadowParams();
    }
}
Also used : GeometryList(com.jme3.renderer.queue.GeometryList) Material(com.jme3.material.Material)

Example 3 with Technique

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

the class Material method preload.

/**
     * Preloads this material for the given render manager.
     * <p>
     * Preloading the material can ensure that when the material is first
     * used for rendering, there won't be any delay since the material has
     * been already been setup for rendering.
     *
     * @param renderManager The render manager to preload for
     */
public void preload(RenderManager renderManager) {
    if (technique == null) {
        selectTechnique(TechniqueDef.DEFAULT_TECHNIQUE_NAME, renderManager);
    }
    TechniqueDef techniqueDef = technique.getDef();
    Renderer renderer = renderManager.getRenderer();
    EnumSet<Caps> rendererCaps = renderer.getCaps();
    if (techniqueDef.isNoRender()) {
        return;
    }
    Shader shader = technique.makeCurrent(renderManager, null, null, null, rendererCaps);
    updateShaderMaterialParameters(renderer, shader, null, null);
    renderManager.getRenderer().setShader(shader);
}
Also used : Renderer(com.jme3.renderer.Renderer) Shader(com.jme3.shader.Shader) Caps(com.jme3.renderer.Caps)

Example 4 with Technique

use of com.jme3.material.Technique 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 5 with Technique

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

the class TechniqueDef method setShaderFile.

/**
     * Sets the shaders that this technique definition will use.
     *
     * @param vertexShader The name of the vertex shader
     * @param fragmentShader The name of the fragment shader
     * @param vertLanguage The vertex shader language
     * @param fragLanguage The fragment shader language
     */
public void setShaderFile(String vertexShader, String fragmentShader, String vertLanguage, String fragLanguage) {
    this.shaderLanguages.put(Shader.ShaderType.Vertex, vertLanguage);
    this.shaderNames.put(Shader.ShaderType.Vertex, vertexShader);
    this.shaderLanguages.put(Shader.ShaderType.Fragment, fragLanguage);
    this.shaderNames.put(Shader.ShaderType.Fragment, fragmentShader);
    requiredCaps.clear();
    Caps vertCap = Caps.valueOf(vertLanguage);
    requiredCaps.add(vertCap);
    Caps fragCap = Caps.valueOf(fragLanguage);
    requiredCaps.add(fragCap);
    weight = Math.max(vertCap.ordinal(), fragCap.ordinal());
}
Also used : Caps(com.jme3.renderer.Caps)

Aggregations

Caps (com.jme3.renderer.Caps)4 Material (com.jme3.material.Material)3 Camera (com.jme3.renderer.Camera)3 Technique (com.jme3.material.Technique)2 Renderer (com.jme3.renderer.Renderer)2 Shader (com.jme3.shader.Shader)2 ShaderType (com.jme3.shader.Shader.ShaderType)2 Texture (com.jme3.texture.Texture)2 Statement (com.jme3.util.blockparser.Statement)2 IOException (java.io.IOException)2 LightList (com.jme3.light.LightList)1 MaterialDef (com.jme3.material.MaterialDef)1 RenderState (com.jme3.material.RenderState)1 ShaderGenerationInfo (com.jme3.material.ShaderGenerationInfo)1 StaticPassLightingLogic (com.jme3.material.logic.StaticPassLightingLogic)1 TechniqueDefLogic (com.jme3.material.logic.TechniqueDefLogic)1 GeometryList (com.jme3.renderer.queue.GeometryList)1 Geometry (com.jme3.scene.Geometry)1 Box (com.jme3.scene.shape.Box)1 DefineList (com.jme3.shader.DefineList)1