Hello all,
Okay, after three days of searching and trying I give up.
I want the following: I have two textures that should be added to an object. the first one is the “ground”-texture and has no alpha-information. The second is one is a .png-file with alpha-information and I want to add the colored parts of this texture to the first one (and so I’m using multitexturing).
Using the texture-units of my gpu works fine, but I figured out, that I need much more than 4 Texture-Unit, so I tried the Renderpass-Tutorial and it worked, but the result isn’t what I want.
In the example and in the code below the renderer uses the color white of the second texture to blend both textures together and ignores the alpha-Value of the png-File.
Here is what I have. I’m using SimplePassGame.
display.setTitle(“Multitexturing”);
display.setVSyncEnabled(true);
cam.setLocation(new Vector3f(-40, 40, 40));
cam.lookAt(new Vector3f(0,0,0), Vector3f.UNIT_Y);
cam.update();
TextureState ts1 = display.getRenderer().createTextureState();
ts1.setTexture(Texter.load(path+“blue.png”));
TextureState ts2 = display.getRenderer().createTextureState();
Texture t1 = Texter.load(path+“alphatest.png”);
t1.setApply(ApplyMode.Decal);
ts2.setTexture(t1);
BlendState bs = display.getRenderer().createBlendState();
bs.setSourceFunction(BlendState.SourceFunction.DestinationColor);
bs.setDestinationFunction(BlendState.DestinationFunction.SourceColor);
bs.setBlendEnabled(true);
b = new Box(“Box”, new Vector3f(5, 5, 5), new Vector3f( -5, -5, -5));
RenderPass rp1 = new RenderPass();
rp1.setPassState(ts1);
rp1.add(b);
RenderPass rp2 = new RenderPass();
rp2.setPassState(ts2);
rp2.setPassState(bs);
rp2.add(b);
pManager.add(rp1);
pManager.add(rp2);
rootNode.attachChild(b);
Thanks for your help.
Okay, I found a solution in the Test "TestPassNode" of the jme-Tests.
ceiphren said:
Okay, I found a solution in the Test "TestPassNode" of the jme-Tests.
Please always post the solution you found so others find it here when they have the same problem.
No prob.
The Test is the solution, but with a heavy bunch of code (267 line) and shows what is possible.
Here is my spartan version (41 lines):
display.setTitle("Multitexturing");
display.setVSyncEnabled(true);
cam.setLocation(new Vector3f(-40, 40, 40));
cam.lookAt(new Vector3f(0,0,0), Vector3f.UNIT_Y);
cam.update();
b = new Box("Box", new Vector3f(5, 5, 5), new Vector3f( -5, -5, -5));
TextureState ts1 = display.getRenderer().createTextureState();
Texture t0 = TextureManager.loadTexture(
Core.class.getClassLoader().getResource("textures/blue.png"),
Texture.MinificationFilter.Trilinear, Texture.MagnificationFilter.Bilinear);
ts1.setTexture(Texter.load(path+"blue.png"),0);
TextureState ts2 = display.getRenderer().createTextureState();
Texture t1 = TextureManager.loadTexture(
Core.class.getClassLoader().getResource("textures/green_alphas.png"),
Texture.MinificationFilter.Trilinear, Texture.MagnificationFilter.Bilinear);
ts2.setTexture(t1);
BlendState bs = display.getRenderer().createBlendState();
bs.setBlendEnabled(true);
PassNode node = new PassNode("AlphaPass");
node.attachChild(b);
PassNodeState state1 = new PassNodeState();
state1.setPassState(ts1);
node.addPass(state1);
PassNodeState state2 = new PassNodeState();
state2.setPassState(ts2);
state2.setPassState(bs);
node.addPass(state2);
rootNode.attachChild(node);
RenderPass pass = new RenderPass();
pass.add(node);
pManager.add(pass);
edit: I tried some fun-stuff and added 40 TextureStates to a scene with 26k tris. The result were 551.000 triangles with a massive bunch of alpha-calculations and hey: 28fps. Now I'm sure the JME-Engine IS fast.