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.app.StatsView;
37 import com.jme3.font.BitmapText;
38 import com.jme3.light.DirectionalLight;
39 import com.jme3.material.Material;
40 import com.jme3.math.ColorRGBA;
41 import com.jme3.math.Quaternion;
42 import com.jme3.math.Vector3f;
43 import com.jme3.post.FilterPostProcessor;
44 import com.jme3.post.filters.LightScatteringFilter;
45 import com.jme3.renderer.queue.RenderQueue.ShadowMode;
46 import com.jme3.scene.Geometry;
47 import com.jme3.scene.Node;
48 import com.jme3.scene.Spatial;
49 import com.jme3.shadow.PssmShadowRenderer;
50 import com.jme3.util.SkyFactory;
51 import com.jme3.util.TangentBinormalGenerator;
52 
53 public class TestLightScattering extends SimpleApplication {
54 
main(String[] args)55     public static void main(String[] args) {
56         TestLightScattering app = new TestLightScattering();
57 
58         app.start();
59     }
60 
61     @Override
simpleInitApp()62     public void simpleInitApp() {
63         // put the camera in a bad position
64         cam.setLocation(new Vector3f(55.35316f, -0.27061665f, 27.092093f));
65         cam.setRotation(new Quaternion(0.010414706f, 0.9874893f, 0.13880467f, -0.07409228f));
66 //        cam.setDirection(new Vector3f(0,-0.5f,1.0f));
67 //        cam.setLocation(new Vector3f(0, 300, -500));
68         //cam.setFrustumFar(1000);
69         flyCam.setMoveSpeed(10);
70         Material mat = assetManager.loadMaterial("Textures/Terrain/Rocky/Rocky.j3m");
71         Spatial scene = assetManager.loadModel("Models/Terrain/Terrain.mesh.xml");
72         TangentBinormalGenerator.generate(((Geometry)((Node)scene).getChild(0)).getMesh());
73         scene.setMaterial(mat);
74         scene.setShadowMode(ShadowMode.CastAndReceive);
75         scene.setLocalScale(400);
76         scene.setLocalTranslation(0, -10, -120);
77 
78         rootNode.attachChild(scene);
79 
80         // load sky
81         rootNode.attachChild(SkyFactory.createSky(assetManager, "Textures/Sky/Bright/FullskiesBlueClear03.dds", false));
82 
83         DirectionalLight sun = new DirectionalLight();
84         Vector3f lightDir = new Vector3f(-0.12f, -0.3729129f, 0.74847335f);
85         sun.setDirection(lightDir);
86         sun.setColor(ColorRGBA.White.clone().multLocal(2));
87         scene.addLight(sun);
88 
89         PssmShadowRenderer pssmRenderer = new PssmShadowRenderer(assetManager,1024,4);
90         pssmRenderer.setDirection(lightDir);
91         pssmRenderer.setShadowIntensity(0.55f);
92      //   viewPort.addProcessor(pssmRenderer);
93 
94         FilterPostProcessor fpp = new FilterPostProcessor(assetManager);
95 //        SSAOFilter ssaoFilter= new SSAOFilter(viewPort, new SSAOConfig(0.36f,1.8f,0.84f,0.16f,false,true));
96 //        fpp.addFilter(ssaoFilter);
97 
98 
99 //           Material mat2 = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
100 //        mat2.setTexture("ColorMap", assetManager.loadTexture("Interface/Logo/Monkey.jpg"));
101 //
102 //        Sphere lite=new Sphere(8, 8, 10.0f);
103 //        Geometry lightSphere=new Geometry("lightsphere", lite);
104 //        lightSphere.setMaterial(mat2);
105         Vector3f lightPos = lightDir.multLocal(-3000);
106 //        lightSphere.setLocalTranslation(lightPos);
107         // rootNode.attachChild(lightSphere);
108         LightScatteringFilter filter = new LightScatteringFilter(lightPos);
109         LightScatteringUI ui = new LightScatteringUI(inputManager, filter);
110         fpp.addFilter(filter);
111 //fpp.setNumSamples(4);
112         //fpp.addFilter(new RadialBlurFilter(0.3f,15.0f));
113         //    SSAOUI ui=new SSAOUI(inputManager, ssaoFilter.getConfig());
114 
115         viewPort.addProcessor(fpp);
116     }
117 
118     @Override
simpleUpdate(float tpf)119     public void simpleUpdate(float tpf) {
120     }
121 }
122