use of com.jme3.texture.Texture.ShadowCompareMode 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();
}
use of com.jme3.texture.Texture.ShadowCompareMode 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);
}
use of com.jme3.texture.Texture.ShadowCompareMode 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);
}
use of com.jme3.texture.Texture.ShadowCompareMode 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);
}
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);
}
Aggregations