Is there an example somewhere of loading in an alphamap? Like in a .j3m file?
I can get alpha to work when I load it in a model as a .obj file but when I try and set the material myself can't seem to get it to work.
I'll poke around some more latter but was leaving work and just wanted to see if anyone else had messed around with it.
Thanks,
William
This tutorial shows a good way on how to use alpha-maps (assuming you want black to be completely transparent):
http://www.jmonkeyengine.com/wiki/doku.php/jme3:beginner:hello_effects
Here's my problem. If I try and create a .j3m file to use an alphamap like so:
Material test : Common/MatDefs/Light/Lighting.j3md {
MaterialParameters {
m_Shininess: 8.0
m_DiffuseMap: tree/tree62Li.jpg
m_AlphaMap: tree/tree62La.jpg
}
}
Noting is transparent.
However if I build the material in the code like:
Material mat = new Material(assetManager,"Common/MatDefs/Light/Lighting.j3md");
mat.setBoolean("m_UseMaterialColors", true);
mat.setColor("m_Ambient", ColorRGBA.Black);
mat.setColor("m_Diffuse", ColorRGBA.White);
mat.setColor("m_Specular", ColorRGBA.Black);
TextureKey key = new TextureKey("tree/tree62Li.jpg");
key.setGenerateMips(true);
Texture texture = assetManager.loadTexture(key);
//texture.setWrap(WrapMode.Repeat);
mat.setTexture("m_DiffuseMap", texture);
TextureKey alphakey = new TextureKey("tree/tree62La.jpg");
alphakey.setGenerateMips(true);
Texture alphaTex = assetManager.loadTexture(alphakey);
//alphaTex.setWrap(WrapMode.Repeat);
mat.setTexture("m_AlphaMap",alphaTex);
mat.setTransparent(true);
mat.getAdditionalRenderState().setBlendMode(BlendMode.Alpha);
mat.getAdditionalRenderState().setAlphaTest(true);
mat.getAdditionalRenderState().setAlphaFallOff(0.01f);
The texture is transparent but upside down. This is basically stolen from the loading mtl code for loading obj.
What am I doing wrong with the .j3m? And why would the texture be upside down?
Thanks,
William
EDIT: Never mind about the upside down thing. Think that's something else from the model. Sorry.
With the .j3m way, it's hard to say since you're using the Lighting material definition. I don't know what all is defined for that definition. You'd think it would include the Blend Alpha render state, but I'm definitely the wrong person to verify that.
You could try creating your own material definition and experimenting with that.
As for your 2nd way (doing it in the code), I believe the flipping occurs due to differences in the (0,0) origin. Most 2d rendering APIs place the origin at the upper left-hand corner of a screen or window (by default). 3d rendering APIs use a lower left-hand origin. Most 3d APIs accommodate for this by providing a flip option, which jme does. Try this in your code:
TextureKey key = new TextureKey("file/path.jpg", true);
Yeah the flipped texture thing I think it's just some setting in the model I was testing. That's not really a problem.
The difference between the j3m and doing it in code is my main concern.
Although just doing it all in the code is fine and probably what I'll end up doing anyway. Was just curious if I was doing something wrong.
With the .j3m way, it's hard to say since you're using the Lighting material definition
I'm using the Lighting material definition in the code as well aren't I? Isn't that:
Material mat = new Material(assetManager,"Common/MatDefs/Light/Lighting.j3md");
I wish I had more experience playing around with .j3m and .j3md files. Hopefully soon, I'll be able to spend more time playing with this awesome feature of jme3 and I'll be able to figure out why your implementation didn't work.
You can put a block like
AdditionalRenderState {
Blend Alpha
}
After the MaterialParameters block in the J3M.
You can also call
material.getAdditionalRenderState().setBlendMode(BlendMode.Alpha)