Search in sources :

Example 6 with ShadowCompareMode

use of com.jme3.texture.Texture.ShadowCompareMode in project jmonkeyengine by jMonkeyEngine.

the class AbstractShadowRenderer 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 = 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 7 with ShadowCompareMode

use of com.jme3.texture.Texture.ShadowCompareMode in project jmonkeyengine by jMonkeyEngine.

the class AbstractShadowRenderer method setMatParams.

private void setMatParams(GeometryList l) {
    //iteration throught all the geometries of the list to gather the materials
    buildMatCache(l);
    //iterating through the mat cache and setting the parameters
    for (Material mat : matCache) {
        mat.setFloat("ShadowMapSize", shadowMapSize);
        for (int j = 0; j < nbShadowMaps; j++) {
            mat.setMatrix4(lightViewStringCache[j], lightViewProjectionsMatrices[j]);
        }
        for (int j = 0; j < nbShadowMaps; j++) {
            mat.setTexture(shadowMapStringCache[j], shadowMaps[j]);
        }
        mat.setBoolean("HardwareShadows", shadowCompareMode == CompareMode.Hardware);
        mat.setInt("FilterMode", edgeFilteringMode.getMaterialParamValue());
        mat.setFloat("PCFEdge", edgesThickness);
        mat.setFloat("ShadowIntensity", shadowIntensity);
        if (fadeInfo != null) {
            mat.setVector2("FadeInfo", fadeInfo);
        }
        if (renderBackFacesShadows != null) {
            mat.setBoolean("BackfaceShadows", renderBackFacesShadows);
        }
        setMaterialParameters(mat);
    }
    //so we fall back to the forced material solution (transparent shadows won't be supported for these objects)
    if (needsfallBackMaterial) {
        setPostShadowParams();
    }
}
Also used : Material(com.jme3.material.Material)

Example 8 with ShadowCompareMode

use of com.jme3.texture.Texture.ShadowCompareMode in project jmonkeyengine by jMonkeyEngine.

the class GLRenderer method setupTextureParams.

@SuppressWarnings("fallthrough")
private void setupTextureParams(int unit, Texture tex) {
    Image image = tex.getImage();
    int target = convertTextureType(tex.getType(), image != null ? image.getMultiSamples() : 1, -1);
    boolean haveMips = true;
    if (image != null) {
        haveMips = image.isGeneratedMipmapsRequired() || image.hasMipmaps();
    }
    LastTextureState curState = image.getLastTextureState();
    if (curState.magFilter != tex.getMagFilter()) {
        bindTextureAndUnit(target, image, unit);
        gl.glTexParameteri(target, GL.GL_TEXTURE_MAG_FILTER, convertMagFilter(tex.getMagFilter()));
        curState.magFilter = tex.getMagFilter();
    }
    if (curState.minFilter != tex.getMinFilter()) {
        bindTextureAndUnit(target, image, unit);
        gl.glTexParameteri(target, GL.GL_TEXTURE_MIN_FILTER, convertMinFilter(tex.getMinFilter(), haveMips));
        curState.minFilter = tex.getMinFilter();
    }
    int desiredAnisoFilter = tex.getAnisotropicFilter() == 0 ? defaultAnisotropicFilter : tex.getAnisotropicFilter();
    if (caps.contains(Caps.TextureFilterAnisotropic) && curState.anisoFilter != desiredAnisoFilter) {
        bindTextureAndUnit(target, image, unit);
        gl.glTexParameterf(target, GLExt.GL_TEXTURE_MAX_ANISOTROPY_EXT, desiredAnisoFilter);
        curState.anisoFilter = desiredAnisoFilter;
    }
    switch(tex.getType()) {
        case ThreeDimensional:
        case // cubemaps use 3D coords
        CubeMap:
            if (gl2 != null && curState.rWrap != tex.getWrap(WrapAxis.R)) {
                bindTextureAndUnit(target, image, unit);
                gl2.glTexParameteri(target, GL2.GL_TEXTURE_WRAP_R, convertWrapMode(tex.getWrap(WrapAxis.R)));
                curState.rWrap = tex.getWrap(WrapAxis.R);
            }
        //There is no break statement on purpose here
        case TwoDimensional:
        case TwoDimensionalArray:
            if (curState.tWrap != tex.getWrap(WrapAxis.T)) {
                bindTextureAndUnit(target, image, unit);
                gl.glTexParameteri(target, GL.GL_TEXTURE_WRAP_T, convertWrapMode(tex.getWrap(WrapAxis.T)));
                image.getLastTextureState().tWrap = tex.getWrap(WrapAxis.T);
            }
            if (curState.sWrap != tex.getWrap(WrapAxis.S)) {
                bindTextureAndUnit(target, image, unit);
                gl.glTexParameteri(target, GL.GL_TEXTURE_WRAP_S, convertWrapMode(tex.getWrap(WrapAxis.S)));
                curState.sWrap = tex.getWrap(WrapAxis.S);
            }
            break;
        default:
            throw new UnsupportedOperationException("Unknown texture type: " + tex.getType());
    }
    ShadowCompareMode texCompareMode = tex.getShadowCompareMode();
    if (gl2 != null && curState.shadowCompareMode != texCompareMode) {
        bindTextureAndUnit(target, image, unit);
        if (texCompareMode != ShadowCompareMode.Off) {
            gl2.glTexParameteri(target, GL2.GL_TEXTURE_COMPARE_MODE, GL2.GL_COMPARE_REF_TO_TEXTURE);
            if (texCompareMode == ShadowCompareMode.GreaterOrEqual) {
                gl2.glTexParameteri(target, GL2.GL_TEXTURE_COMPARE_FUNC, GL.GL_GEQUAL);
            } else {
                gl2.glTexParameteri(target, GL2.GL_TEXTURE_COMPARE_FUNC, GL.GL_LEQUAL);
            }
        } else {
            gl2.glTexParameteri(target, GL2.GL_TEXTURE_COMPARE_MODE, GL.GL_NONE);
        }
        curState.shadowCompareMode = texCompareMode;
    }
    // If at this point we didn't bind the texture, bind it now
    bindTextureOnly(target, image, unit);
}
Also used : ShadowCompareMode(com.jme3.texture.Texture.ShadowCompareMode) LastTextureState(com.jme3.texture.image.LastTextureState) Image(com.jme3.texture.Image)

