Home | History | Annotate | Download | only in post
      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 
     33 package jme3test.post;
     34 
     35 import com.jme3.app.SimpleApplication;
     36 import com.jme3.input.KeyInput;
     37 import com.jme3.input.controls.ActionListener;
     38 import com.jme3.input.controls.KeyTrigger;
     39 import com.jme3.light.DirectionalLight;
     40 import com.jme3.material.Material;
     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.renderer.queue.RenderQueue.ShadowMode;
     47 import com.jme3.scene.Geometry;
     48 import com.jme3.scene.Spatial;
     49 import com.jme3.scene.debug.WireFrustum;
     50 import com.jme3.scene.shape.Box;
     51 import com.jme3.util.SkyFactory;
     52 
     53 public class TestBloom extends SimpleApplication {
     54 
     55     float angle;
     56     Spatial lightMdl;
     57     Spatial teapot;
     58     Geometry frustumMdl;
     59     WireFrustum frustum;
     60     boolean active=true;
     61     FilterPostProcessor fpp;
     62 
     63     public static void main(String[] args){
     64         TestBloom app = new TestBloom();
     65         app.start();
     66     }
     67 
     68     @Override
     69     public void simpleInitApp() {
     70         // put the camera in a bad position
     71         cam.setLocation(new Vector3f(-2.336393f, 11.91392f, -7.139601f));
     72         cam.setRotation(new Quaternion(0.23602544f, 0.11321983f, -0.027698677f, 0.96473104f));
     73         //cam.setFrustumFar(1000);
     74 
     75 
     76         Material mat = new Material(assetManager,"Common/MatDefs/Light/Lighting.j3md");
     77         mat.setFloat("Shininess", 15f);
     78         mat.setBoolean("UseMaterialColors", true);
     79         mat.setColor("Ambient", ColorRGBA.Yellow.mult(0.2f));
     80         mat.setColor("Diffuse", ColorRGBA.Yellow.mult(0.2f));
     81         mat.setColor("Specular", ColorRGBA.Yellow.mult(0.8f));
     82 
     83 
     84 
     85 
     86         Material matSoil = new Material(assetManager,"Common/MatDefs/Light/Lighting.j3md");
     87         matSoil.setFloat("Shininess", 15f);
     88         matSoil.setBoolean("UseMaterialColors", true);
     89         matSoil.setColor("Ambient", ColorRGBA.Gray);
     90         matSoil.setColor("Diffuse", ColorRGBA.Black);
     91         matSoil.setColor("Specular", ColorRGBA.Gray);
     92 
     93 
     94 
     95         teapot = assetManager.loadModel("Models/Teapot/Teapot.obj");
     96         teapot.setLocalTranslation(0,0,10);
     97 
     98         teapot.setMaterial(mat);
     99         teapot.setShadowMode(ShadowMode.CastAndReceive);
    100         teapot.setLocalScale(10.0f);
    101         rootNode.attachChild(teapot);
    102 
    103 
    104 
    105         Geometry soil=new Geometry("soil", new Box(new Vector3f(0, -13, 550), 800, 10, 700));
    106         soil.setMaterial(matSoil);
    107         soil.setShadowMode(ShadowMode.CastAndReceive);
    108         rootNode.attachChild(soil);
    109 
    110         DirectionalLight light=new DirectionalLight();
    111         light.setDirection(new Vector3f(-1, -1, -1).normalizeLocal());
    112         light.setColor(ColorRGBA.White.mult(1.5f));
    113         rootNode.addLight(light);
    114 
    115         // load sky
    116         Spatial sky = SkyFactory.createSky(assetManager, "Textures/Sky/Bright/FullskiesBlueClear03.dds", false);
    117         sky.setCullHint(Spatial.CullHint.Never);
    118         rootNode.attachChild(sky);
    119 
    120         fpp=new FilterPostProcessor(assetManager);
    121        // fpp.setNumSamples(4);
    122         BloomFilter bloom=new BloomFilter();
    123         bloom.setDownSamplingFactor(2);
    124         bloom.setBlurScale(1.37f);
    125         bloom.setExposurePower(3.30f);
    126         bloom.setExposureCutOff(0.2f);
    127         bloom.setBloomIntensity(2.45f);
    128         BloomUI ui=new BloomUI(inputManager, bloom);
    129 
    130 
    131         viewPort.addProcessor(fpp);
    132         fpp.addFilter(bloom);
    133         initInputs();
    134 
    135     }
    136 
    137          private void initInputs() {
    138         inputManager.addMapping("toggle", new KeyTrigger(KeyInput.KEY_SPACE));
    139 
    140         ActionListener acl = new ActionListener() {
    141 
    142             public void onAction(String name, boolean keyPressed, float tpf) {
    143                 if (name.equals("toggle") && keyPressed) {
    144                     if(active){
    145                         active=false;
    146                         viewPort.removeProcessor(fpp);
    147                     }else{
    148                         active=true;
    149                         viewPort.addProcessor(fpp);
    150                     }
    151                 }
    152             }
    153         };
    154 
    155         inputManager.addListener(acl, "toggle");
    156 
    157     }
    158 
    159 
    160 
    161 }
    162