1 /* 2 * Copyright (c) 2009-2010 jMonkeyEngine 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions are 7 * met: 8 * 9 * * Redistributions of source code must retain the above copyright 10 * notice, this list of conditions and the following disclaimer. 11 * 12 * * Redistributions in binary form must reproduce the above copyright 13 * notice, this list of conditions and the following disclaimer in the 14 * documentation and/or other materials provided with the distribution. 15 * 16 * * Neither the name of 'jMonkeyEngine' nor the names of its contributors 17 * may be used to endorse or promote products derived from this software 18 * without specific prior written permission. 19 * 20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 21 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 22 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 23 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 24 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 25 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 26 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 27 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 28 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 29 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 30 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 */ 32 package jme3test.post; 33 34 import com.jme3.app.SimpleApplication; 35 import com.jme3.asset.plugins.HttpZipLocator; 36 import com.jme3.asset.plugins.ZipLocator; 37 import com.jme3.input.KeyInput; 38 import com.jme3.input.controls.ActionListener; 39 import com.jme3.input.controls.KeyTrigger; 40 import com.jme3.light.DirectionalLight; 41 import com.jme3.math.ColorRGBA; 42 import com.jme3.math.Quaternion; 43 import com.jme3.math.Vector3f; 44 import com.jme3.post.FilterPostProcessor; 45 import com.jme3.post.filters.BloomFilter; 46 import com.jme3.post.filters.ColorOverlayFilter; 47 import com.jme3.post.ssao.SSAOFilter; 48 import com.jme3.scene.Spatial; 49 import com.jme3.util.SkyFactory; 50 import com.jme3.water.WaterFilter; 51 import java.io.File; 52 53 public class TestMultiplesFilters extends SimpleApplication { 54 55 private static boolean useHttp = false; 56 main(String[] args)57 public static void main(String[] args) { 58 File file = new File("wildhouse.zip"); 59 if (!file.exists()) { 60 useHttp = true; 61 } 62 TestMultiplesFilters app = new TestMultiplesFilters(); 63 app.start(); 64 } 65 SSAOFilter ssaoFilter; 66 FilterPostProcessor fpp; 67 boolean en = true; 68 simpleInitApp()69 public void simpleInitApp() { 70 this.flyCam.setMoveSpeed(10); 71 cam.setLocation(new Vector3f(6.0344796f, 1.5054002f, 55.572033f)); 72 cam.setRotation(new Quaternion(0.0016069f, 0.9810479f, -0.008143323f, 0.19358753f)); 73 74 // load sky 75 rootNode.attachChild(SkyFactory.createSky(assetManager, "Textures/Sky/Bright/BrightSky.dds", false)); 76 77 // create the geometry and attach it 78 // load the level from zip or http zip 79 if (useHttp) { 80 assetManager.registerLocator("http://jmonkeyengine.googlecode.com/files/wildhouse.zip", HttpZipLocator.class.getName()); 81 } else { 82 assetManager.registerLocator("wildhouse.zip", ZipLocator.class.getName()); 83 } 84 Spatial scene = assetManager.loadModel("main.scene"); 85 86 87 DirectionalLight sun = new DirectionalLight(); 88 sun.setDirection(new Vector3f(-0.4790551f, -0.39247334f, -0.7851566f)); 89 sun.setColor(ColorRGBA.White.clone().multLocal(2)); 90 scene.addLight(sun); 91 92 fpp = new FilterPostProcessor(assetManager); 93 // fpp.setNumSamples(4); 94 ssaoFilter = new SSAOFilter(0.92f, 2.2f, 0.46f, 0.2f); 95 final WaterFilter water=new WaterFilter(rootNode,new Vector3f(-0.4790551f, -0.39247334f, -0.7851566f)); 96 water.setWaterHeight(-20); 97 SSAOUI ui=new SSAOUI(inputManager,ssaoFilter); 98 final BloomFilter bloom = new BloomFilter(); 99 final ColorOverlayFilter overlay = new ColorOverlayFilter(ColorRGBA.LightGray); 100 101 102 fpp.addFilter(ssaoFilter); 103 104 fpp.addFilter(water); 105 106 fpp.addFilter(bloom); 107 108 fpp.addFilter(overlay); 109 110 viewPort.addProcessor(fpp); 111 112 rootNode.attachChild(scene); 113 114 inputManager.addListener(new ActionListener() { 115 116 public void onAction(String name, boolean isPressed, float tpf) { 117 if ("toggleSSAO".equals(name) && isPressed) { 118 if (ssaoFilter.isEnabled()) { 119 ssaoFilter.setEnabled(false); 120 } else { 121 ssaoFilter.setEnabled(true); 122 } 123 } 124 if ("toggleWater".equals(name) && isPressed) { 125 if (water.isEnabled()) { 126 water.setEnabled(false); 127 } else { 128 water.setEnabled(true); 129 } 130 } 131 if ("toggleBloom".equals(name) && isPressed) { 132 if (bloom.isEnabled()) { 133 bloom.setEnabled(false); 134 } else { 135 bloom.setEnabled(true); 136 } 137 } 138 if ("toggleOverlay".equals(name) && isPressed) { 139 if (overlay.isEnabled()) { 140 overlay.setEnabled(false); 141 } else { 142 overlay.setEnabled(true); 143 } 144 } 145 } 146 }, "toggleSSAO", "toggleBloom", "toggleWater","toggleOverlay"); 147 inputManager.addMapping("toggleSSAO", new KeyTrigger(KeyInput.KEY_1)); 148 inputManager.addMapping("toggleWater", new KeyTrigger(KeyInput.KEY_2)); 149 inputManager.addMapping("toggleBloom", new KeyTrigger(KeyInput.KEY_3)); 150 inputManager.addMapping("toggleOverlay", new KeyTrigger(KeyInput.KEY_4)); 151 152 } 153 } 154