Search in sources :

Example 1 with EdgeFilteringMode

use of com.jme3.shadow.EdgeFilteringMode in project jmonkeyengine by jMonkeyEngine.

the class AbstractShadowRendererVR method read.

/**
     * De-serialize this instance, for example when loading from a J3O file.
     *
     * @param im importer (not null)
     */
public void read(JmeImporter im) throws IOException {
    InputCapsule ic = (InputCapsule) im.getCapsule(this);
    assetManager = im.getAssetManager();
    nbShadowMaps = ic.readInt("nbShadowMaps", 1);
    shadowMapSize = ic.readFloat("shadowMapSize", 0f);
    shadowIntensity = ic.readFloat("shadowIntensity", 0.7f);
    edgeFilteringMode = ic.readEnum("edgeFilteringMode", EdgeFilteringMode.class, EdgeFilteringMode.Bilinear);
    shadowCompareMode = ic.readEnum("shadowCompareMode", CompareMode.class, CompareMode.Hardware);
    init(assetManager, nbShadowMaps, (int) shadowMapSize);
    edgesThickness = ic.readFloat("edgesThickness", 1.0f);
    postshadowMat.setFloat("PCFEdge", edgesThickness);
}
Also used : InputCapsule(com.jme3.export.InputCapsule) EdgeFilteringMode(com.jme3.shadow.EdgeFilteringMode) ShadowCompareMode(com.jme3.texture.Texture.ShadowCompareMode) CompareMode(com.jme3.shadow.CompareMode)

Example 2 with EdgeFilteringMode

use of com.jme3.shadow.EdgeFilteringMode in project jmonkeyengine by jMonkeyEngine.

the class AbstractShadowRendererVR method write.

/**
     * Serialize this instance, for example when saving to a J3O file.
     *
     * @param ex exporter (not null)
     */
public void write(JmeExporter ex) throws IOException {
    OutputCapsule oc = (OutputCapsule) ex.getCapsule(this);
    oc.write(nbShadowMaps, "nbShadowMaps", 1);
    oc.write(shadowMapSize, "shadowMapSize", 0);
    oc.write(shadowIntensity, "shadowIntensity", 0.7f);
    oc.write(edgeFilteringMode, "edgeFilteringMode", EdgeFilteringMode.Bilinear);
    oc.write(shadowCompareMode, "shadowCompareMode", CompareMode.Hardware);
    oc.write(edgesThickness, "edgesThickness", 1.0f);
}
Also used : OutputCapsule(com.jme3.export.OutputCapsule)

Example 3 with EdgeFilteringMode

use of com.jme3.shadow.EdgeFilteringMode in project jmonkeyengine by jMonkeyEngine.

the class AbstractShadowRenderer method setShadowCompareMode.

/**
     * Sets the shadow compare mode. See {@link CompareMode} for more info.
     *
     * @param compareMode the desired compare mode (not null)
     */
public final void setShadowCompareMode(CompareMode compareMode) {
    if (compareMode == null) {
        throw new IllegalArgumentException("Shadow compare mode cannot be null");
    }
    this.shadowCompareMode = compareMode;
    for (Texture2D shadowMap : shadowMaps) {
        if (compareMode == CompareMode.Hardware) {
            shadowMap.setShadowCompareMode(ShadowCompareMode.LessOrEqual);
            if (edgeFilteringMode == EdgeFilteringMode.Bilinear) {
                shadowMap.setMagFilter(MagFilter.Bilinear);
                shadowMap.setMinFilter(MinFilter.BilinearNoMipMaps);
            } else {
                shadowMap.setMagFilter(MagFilter.Nearest);
                shadowMap.setMinFilter(MinFilter.NearestNoMipMaps);
            }
        } else {
            shadowMap.setShadowCompareMode(ShadowCompareMode.Off);
            shadowMap.setMagFilter(MagFilter.Nearest);
            shadowMap.setMinFilter(MinFilter.NearestNoMipMaps);
        }
    }
    postshadowMat.setBoolean("HardwareShadows", compareMode == CompareMode.Hardware);
}
Also used : Texture2D(com.jme3.texture.Texture2D)

Example 4 with EdgeFilteringMode

use of com.jme3.shadow.EdgeFilteringMode in project jmonkeyengine by jMonkeyEngine.

the class AbstractShadowRenderer method init.

