use of com.jme3.texture.Texture2D 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);
}
}
}
}
use of com.jme3.texture.Texture2D in project jmonkeyengine by jMonkeyEngine.
the class AbstractShadowRendererVR 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.Texture2D in project jmonkeyengine by jMonkeyEngine.
the class AbstractShadowRendererVR 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);
}
use of com.jme3.texture.Texture2D in project jmonkeyengine by jMonkeyEngine.
the class VRViewManagerOpenVR method setupFinalFullTexture.
private void setupFinalFullTexture(Camera cam) {
if (environment != null) {
if (environment.getApplication() != null) {
// create offscreen framebuffer
FrameBuffer out = new FrameBuffer(cam.getWidth(), cam.getHeight(), 1);
//offBuffer.setSrgb(true);
//setup framebuffer's texture
dualEyeTex = new Texture2D(cam.getWidth(), cam.getHeight(), Image.Format.RGBA8);
dualEyeTex.setMinFilter(Texture.MinFilter.BilinearNoMipMaps);
dualEyeTex.setMagFilter(Texture.MagFilter.Bilinear);
logger.config("Dual eye texture " + dualEyeTex.getName() + " (" + dualEyeTex.getImage().getId() + ")");
logger.config(" Type: " + dualEyeTex.getType());
logger.config(" Size: " + dualEyeTex.getImage().getWidth() + "x" + dualEyeTex.getImage().getHeight());
logger.config(" Image depth: " + dualEyeTex.getImage().getDepth());
logger.config(" Image format: " + dualEyeTex.getImage().getFormat());
logger.config(" Image color space: " + dualEyeTex.getImage().getColorSpace());
//setup framebuffer to use texture
out.setDepthBuffer(Image.Format.Depth);
out.setColorTexture(dualEyeTex);
ViewPort viewPort = environment.getApplication().getViewPort();
viewPort.setClearFlags(true, true, true);
viewPort.setBackgroundColor(ColorRGBA.Black);
viewPort.setOutputFrameBuffer(out);
} else {
throw new IllegalStateException("This VR environment is not attached to any application.");
}
} else {
throw new IllegalStateException("This VR view manager is not attached to any VR environment.");
}
}
use of com.jme3.texture.Texture2D in project chordatlas by twak.
the class SkelFootprint method getColor.
public static ColorRGBA getColor(Geometry geom, Vector3f pt, int index, Tweed tweed) {
MatParam param = geom.getMaterial().getParam("DiffuseMap");
ImageRaster ir = ImageRaster.create(tweed.getAssetManager().loadTexture(((Texture2D) param.getValue()).getName()).getImage());
Mesh mesh = geom.getMesh();
// geom.getMaterial().getMaterialDef().
VertexBuffer pb = mesh.getBuffer(Type.Position);
VertexBuffer tb = mesh.getBuffer(Type.TexCoord);
IndexBuffer ib = mesh.getIndicesAsList();
Vector2f uva = new Vector2f(), uvb = new Vector2f(), uvc = new Vector2f();
Vector3f la = new Vector3f(), lb = new Vector3f(), lc = new Vector3f();
if (pb != null && pb.getFormat() == Format.Float && pb.getNumComponents() == 3) {
FloatBuffer fpb = (FloatBuffer) pb.getData();
FloatBuffer ftb = (FloatBuffer) tb.getData();
// aquire triangle's vertex indices
int vertIndex = index * 3;
int va = ib.get(vertIndex);
int vb = ib.get(vertIndex + 1);
int vc = ib.get(vertIndex + 2);
BufferUtils.populateFromBuffer(la, fpb, va);
BufferUtils.populateFromBuffer(lb, fpb, vb);
BufferUtils.populateFromBuffer(lc, fpb, vc);
BufferUtils.populateFromBuffer(uva, ftb, va);
BufferUtils.populateFromBuffer(uvb, ftb, vb);
BufferUtils.populateFromBuffer(uvc, ftb, vc);
// PaintThing.debug.put(1, new Line ( la.x, la.z, lb.x, lb.z) );
// PaintThing.debug.put(2, new Line ( lb.x, lb.z, lc.x, lc.z) );
// PaintThing.debug.put(3, new Line ( lc.x, lc.z, la.x, la.z) );
float[] bary = barycentric(pt, la, lb, lc);
int x = (int) ((uva.x * bary[0] + uvb.x * bary[1] + uvc.x * bary[2]) * ir.getWidth()), y = (int) ((uva.y * bary[0] + uvb.y * bary[1] + uvc.y * bary[2]) * ir.getHeight());
// ir.getHeight() - y -1 );
ColorRGBA out = ir.getPixel(x, y);
return out;
} else {
throw new UnsupportedOperationException("Position buffer not set or has incompatible format");
}
}
Aggregations