Example 9 with ShadowCompareMode

use of com.jme3.texture.Texture.ShadowCompareMode in project jmonkeyengine by jMonkeyEngine.

the class AbstractShadowRendererVR method setMatParams.

private void setMatParams(GeometryList l) {
    //iteration throught all the geometries of the list to gather the materials
    buildMatCache(l);
    //iterating through the mat cache and setting the parameters
    for (Material mat : matCache) {
        mat.setFloat("ShadowMapSize", shadowMapSize);
        for (int j = 0; j < nbShadowMaps; j++) {
            mat.setMatrix4(lightViewStringCache[j], lightViewProjectionsMatrices[j]);
        }
        for (int j = 0; j < nbShadowMaps; j++) {
            mat.setTexture(shadowMapStringCache[j], shadowMaps[j]);
        }
        mat.setBoolean("HardwareShadows", shadowCompareMode == CompareMode.Hardware);
        mat.setInt("FilterMode", edgeFilteringMode.getMaterialParamValue());
        mat.setFloat("PCFEdge", edgesThickness);
        mat.setFloat("ShadowIntensity", shadowIntensity);
        if (fadeInfo != null) {
            mat.setVector2("FadeInfo", fadeInfo);
        }
        if (renderBackFacesShadows != null) {
            mat.setBoolean("BackfaceShadows", renderBackFacesShadows);
        }
        setMaterialParameters(mat);
    }
    //so we fall back to the forced material solution (transparent shadows won't be supported for these objects)
    if (needsfallBackMaterial) {
        setPostShadowParams();
    }
}
Also used : Material(com.jme3.material.Material)

Example 10 with ShadowCompareMode

use of com.jme3.texture.Texture.ShadowCompareMode in project jmonkeyengine by jMonkeyEngine.

the class AbstractShadowRendererVR method setEdgeFilteringMode.

/**
     * Sets the filtering mode for shadow edges. See {@link EdgeFilteringMode}
     * for more info.
     *
     * @param filterMode the desired filter mode (not null)
     */
public final void setEdgeFilteringMode(EdgeFilteringMode filterMode) {
    if (filterMode == null) {
        throw new NullPointerException();
    }
    this.edgeFilteringMode = filterMode;
    postshadowMat.setInt("FilterMode", filterMode.getMaterialParamValue());
    postshadowMat.setFloat("PCFEdge", edgesThickness);
    if (shadowCompareMode == CompareMode.Hardware) {
        for (Texture2D shadowMap : shadowMaps) {
            if (filterMode == EdgeFilteringMode.Bilinear) {
                shadowMap.setMagFilter(MagFilter.Bilinear);
                shadowMap.setMinFilter(MinFilter.BilinearNoMipMaps);
            } else {
                shadowMap.setMagFilter(MagFilter.Nearest);
                shadowMap.setMinFilter(MinFilter.NearestNoMipMaps);
            }
        }
    }
}
Also used : Texture2D(com.jme3.texture.Texture2D)

Aggregations

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