use of com.jme3.util.MaterialDebugAppState in project jmonkeyengine by jMonkeyEngine.
the class TestSimpleLighting method simpleInitApp.
@Override
public void simpleInitApp() {
Geometry teapot = (Geometry) assetManager.loadModel("Models/Teapot/Teapot.obj");
TangentBinormalGenerator.generate(teapot.getMesh(), true);
teapot.setLocalScale(2f);
Material mat = new Material(assetManager, "Common/MatDefs/Light/Lighting.j3md");
// mat.selectTechnique("GBuf");
mat.setFloat("Shininess", 25);
mat.setBoolean("UseMaterialColors", true);
cam.setLocation(new Vector3f(0.015041917f, 0.4572918f, 5.2874837f));
cam.setRotation(new Quaternion(-1.8875003E-4f, 0.99882424f, 0.04832061f, 0.0039016632f));
// mat.setTexture("ColorRamp", assetManager.loadTexture("Textures/ColorRamp/cloudy.png"));
//
// mat.setBoolean("VTangent", true);
// mat.setBoolean("Minnaert", true);
// mat.setBoolean("WardIso", true);
// mat.setBoolean("VertexLighting", true);
// mat.setBoolean("LowQuality", true);
// mat.setBoolean("HighQuality", true);
mat.setColor("Ambient", ColorRGBA.Black);
mat.setColor("Diffuse", ColorRGBA.Gray);
mat.setColor("Specular", ColorRGBA.Gray);
teapot.setMaterial(mat);
rootNode.attachChild(teapot);
lightMdl = new Geometry("Light", new Sphere(10, 10, 0.1f));
lightMdl.setMaterial(assetManager.loadMaterial("Common/Materials/RedColor.j3m"));
lightMdl.getMesh().setStatic();
rootNode.attachChild(lightMdl);
pl = new PointLight();
pl.setColor(ColorRGBA.White);
pl.setRadius(4f);
rootNode.addLight(pl);
DirectionalLight dl = new DirectionalLight();
dl.setDirection(new Vector3f(-1, -1, -1).normalizeLocal());
dl.setColor(ColorRGBA.Green);
rootNode.addLight(dl);
MaterialDebugAppState debug = new MaterialDebugAppState();
debug.registerBinding("Common/ShaderLib/BlinnPhongLighting.glsllib", teapot);
stateManager.attach(debug);
setPauseOnLostFocus(false);
flyCam.setDragToRotate(true);
}
use of com.jme3.util.MaterialDebugAppState in project jmonkeyengine by jMonkeyEngine.
the class TestPbrEnv method simpleInitApp.
@Override
public void simpleInitApp() {
assetManager.registerLoader(KTXLoader.class, "ktx");
// put the camera in a bad position
cam.setLocation(new Vector3f(-52.433647f, 68.69636f, -118.60924f));
cam.setRotation(new Quaternion(0.10294232f, 0.25269797f, -0.027049713f, 0.96167296f));
flyCam.setMoveSpeed(100);
loadScene();
dlsr = new DirectionalLightShadowRenderer(assetManager, SHADOWMAP_SIZE, 4);
dlsr.setLight(l);
//dlsr.setLambda(0.55f);
dlsr.setShadowIntensity(0.5f);
dlsr.setEdgeFilteringMode(EdgeFilteringMode.PCFPOISSON);
//dlsr.displayDebug();
// viewPort.addProcessor(dlsr);
FilterPostProcessor fpp = new FilterPostProcessor(assetManager);
fpp.addFilter(new ToneMapFilter(Vector3f.UNIT_XYZ.mult(6.0f)));
SSAOFilter ssao = new SSAOFilter();
ssao.setIntensity(5);
fpp.addFilter(ssao);
BloomFilter bloomFilter = new BloomFilter();
fpp.addFilter(bloomFilter);
fpp.addFilter(new FXAAFilter());
//viewPort.addProcessor(fpp);
initInputs();
// envManager = new EnvironmentManager();
// getStateManager().attach(envManager);
//
envCam = new EnvironmentCamera();
getStateManager().attach(envCam);
debugState = new LightsDebugState();
debugState.setProbeScale(5);
getStateManager().attach(debugState);
camGeom = new Geometry("camGeom", new Sphere(16, 16, 2));
// Material m = new Material(assetManager, "Common/MatDefs/Misc/UnshadedNodes.j3md");
// m.setColor("Color", ColorRGBA.Green);
Material m = assetManager.loadMaterial("jme3test/light/pbr/pbrMat3.j3m");
camGeom.setMaterial(m);
camGeom.setLocalTranslation(0, 20, 0);
camGeom.setLocalScale(5);
rootNode.attachChild(camGeom);
// envManager.setScene(rootNode);
// MaterialDebugAppState debug = new MaterialDebugAppState();
// debug.registerBinding("MatDefs/PBRLighting.frag", rootNode);
// getStateManager().attach(debug);
flyCam.setDragToRotate(true);
setPauseOnLostFocus(false);
// cam.lookAt(camGeom.getWorldTranslation(), Vector3f.UNIT_Y);
}
use of com.jme3.util.MaterialDebugAppState in project jmonkeyengine by jMonkeyEngine.
the class TestManyLightsSingle method reloadScene.
protected void reloadScene(Geometry g, Geometry boxGeo, Node cubeNodes) {
MaterialDebugAppState debug = stateManager.getState(MaterialDebugAppState.class);
Material m = debug.reloadMaterial(g.getMaterial());
if (m != null) {
g.setMaterial(m);
}
m = debug.reloadMaterial(boxGeo.getMaterial());
if (m != null) {
cubeNodes.setMaterial(m);
}
}
use of com.jme3.util.MaterialDebugAppState in project jmonkeyengine by jMonkeyEngine.
the class TestManyLightsSingle method simpleInitApp.
@Override
public void simpleInitApp() {
renderManager.setPreferredLightMode(lm);
renderManager.setSinglePassLightBatchSize(6);
flyCam.setMoveSpeed(10);
Node scene = (Node) assetManager.loadModel("Scenes/ManyLights/Main.scene");
rootNode.attachChild(scene);
Node n = (Node) rootNode.getChild(0);
final LightList lightList = n.getWorldLightList();
final Geometry g = (Geometry) n.getChild("Grid-geom-1");
g.getMaterial().setColor("Ambient", new ColorRGBA(0.2f, 0.2f, 0.2f, 1f));
/* A colored lit cube. Needs light source! */
Box boxMesh = new Box(1f, 1f, 1f);
final Geometry boxGeo = new Geometry("Colored Box", boxMesh);
Material boxMat = g.getMaterial().clone();
boxMat.clearParam("DiffuseMap");
boxMat.setBoolean("UseMaterialColors", true);
boxMat.setColor("Ambient", new ColorRGBA(0.2f, 0.2f, 0.2f, 1f));
boxMat.setColor("Diffuse", ColorRGBA.Blue);
boxGeo.setMaterial(boxMat);
final Node cubeNodes = new Node();
n.attachChild(cubeNodes);
int nb = 0;
for (Light light : lightList) {
nb++;
PointLight p = (PointLight) light;
if (nb > 60) {
n.removeLight(light);
} else {
LightNode ln = new LightNode("l", light);
n.attachChild(ln);
ln.setLocalTranslation(p.getPosition());
int rand = FastMath.nextRandomInt(0, 3);
switch(rand) {
case 0:
light.setColor(ColorRGBA.Red);
// ln.addControl(new MoveControl(5f));
break;
case 1:
light.setColor(ColorRGBA.Yellow);
// ln.addControl(new MoveControl(5f));
break;
case 2:
light.setColor(ColorRGBA.Green);
//ln.addControl(new MoveControl(-5f));
break;
case 3:
light.setColor(ColorRGBA.Orange);
//ln.addControl(new MoveControl(-5f));
break;
}
}
Geometry b = boxGeo.clone(false);
cubeNodes.attachChild(b);
b.setLocalTranslation(p.getPosition().x, 2, p.getPosition().z);
}
// cam.setLocation(new Vector3f(3.1893547f, 17.977385f, 30.8378f));
// cam.setRotation(new Quaternion(0.14317635f, 0.82302624f, -0.23777823f, 0.49557027f));
cam.setLocation(new Vector3f(-1.8901939f, 29.34097f, 73.07533f));
cam.setRotation(new Quaternion(0.0021000702f, 0.971012f, -0.23886925f, 0.008527749f));
BasicProfilerState profiler = new BasicProfilerState(true);
profiler.setGraphScale(1000f);
// getStateManager().attach(profiler);
// guiNode.setCullHint(CullHint.Always);
flyCam.setDragToRotate(true);
flyCam.setMoveSpeed(50);
final MaterialDebugAppState debug = new MaterialDebugAppState();
stateManager.attach(debug);
inputManager.addListener(new ActionListener() {
public void onAction(String name, boolean isPressed, float tpf) {
if (name.equals("toggle") && isPressed) {
if (lm == TechniqueDef.LightMode.SinglePass) {
lm = TechniqueDef.LightMode.MultiPass;
helloText.setText("(Multi pass)");
} else {
lm = TechniqueDef.LightMode.SinglePass;
helloText.setText("(Single pass) nb lights per batch : " + renderManager.getSinglePassLightBatchSize());
}
renderManager.setPreferredLightMode(lm);
reloadScene(g, boxGeo, cubeNodes);
}
if (name.equals("lightsUp") && isPressed) {
renderManager.setSinglePassLightBatchSize(renderManager.getSinglePassLightBatchSize() + 1);
helloText.setText("(Single pass) nb lights per batch : " + renderManager.getSinglePassLightBatchSize());
}
if (name.equals("lightsDown") && isPressed) {
renderManager.setSinglePassLightBatchSize(renderManager.getSinglePassLightBatchSize() - 1);
helloText.setText("(Single pass) nb lights per batch : " + renderManager.getSinglePassLightBatchSize());
}
if (name.equals("toggleOnOff") && isPressed) {
for (final Light light : lightList) {
if (light instanceof AmbientLight) {
continue;
}
light.setEnabled(!light.isEnabled());
}
}
}
}, "toggle", "lightsUp", "lightsDown", "toggleOnOff");
inputManager.addMapping("toggle", new KeyTrigger(KeyInput.KEY_SPACE));
inputManager.addMapping("lightsUp", new KeyTrigger(KeyInput.KEY_UP));
inputManager.addMapping("lightsDown", new KeyTrigger(KeyInput.KEY_DOWN));
inputManager.addMapping("toggleOnOff", new KeyTrigger(KeyInput.KEY_L));
SpotLight spot = new SpotLight();
spot.setDirection(new Vector3f(-1f, -1f, -1f).normalizeLocal());
spot.setColor(ColorRGBA.Blue.mult(5));
spot.setSpotOuterAngle(FastMath.DEG_TO_RAD * 20);
spot.setSpotInnerAngle(FastMath.DEG_TO_RAD * 5);
spot.setPosition(new Vector3f(10, 10, 20));
rootNode.addLight(spot);
DirectionalLight dl = new DirectionalLight();
dl.setDirection(new Vector3f(-1, -1, 1));
rootNode.addLight(dl);
AmbientLight al = new AmbientLight();
al.setColor(new ColorRGBA(0.2f, 0.2f, 0.2f, 1f));
rootNode.addLight(al);
/**
* Write text on the screen (HUD)
*/
guiNode.detachAllChildren();
guiFont = assetManager.loadFont("Interface/Fonts/Default.fnt");
helloText = new BitmapText(guiFont, false);
helloText.setSize(guiFont.getCharSet().getRenderedSize());
helloText.setText("(Single pass) nb lights per batch : " + renderManager.getSinglePassLightBatchSize());
helloText.setLocalTranslation(300, helloText.getLineHeight(), 0);
guiNode.attachChild(helloText);
}
use of com.jme3.util.MaterialDebugAppState in project jmonkeyengine by jMonkeyEngine.
the class TestPBRLighting method simpleInitApp.
@Override
public void simpleInitApp() {
assetManager.registerLoader(KTXLoader.class, "ktx");
viewPort.setBackgroundColor(ColorRGBA.White);
modelNode = (Node) new Node("modelNode");
model = (Geometry) assetManager.loadModel("Models/Tank/tank.j3o");
MikktspaceTangentGenerator.generate(model);
modelNode.attachChild(model);
dl = new DirectionalLight();
dl.setDirection(new Vector3f(-1, -1, -1).normalizeLocal());
rootNode.addLight(dl);
dl.setColor(ColorRGBA.White);
rootNode.attachChild(modelNode);
FilterPostProcessor fpp = new FilterPostProcessor(assetManager);
// fpp.addFilter(new FXAAFilter());
fpp.addFilter(new ToneMapFilter(Vector3f.UNIT_XYZ.mult(4.0f)));
// fpp.addFilter(new SSAOFilter(0.5f, 3, 0.2f, 0.2f));
viewPort.addProcessor(fpp);
//Spatial sky = SkyFactory.createSky(assetManager, "Textures/Sky/Sky_Cloudy.hdr", SkyFactory.EnvMapType.EquirectMap);
Spatial sky = SkyFactory.createSky(assetManager, "Textures/Sky/Path.hdr", SkyFactory.EnvMapType.EquirectMap);
//Spatial sky = SkyFactory.createSky(assetManager, "Textures/Sky/Bright/BrightSky.dds", SkyFactory.EnvMapType.CubeMap);
//Spatial sky = SkyFactory.createSky(assetManager, "Textures/Sky/road.hdr", SkyFactory.EnvMapType.EquirectMap);
rootNode.attachChild(sky);
pbrMat = assetManager.loadMaterial("Models/Tank/tank.j3m");
model.setMaterial(pbrMat);
final EnvironmentCamera envCam = new EnvironmentCamera(128, new Vector3f(0, 3f, 0));
stateManager.attach(envCam);
// EnvironmentManager envManager = new EnvironmentManager();
// stateManager.attach(envManager);
// envManager.setScene(rootNode);
LightsDebugState debugState = new LightsDebugState();
stateManager.attach(debugState);
ChaseCamera chaser = new ChaseCamera(cam, modelNode, inputManager);
chaser.setDragToRotate(true);
chaser.setMinVerticalRotation(-FastMath.HALF_PI);
chaser.setMaxDistance(1000);
chaser.setSmoothMotion(true);
chaser.setRotationSensitivity(10);
chaser.setZoomSensitivity(5);
flyCam.setEnabled(false);
//flyCam.setMoveSpeed(100);
inputManager.addListener(new ActionListener() {
@Override
public void onAction(String name, boolean isPressed, float tpf) {
if (name.equals("debug") && isPressed) {
if (tex == null) {
return;
}
if (tex.getParent() == null && tex2.getParent() == null) {
guiNode.attachChild(tex);
} else if (tex2.getParent() == null) {
tex.removeFromParent();
guiNode.attachChild(tex2);
} else {
tex2.removeFromParent();
}
}
if (name.equals("up") && isPressed) {
model.move(0, tpf * 100f, 0);
}
if (name.equals("down") && isPressed) {
model.move(0, -tpf * 100f, 0);
}
if (name.equals("left") && isPressed) {
model.move(0, 0, tpf * 100f);
}
if (name.equals("right") && isPressed) {
model.move(0, 0, -tpf * 100f);
}
if (name.equals("light") && isPressed) {
dl.setDirection(cam.getDirection().normalize());
}
}
}, "toggle", "light", "up", "down", "left", "right", "debug");
inputManager.addMapping("toggle", new KeyTrigger(KeyInput.KEY_RETURN));
inputManager.addMapping("light", new KeyTrigger(KeyInput.KEY_F));
inputManager.addMapping("up", new KeyTrigger(KeyInput.KEY_UP));
inputManager.addMapping("down", new KeyTrigger(KeyInput.KEY_DOWN));
inputManager.addMapping("left", new KeyTrigger(KeyInput.KEY_LEFT));
inputManager.addMapping("right", new KeyTrigger(KeyInput.KEY_RIGHT));
inputManager.addMapping("debug", new KeyTrigger(KeyInput.KEY_D));
MaterialDebugAppState debug = new MaterialDebugAppState();
debug.registerBinding("Common/MatDefs/Light/PBRLighting.frag", rootNode);
getStateManager().attach(debug);
}
Aggregations