use of com.jme3.texture.Texture2D in project jmonkeyengine by jMonkeyEngine.
the class TestNiftyToMesh method simpleInitApp.
public void simpleInitApp() {
ViewPort niftyView = renderManager.createPreView("NiftyView", new Camera(1024, 768));
niftyView.setClearFlags(true, true, true);
NiftyJmeDisplay niftyDisplay = new NiftyJmeDisplay(assetManager, inputManager, audioRenderer, niftyView);
nifty = niftyDisplay.getNifty();
nifty.fromXml("all/intro.xml", "start");
niftyView.addProcessor(niftyDisplay);
Texture2D depthTex = new Texture2D(1024, 768, Format.Depth);
FrameBuffer fb = new FrameBuffer(1024, 768, 1);
fb.setDepthTexture(depthTex);
Texture2D tex = new Texture2D(1024, 768, Format.RGBA8);
tex.setMinFilter(MinFilter.Trilinear);
tex.setMagFilter(MagFilter.Bilinear);
fb.setColorTexture(tex);
niftyView.setClearFlags(true, true, true);
niftyView.setOutputFrameBuffer(fb);
Box b = new Box(1, 1, 1);
Geometry geom = new Geometry("Box", b);
Material mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
mat.setTexture("ColorMap", tex);
geom.setMaterial(mat);
rootNode.attachChild(geom);
}
use of com.jme3.texture.Texture2D in project jmonkeyengine by jMonkeyEngine.
the class TestLoadKtx method simpleInitApp.
@Override
public void simpleInitApp() {
viewPort.setBackgroundColor(ColorRGBA.DarkGray);
assetManager.registerLoader(KTXLoader.class, "ktx");
Texture2D t = (Texture2D) assetManager.loadTexture("Textures/ktx/down-reference.ktx");
Picture p = new Picture("bla", false);
p.setTexture(assetManager, t, false);
p.setLocalTranslation(200, 200, 0);
p.setWidth(t.getImage().getWidth());
p.setHeight(t.getImage().getHeight());
guiNode.attachChild(p);
Texture2D t2 = (Texture2D) assetManager.loadTexture("Textures/ktx/up-reference.ktx");
Picture p2 = new Picture("bla", false);
p2.setTexture(assetManager, t2, false);
p2.setLocalTranslation(400, 200, 0);
p2.setWidth(t2.getImage().getWidth());
p2.setHeight(t2.getImage().getHeight());
guiNode.attachChild(p2);
Texture2D t3 = (Texture2D) assetManager.loadTexture("Textures/ktx/rgba-reference.ktx");
Picture p3 = new Picture("bla", false);
p3.setTexture(assetManager, t3, false);
p3.setLocalTranslation(200, 400, 0);
p3.setWidth(t3.getImage().getWidth());
p3.setHeight(t3.getImage().getHeight());
guiNode.attachChild(p3);
Texture2D t4 = (Texture2D) assetManager.loadTexture("Textures/ktx/rgb-amg-reference.ktx");
Picture p4 = new Picture("bla", false);
p4.setTexture(assetManager, t4, false);
p4.setLocalTranslation(400, 400, 0);
p4.setWidth(t4.getImage().getWidth());
p4.setHeight(t4.getImage().getHeight());
guiNode.attachChild(p4);
flyCam.setDragToRotate(true);
}
use of com.jme3.texture.Texture2D in project jmonkeyengine by jMonkeyEngine.
the class TestMultiPostWater method simpleInitApp.
@Override
public void simpleInitApp() {
// setDisplayFps(false);
// setDisplayStatView(false);
Node mainScene = new Node("Main Scene");
rootNode.attachChild(mainScene);
createTerrain(mainScene);
DirectionalLight sun = new DirectionalLight();
sun.setDirection(lightDir);
sun.setColor(ColorRGBA.White.clone().multLocal(1.7f));
mainScene.addLight(sun);
flyCam.setMoveSpeed(100);
//cam.setLocation(new Vector3f(-700, 100, 300));
//cam.setRotation(new Quaternion().fromAngleAxis(0.5f, Vector3f.UNIT_Z));
cam.setLocation(new Vector3f(-327.21957f, 251.6459f, 126.884346f));
cam.setRotation(new Quaternion().fromAngles(new float[] { FastMath.PI * 0.06f, FastMath.PI * 0.65f, 0 }));
Spatial sky = SkyFactory.createSky(assetManager, "Scenes/Beach/FullskiesSunset0068.dds", false);
sky.setLocalScale(350);
mainScene.attachChild(sky);
cam.setFrustumFar(4000);
FilterPostProcessor fpp = new FilterPostProcessor(assetManager);
water = new WaterFilter(rootNode, lightDir);
water.setCenter(new Vector3f(9.628218f, -15.830074f, 199.23595f));
water.setRadius(260);
water.setWaveScale(0.003f);
water.setMaxAmplitude(2f);
water.setFoamExistence(new Vector3f(1f, 4, 0.5f));
water.setFoamTexture((Texture2D) assetManager.loadTexture("Common/MatDefs/Water/Textures/foam2.jpg"));
water.setRefractionStrength(0.2f);
water.setWaterHeight(WATER_HEIGHT);
fpp.addFilter(water);
WaterFilter water2 = new WaterFilter(rootNode, lightDir);
water2.setCenter(new Vector3f(-280.46027f, -24.971727f, -271.71976f));
water2.setRadius(260);
water2.setWaterHeight(WATER_HEIGHT);
water2.setUseFoam(false);
water2.setUseRipples(false);
water2.setDeepWaterColor(ColorRGBA.Brown);
water2.setWaterColor(ColorRGBA.Brown.mult(2.0f));
water2.setWaterTransparency(0.2f);
water2.setMaxAmplitude(0.3f);
water2.setWaveScale(0.008f);
water2.setSpeed(0.7f);
water2.setShoreHardness(1.0f);
water2.setRefractionConstant(0.2f);
water2.setShininess(0.3f);
water2.setSunScale(1.0f);
water2.setColorExtinction(new Vector3f(10.0f, 20.0f, 30.0f));
fpp.addFilter(water2);
WaterFilter water3 = new WaterFilter(rootNode, lightDir);
water3.setCenter(new Vector3f(319.6663f, -18.367947f, -236.67674f));
water3.setRadius(260);
water3.setWaterHeight(WATER_HEIGHT);
water3.setWaveScale(0.003f);
water3.setMaxAmplitude(2f);
water3.setFoamExistence(new Vector3f(1f, 4, 0.5f));
water3.setFoamTexture((Texture2D) assetManager.loadTexture("Common/MatDefs/Water/Textures/foam2.jpg"));
water3.setRefractionStrength(0.2f);
water3.setDeepWaterColor(ColorRGBA.Red);
water3.setWaterColor(ColorRGBA.Red.mult(2.0f));
water3.setLightColor(ColorRGBA.Red);
fpp.addFilter(water3);
viewPort.addProcessor(fpp);
//fpp.setNumSamples(4);
}
use of com.jme3.texture.Texture2D in project jmonkeyengine by jMonkeyEngine.
the class TestPostWater method simpleInitApp.
@Override
public void simpleInitApp() {
setDisplayFps(false);
setDisplayStatView(false);
Node mainScene = new Node("Main Scene");
rootNode.attachChild(mainScene);
createTerrain(mainScene);
DirectionalLight sun = new DirectionalLight();
sun.setDirection(lightDir);
sun.setColor(ColorRGBA.White.clone().multLocal(1f));
mainScene.addLight(sun);
AmbientLight al = new AmbientLight();
al.setColor(new ColorRGBA(0.1f, 0.1f, 0.1f, 1.0f));
mainScene.addLight(al);
flyCam.setMoveSpeed(50);
//cam.setLocation(new Vector3f(-700, 100, 300));
//cam.setRotation(new Quaternion().fromAngleAxis(0.5f, Vector3f.UNIT_Z));
// cam.setLocation(new Vector3f(-327.21957f, 61.6459f, 126.884346f));
// cam.setRotation(new Quaternion(0.052168474f, 0.9443102f, -0.18395276f, 0.2678024f));
cam.setLocation(new Vector3f(-370.31592f, 182.04016f, 196.81192f));
cam.setRotation(new Quaternion(0.015302252f, 0.9304095f, -0.039101653f, 0.3641086f));
Spatial sky = SkyFactory.createSky(assetManager, "Scenes/Beach/FullskiesSunset0068.dds", false);
sky.setLocalScale(350);
mainScene.attachChild(sky);
cam.setFrustumFar(4000);
//Water Filter
water = new WaterFilter(rootNode, lightDir);
water.setWaterColor(new ColorRGBA().setAsSrgb(0.0078f, 0.3176f, 0.5f, 1.0f));
water.setDeepWaterColor(new ColorRGBA().setAsSrgb(0.0039f, 0.00196f, 0.145f, 1.0f));
water.setUnderWaterFogDistance(80);
water.setWaterTransparency(0.12f);
water.setFoamIntensity(0.4f);
water.setFoamHardness(0.3f);
water.setFoamExistence(new Vector3f(0.8f, 8f, 1f));
water.setReflectionDisplace(50);
water.setRefractionConstant(0.25f);
water.setColorExtinction(new Vector3f(30, 50, 70));
water.setCausticsIntensity(0.4f);
water.setWaveScale(0.003f);
water.setMaxAmplitude(2f);
water.setFoamTexture((Texture2D) assetManager.loadTexture("Common/MatDefs/Water/Textures/foam2.jpg"));
water.setRefractionStrength(0.2f);
water.setWaterHeight(initialWaterHeight);
//Bloom Filter
BloomFilter bloom = new BloomFilter();
bloom.setExposurePower(55);
bloom.setBloomIntensity(1.0f);
//Light Scattering Filter
LightScatteringFilter lsf = new LightScatteringFilter(lightDir.mult(-300));
lsf.setLightDensity(0.5f);
//Depth of field Filter
DepthOfFieldFilter dof = new DepthOfFieldFilter();
dof.setFocusDistance(0);
dof.setFocusRange(100);
FilterPostProcessor fpp = new FilterPostProcessor(assetManager);
fpp.addFilter(water);
fpp.addFilter(bloom);
fpp.addFilter(dof);
fpp.addFilter(lsf);
fpp.addFilter(new FXAAFilter());
// fpp.addFilter(new TranslucentBucketFilter());
int numSamples = getContext().getSettings().getSamples();
if (numSamples > 0) {
fpp.setNumSamples(numSamples);
}
uw = cam.getLocation().y < waterHeight;
waves = new AudioNode(assetManager, "Sound/Environment/Ocean Waves.ogg", false);
waves.setLooping(true);
waves.setReverbEnabled(true);
if (uw) {
waves.setDryFilter(new LowPassFilter(0.5f, 0.1f));
} else {
waves.setDryFilter(aboveWaterAudioFilter);
}
audioRenderer.playSource(waves);
//
viewPort.addProcessor(fpp);
inputManager.addListener(new ActionListener() {
public void onAction(String name, boolean isPressed, float tpf) {
if (isPressed) {
if (name.equals("foam1")) {
water.setFoamTexture((Texture2D) assetManager.loadTexture("Common/MatDefs/Water/Textures/foam.jpg"));
}
if (name.equals("foam2")) {
water.setFoamTexture((Texture2D) assetManager.loadTexture("Common/MatDefs/Water/Textures/foam2.jpg"));
}
if (name.equals("foam3")) {
water.setFoamTexture((Texture2D) assetManager.loadTexture("Common/MatDefs/Water/Textures/foam3.jpg"));
}
if (name.equals("upRM")) {
water.setReflectionMapSize(Math.min(water.getReflectionMapSize() * 2, 4096));
System.out.println("Reflection map size : " + water.getReflectionMapSize());
}
if (name.equals("downRM")) {
water.setReflectionMapSize(Math.max(water.getReflectionMapSize() / 2, 32));
System.out.println("Reflection map size : " + water.getReflectionMapSize());
}
}
}
}, "foam1", "foam2", "foam3", "upRM", "downRM");
inputManager.addMapping("foam1", new KeyTrigger(KeyInput.KEY_1));
inputManager.addMapping("foam2", new KeyTrigger(KeyInput.KEY_2));
inputManager.addMapping("foam3", new KeyTrigger(KeyInput.KEY_3));
inputManager.addMapping("upRM", new KeyTrigger(KeyInput.KEY_PGUP));
inputManager.addMapping("downRM", new KeyTrigger(KeyInput.KEY_PGDN));
// createBox();
// createFire();
}
use of com.jme3.texture.Texture2D in project jmonkeyengine by jMonkeyEngine.
the class TestAnisotropicFilter method createCheckerBoardTexture.
private static Texture2D createCheckerBoardTexture() {
Image image = new Image(Format.RGBA8, 1024, 1024, BufferUtils.createByteBuffer(1024 * 1024 * 4), ColorSpace.sRGB);
ImageRaster raster = ImageRaster.create(image);
for (int y = 0; y < 1024; y++) {
for (int x = 0; x < 1024; x++) {
if (y < 512) {
if (x < 512) {
raster.setPixel(x, y, ColorRGBA.Black);
} else {
raster.setPixel(x, y, ColorRGBA.White);
}
} else {
if (x < 512) {
raster.setPixel(x, y, ColorRGBA.White);
} else {
raster.setPixel(x, y, ColorRGBA.Black);
}
}
}
}
return new Texture2D(image);
}
Aggregations