OSDN Git Service

Set optimal mime types and executable settings.
[mikumikustudio/MikuMikuStudio.git] / src / jmetest / renderer / state / TestShaderTexturing.java
1 /*
2  * Copyright (c) 2003-2009 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 jmetest.renderer.state;
34
35 import com.jme.app.SimpleGame;
36 import com.jme.image.Texture;
37 import com.jme.scene.shape.Quad;
38 import com.jme.scene.state.GLSLShaderObjectsState;
39 import com.jme.scene.state.TextureState;
40 import com.jme.util.TextureManager;
41
42 public class TestShaderTexturing extends SimpleGame {
43
44     public static void main(String[] args) {
45         TestShaderTexturing app = new TestShaderTexturing();
46         app.setConfigShowMode(ConfigShowMode.AlwaysShow);
47         app.start();
48     }
49     
50     @Override
51     protected void simpleInitGame() {
52         String shader = "uniform sampler2D tex0, tex1, tex2, tex3, tex4;"
53                 + " void main(){"
54                 + "vec2 tc0 = vec2(gl_TexCoord[1].x, gl_TexCoord[1].y);"
55                 + "vec2 tc1 = vec2(gl_TexCoord[0].x, gl_TexCoord[0].y);"
56                 + "vec4 result = texture2D(tex0,tc0);"
57                 + "vec4 col0 = texture2D(tex1, tc0);"
58                 + "vec4 alp0= texture2D(tex2, tc1);"
59                 + "result = mix(result, col0, alp0.r);"
60                 + "vec4 col1 = texture2D(tex3, tc0);"
61                 + "vec4 alp1= texture2D(tex4, tc1);"
62                 + "result = mix(result, col1, alp1.r);"
63                 + "gl_FragColor = result * gl_Color;" + "}";
64
65         GLSLShaderObjectsState so = display.getRenderer()
66                 .createGLSLShaderObjectsState();
67         so.load(null, shader);
68         so.setUniform("tex0", 0);
69         so.setUniform("tex1", 1);
70         so.setUniform("tex2", 2);
71         so.setUniform("tex3", 3);
72         so.setUniform("tex4", 4);
73         so.setEnabled(true);
74
75         Quad mesh = new Quad("mesh", 10, 10);
76         mesh.copyTextureCoordinates(0, 1, 1.0f);
77         mesh.setRenderState(so);
78
79         TextureState ts = display.getRenderer().createTextureState();
80         Texture t0 = TextureManager.loadTexture(ClassLoader
81                 .getSystemResource("jmetest/data/texture/decalimage.png"),
82                 Texture.MinificationFilter.Trilinear, Texture.MagnificationFilter.NearestNeighbor);
83         ts.setTexture(t0, 0);
84         Texture t1 = TextureManager.loadTexture(ClassLoader
85                 .getSystemResource("jmetest/data/texture/highest.jpg"),
86                 Texture.MinificationFilter.Trilinear, Texture.MagnificationFilter.Bilinear);
87         ts.setTexture(t1, 1);
88         Texture t2 = TextureManager.loadTexture(ClassLoader
89                 .getSystemResource("jmetest/data/cursor/testcursor.png"),
90                 Texture.MinificationFilter.Trilinear, Texture.MagnificationFilter.NearestNeighbor, 0, true);
91         t2.setWrap(Texture.WrapMode.EdgeClamp);
92         ts.setTexture(t2, 2);
93         Texture t3 = TextureManager.loadTexture(ClassLoader
94                 .getSystemResource("jmetest/data/texture/highest.jpg"),
95                 Texture.MinificationFilter.Trilinear, Texture.MagnificationFilter.Bilinear);
96         ts.setTexture(t3, 3);
97         Texture t4 = TextureManager.loadTexture(ClassLoader
98                 .getSystemResource("jmetest/data/cursor/testcursor.png"),
99                 Texture.MinificationFilter.Trilinear, Texture.MagnificationFilter.NearestNeighbor, 0, false);
100         t4.setWrap(Texture.WrapMode.EdgeClamp);
101         ts.setTexture(t4, 4);
102
103         mesh.setRenderState(ts);
104         rootNode.attachChild(mesh);
105
106         lightState.setEnabled(false);
107     }
108
109 }