private void init(AssetManager assetManager, int nbShadowMaps, int shadowMapSize) {
    this.postshadowMat = new Material(assetManager, "Common/MatDefs/Shadow/PostShadow.j3md");
    shadowFB = new FrameBuffer[nbShadowMaps];
    shadowMaps = new Texture2D[nbShadowMaps];
    dispPic = new Picture[nbShadowMaps];
    lightViewProjectionsMatrices = new Matrix4f[nbShadowMaps];
    shadowMapStringCache = new String[nbShadowMaps];
    lightViewStringCache = new String[nbShadowMaps];
    //DO NOT COMMENT THIS (it prevent the OSX incomplete read buffer crash)
    dummyTex = new Texture2D(shadowMapSize, shadowMapSize, Format.RGBA8);
    preshadowMat = new Material(assetManager, "Common/MatDefs/Shadow/PreShadow.j3md");
    postshadowMat.setFloat("ShadowMapSize", shadowMapSize);
    for (int i = 0; i < nbShadowMaps; i++) {
        lightViewProjectionsMatrices[i] = new Matrix4f();
        shadowFB[i] = new FrameBuffer(shadowMapSize, shadowMapSize, 1);
        shadowMaps[i] = new Texture2D(shadowMapSize, shadowMapSize, Format.Depth);
        shadowFB[i].setDepthTexture(shadowMaps[i]);
        //DO NOT COMMENT THIS (it prevent the OSX incomplete read buffer crash)
        shadowFB[i].setColorTexture(dummyTex);
        shadowMapStringCache[i] = "ShadowMap" + i;
        lightViewStringCache[i] = "LightViewProjectionMatrix" + i;
        postshadowMat.setTexture(shadowMapStringCache[i], shadowMaps[i]);
        //quads for debuging purpose
        dispPic[i] = new Picture("Picture" + i);
        dispPic[i].setTexture(assetManager, shadowMaps[i], false);
    }
    setShadowCompareMode(shadowCompareMode);
    setEdgeFilteringMode(edgeFilteringMode);
    setShadowIntensity(shadowIntensity);
    initForcedRenderState();
}
Also used : Texture2D(com.jme3.texture.Texture2D) Matrix4f(com.jme3.math.Matrix4f) Picture(com.jme3.ui.Picture) Material(com.jme3.material.Material) FrameBuffer(com.jme3.texture.FrameBuffer)

Example 5 with EdgeFilteringMode

use of com.jme3.shadow.EdgeFilteringMode in project jmonkeyengine by jMonkeyEngine.

the class AbstractShadowRenderer method read.

/**
     * De-serialize this instance, for example when loading from a J3O file.
     *
     * @param im importer (not null)
     */
public void read(JmeImporter im) throws IOException {
    InputCapsule ic = im.getCapsule(this);
    assetManager = im.getAssetManager();
    nbShadowMaps = ic.readInt("nbShadowMaps", 1);
    shadowMapSize = ic.readFloat("shadowMapSize", 0f);
    shadowIntensity = ic.readFloat("shadowIntensity", 0.7f);
    edgeFilteringMode = ic.readEnum("edgeFilteringMode", EdgeFilteringMode.class, EdgeFilteringMode.Bilinear);
    shadowCompareMode = ic.readEnum("shadowCompareMode", CompareMode.class, CompareMode.Hardware);
    init(assetManager, nbShadowMaps, (int) shadowMapSize);
    edgesThickness = ic.readFloat("edgesThickness", 1.0f);
    postshadowMat.setFloat("PCFEdge", edgesThickness);
}
Also used : InputCapsule(com.jme3.export.InputCapsule) ShadowCompareMode(com.jme3.texture.Texture.ShadowCompareMode)

Aggregations

Texture2D (com.jme3.texture.Texture2D)6 InputCapsule (com.jme3.export.InputCapsule)2 OutputCapsule (com.jme3.export.OutputCapsule)2 Material (com.jme3.material.Material)2 Matrix4f (com.jme3.math.Matrix4f)2 EdgeFilteringMode (com.jme3.shadow.EdgeFilteringMode)2 FrameBuffer (com.jme3.texture.FrameBuffer)2 ShadowCompareMode (com.jme3.texture.Texture.ShadowCompareMode)2 Picture (com.jme3.ui.Picture)2 CompareMode (com.jme3.shadow.CompareMode)1