Java examples for Game:JME3
Depth Of Field Blur jme3
package Effects;// w w w.j a v a 2 s. co m import com.jme3.app.SimpleApplication; import com.jme3.asset.plugins.ZipLocator; import com.jme3.collision.CollisionResult; import com.jme3.collision.CollisionResults; import com.jme3.light.DirectionalLight; import com.jme3.math.Ray; import com.jme3.math.Vector3f; import com.jme3.post.FilterPostProcessor; import com.jme3.post.filters.DepthOfFieldFilter; import com.jme3.renderer.RenderManager; import com.jme3.scene.Spatial; /** * test * * @author normenhansen */ public class DepthOfFieldBlur extends SimpleApplication { private Spatial sceneGeo; private FilterPostProcessor fpp; private DepthOfFieldFilter dofFilter; public static void main(String[] args) { DepthOfFieldBlur app = new DepthOfFieldBlur(); app.start(); } @Override public void simpleInitApp() { fpp = new FilterPostProcessor(assetManager); viewPort.addProcessor(fpp); dofFilter = new DepthOfFieldFilter(); fpp.addFilter(dofFilter); assetManager.registerLocator("town.zip", ZipLocator.class); sceneGeo = assetManager.loadModel("main.scene"); rootNode.attachChild(sceneGeo); DirectionalLight sunLight = new DirectionalLight(); sunLight.setDirection(new Vector3f(0.3f, -0.5f, -0.5f)); rootNode.addLight(sunLight); } @Override public void simpleUpdate(float tpf) { Ray ray = new Ray(cam.getLocation(), cam.getDirection()); CollisionResults results = new CollisionResults(); int numCollisions = sceneGeo.collideWith(ray, results); if (numCollisions > 0) { CollisionResult hit = results.getClosestCollision(); dofFilter.setFocusDistance(hit.getDistance() / 10.0f); } } @Override public void simpleRender(RenderManager rm) { //TODO: add render code } }