use of com.jme3.post.Filter.Pass in project jmonkeyengine by jMonkeyEngine.
the class CartoonEdgeFilter method initFilter.
@Override
protected void initFilter(AssetManager manager, RenderManager renderManager, ViewPort vp, int w, int h) {
this.renderManager = renderManager;
this.viewPort = vp;
normalPass = new Pass();
normalPass.init(renderManager.getRenderer(), w, h, Format.RGBA8, Format.Depth);
material = new Material(manager, "Common/MatDefs/Post/CartoonEdge.j3md");
material.setFloat("EdgeWidth", edgeWidth);
material.setFloat("EdgeIntensity", edgeIntensity);
material.setFloat("NormalThreshold", normalThreshold);
material.setFloat("DepthThreshold", depthThreshold);
material.setFloat("NormalSensitivity", normalSensitivity);
material.setFloat("DepthSensitivity", depthSensitivity);
material.setColor("EdgeColor", edgeColor);
}
use of com.jme3.post.Filter.Pass 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.post.Filter.Pass in project jmonkeyengine by jMonkeyEngine.
the class TestTwoSideLighting method simpleInitApp.
@Override
public void simpleInitApp() {
// Two-sided lighting requires single pass.
renderManager.setPreferredLightMode(TechniqueDef.LightMode.SinglePass);
renderManager.setSinglePassLightBatchSize(4);
cam.setLocation(new Vector3f(5.936224f, 3.3759952f, -3.3202777f));
cam.setRotation(new Quaternion(0.16265652f, -0.4811838f, 0.09137692f, 0.8565368f));
Geometry quadGeom = new Geometry("quad", new Quad(1, 1));
quadGeom.move(1, 0, 0);
Material mat1 = assetManager.loadMaterial("Textures/BumpMapTest/SimpleBump.j3m");
// Display both front and back faces.
mat1.getAdditionalRenderState().setFaceCullMode(RenderState.FaceCullMode.Off);
quadGeom.setMaterial(mat1);
// SimpleBump material requires tangents.
TangentBinormalGenerator.generate(quadGeom);
rootNode.attachChild(quadGeom);
Geometry teapot = (Geometry) assetManager.loadModel("Models/Teapot/Teapot.obj");
teapot.move(-1, 0, 0);
teapot.setLocalScale(2f);
Material mat2 = new Material(assetManager, "Common/MatDefs/Light/Lighting.j3md");
mat2.setFloat("Shininess", 25);
mat2.setBoolean("UseMaterialColors", true);
mat2.setColor("Ambient", ColorRGBA.Black);
mat2.setColor("Diffuse", ColorRGBA.Gray);
mat2.setColor("Specular", ColorRGBA.Gray);
// Only display backfaces.
mat2.getAdditionalRenderState().setFaceCullMode(RenderState.FaceCullMode.Front);
teapot.setMaterial(mat2);
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);
}
use of com.jme3.post.Filter.Pass in project jmonkeyengine by jMonkeyEngine.
the class TestMultiRenderTarget method reshape.
public void reshape(ViewPort vp, int w, int h) {
diffuseData = new Texture2D(w, h, Format.RGBA8);
normalData = new Texture2D(w, h, Format.RGBA8);
specularData = new Texture2D(w, h, Format.RGBA8);
depthData = new Texture2D(w, h, Format.Depth);
mat = new Material(assetManager, "Common/MatDefs/Light/Deferred.j3md");
mat.setTexture("DiffuseData", diffuseData);
mat.setTexture("SpecularData", specularData);
mat.setTexture("NormalData", normalData);
mat.setTexture("DepthData", depthData);
display.setMaterial(mat);
display.setPosition(0, 0);
display.setWidth(w);
display.setHeight(h);
display1.setTexture(assetManager, diffuseData, false);
display2.setTexture(assetManager, normalData, false);
display3.setTexture(assetManager, specularData, false);
display4.setTexture(assetManager, depthData, false);
display1.setPosition(0, 0);
display2.setPosition(w / 2, 0);
display3.setPosition(0, h / 2);
display4.setPosition(w / 2, h / 2);
display1.setWidth(w / 2);
display1.setHeight(h / 2);
display2.setWidth(w / 2);
display2.setHeight(h / 2);
display3.setWidth(w / 2);
display3.setHeight(h / 2);
display4.setWidth(w / 2);
display4.setHeight(h / 2);
guiNode.updateGeometricState();
fb = new FrameBuffer(w, h, 1);
fb.setDepthTexture(depthData);
fb.addColorTexture(diffuseData);
fb.addColorTexture(normalData);
fb.addColorTexture(specularData);
fb.setMultiTarget(true);
/*
* Marks pixels in front of the far light boundary
Render back-faces of light volume
Depth test GREATER-EQUAL
Write to stencil on depth pass
Skipped for very small distant lights
*/
/*
* Find amount of lit pixels inside the volume
Start pixel query
Render front faces of light volume
Depth test LESS-EQUAL
Don’t write anything – only EQUAL stencil test
*/
/*
* Enable conditional rendering
Based on query results from previous stage
GPU skips rendering for invisible lights
*/
/*
* Render front-faces of light volume
Depth test - LESS-EQUAL
Stencil test - EQUAL
Runs only on marked pixels inside light
*/
}
use of com.jme3.post.Filter.Pass in project jmonkeyengine by jMonkeyEngine.
the class SceneLoader method load.
public Object load(AssetInfo info) throws IOException {
try {
key = info.getKey();
assetManager = info.getManager();
sceneName = key.getName();
String ext = key.getExtension();
folderName = key.getFolder();
sceneName = sceneName.substring(0, sceneName.length() - ext.length() - 1);
reset();
// == Run 1st pass over XML file to determine material list ==
materialList = materialLoader.load(assetManager, folderName, info.openStream());
if (materialList == null || materialList.isEmpty()) {
// NOTE: No materials were found by searching the externals section.
// Try finding a similarly named material file in the same folder.
// (Backward compatibility only!)
OgreMaterialKey materialKey = new OgreMaterialKey(sceneName + ".material");
try {
materialList = (MaterialList) assetManager.loadAsset(materialKey);
} catch (AssetNotFoundException ex) {
logger.log(Level.WARNING, "Cannot locate {0} for scene {1}", new Object[] { materialKey, key });
materialList = null;
}
}
// == Run 2nd pass to load entities and other objects ==
// Added by larynx 25.06.2011
// Android needs the namespace aware flag set to true
// Kirill 30.06.2011
// Now, hack is applied for both desktop and android to avoid
// checking with JmeSystem.
SAXParserFactory factory = SAXParserFactory.newInstance();
factory.setNamespaceAware(true);
XMLReader xr = factory.newSAXParser().getXMLReader();
xr.setContentHandler(this);
xr.setErrorHandler(this);
InputStreamReader r = null;
try {
r = new InputStreamReader(info.openStream());
xr.parse(new InputSource(r));
} finally {
if (r != null) {
r.close();
}
}
return root;
} catch (SAXException ex) {
IOException ioEx = new IOException("Error while parsing Ogre3D dotScene");
ioEx.initCause(ex);
throw ioEx;
} catch (ParserConfigurationException ex) {
IOException ioEx = new IOException("Error while parsing Ogre3D dotScene");
ioEx.initCause(ex);
throw ioEx;
}
}
Aggregations