2 * Copyright (c) 2003-2009 jMonkeyEngine
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are
9 * * Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
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.
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.
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.
33 package jmetest.effects;
35 import com.jme.app.SimpleGame;
36 import com.jme.bounding.BoundingBox;
37 import com.jme.image.Texture;
38 import com.jme.light.DirectionalLight;
39 import com.jme.math.FastMath;
40 import com.jme.math.Vector3f;
41 import com.jme.renderer.ColorRGBA;
42 import com.jme.scene.shape.Torus;
43 import com.jme.scene.state.MaterialState;
44 import com.jme.scene.state.TextureState;
45 import com.jme.scene.state.ZBufferState;
46 import com.jme.system.DisplaySystem;
47 import com.jme.util.BumpMapColorController;
48 import com.jme.util.TextureManager;
51 * <code>TestLightState</code>
54 * @version $Id: TestBumpMapping.java,v 1.9 2007/08/21 20:10:03 nca Exp $
56 public class TestBumpMapping extends SimpleGame {
63 * Entry point for the test,
67 public static void main(String[] args) {
68 TestBumpMapping app = new TestBumpMapping();
69 app.setConfigShowMode(ConfigShowMode.AlwaysShow);
74 * Not used in this test.
76 * @see com.jme.app.BaseGame#update(float)
78 protected void simpleUpdate() {
81 ((DirectionalLight)lightState.get(0)).setDirection(new Vector3f(2.0f *
82 FastMath.cos(angle0), 2.0f * FastMath.sin(angle0), -1.5f));
88 * @see com.jme.app.SimpleGame#initGame()
90 protected void simpleInitGame() {
92 t = new Torus("Torus", 30, 30, 5, 10);
93 t.setModelBound(new BoundingBox());
96 BumpMapColorController c = new BumpMapColorController(t);
99 MaterialState ms = DisplaySystem.getDisplaySystem().getRenderer()
100 .createMaterialState();
101 ms.setColorMaterial(MaterialState.ColorMaterial.Diffuse);
102 t.setRenderState(ms);
103 t.updateRenderState();
105 rootNode.attachChild(t);
107 TextureState ts = display.getRenderer().createTextureState();
109 Texture tex = TextureManager.loadTexture(TestBumpMapping.class
110 .getClassLoader().getResource(
111 "jmetest/data/images/FieldstoneNormal.jpg"),
112 Texture.MinificationFilter.Trilinear, Texture.MagnificationFilter.Bilinear);
114 tex.setWrap(Texture.WrapMode.Repeat);
115 tex.setApply(Texture.ApplyMode.Combine);
116 tex.setCombineFuncRGB(Texture.CombinerFunctionRGB.Dot3RGB);
117 tex.setCombineSrc0RGB(Texture.CombinerSource.CurrentTexture);
118 tex.setCombineSrc1RGB(Texture.CombinerSource.PrimaryColor);
120 ts.setTexture(tex, 0);
122 Texture tex2 = TextureManager.loadTexture(
123 TestBumpMapping.class.getClassLoader().getResource(
124 "jmetest/data/texture/decalimage.png"),
125 Texture.MinificationFilter.Trilinear, Texture.MagnificationFilter.Bilinear, 0.0f, true);
126 tex2.setApply(Texture.ApplyMode.Combine);
127 tex2.setWrap(Texture.WrapMode.Repeat);
128 tex2.setCombineFuncRGB(Texture.CombinerFunctionRGB.Modulate);
129 tex2.setCombineSrc0RGB(Texture.CombinerSource.Previous);
130 tex2.setCombineSrc1RGB(Texture.CombinerSource.CurrentTexture);
131 ts.setTexture(tex2, 1);
133 t.copyTextureCoordinates(0, 1, 1.0f);
134 t.scaleTextureCoordinates(0, 8);
136 t.setRenderState(ts);
138 ZBufferState buf = display.getRenderer().createZBufferState();
139 buf.setEnabled(true);
140 buf.setFunction(ZBufferState.TestFunction.LessThanOrEqualTo);
142 t.setRenderState(buf);
145 DirectionalLight dr = new DirectionalLight();
146 dr.setAmbient(new ColorRGBA(0.75f, 0.75f, 0.75f, 1));
147 dr.setDiffuse(new ColorRGBA(1, 1, 1, 1));
149 dr.setDirection(new Vector3f(1,1,-1));
151 lightState.detachAll();
152 lightState.attach(dr);
154 rootNode.updateRenderState();
155 rootNode.updateGeometricState(0.0f, true);