Multi Texturing with transparency and alpha

Hello !



I'm not experienced enough with multi-texturing and so my problem is that

I want to blend two textures with transparencies on them, and have an alphastate



I readed a lot of posts on the forum and played a lot with those CombineSrc0RG and setApplyMode functions but I can't make it work…



Here is my code …




((TriMesh) Circuit.getChild(2)).copyTextureCoords(0, 0, 1);
((TriMesh) Circuit.getChild(3)).copyTextureCoords(0, 0, 1);

Texture anisoTexture;
TextureState tss;

tss = display.getRenderer().createTextureState();
tss.setEnabled(true);
 
circuitTex = TextureManager.loadTexture(MonkeyRacing.class
.getClassLoader().getResource("data/protect1.png"),
Texture.MM_LINEAR_LINEAR,
Texture.FM_LINEAR,
tss.getMaxAnisotropic(), true);


circuitTex.setRTTSource(Texture.RTT_SOURCE_RGBA);

circuitTex.setApply(Texture.AM_COMBINE);
//  circuitTex.setCombineFuncRGB(Texture.ACF_MODULATE);
circuitTex.setCombineSrc0RGB(Texture.ACS_TEXTURE);
//  circuitTex.setCombineSrc1RGB(Texture.ACS_PRIMARY_COLOR);

 
tss.setTexture( circuitTex, 0);
circuitTex.setWrap(Texture.WM_WRAP_S_WRAP_T);

anisoTexture = TextureManager.loadTexture(MonkeyRacing.class
.getClassLoader().getResource("data/circuit/alpha.png"),
Texture.MM_LINEAR_LINEAR,
Texture.FM_LINEAR,
tss.getMaxAnisotropic(), true);

anisoTexture.setRTTSource(Texture.RTT_SOURCE_RGBA);

anisoTexture.setApply(Texture.AM_COMBINE);
anisoTexture.setWrap(Texture.WM_WRAP_S_WRAP_T);
anisoTexture.setCombineFuncRGB(Texture.ACF_MODULATE);
anisoTexture.setCombineSrc0RGB(Texture.ACS_PREVIOUS);
anisoTexture.setCombineSrc1RGB(Texture.ACS_TEXTURE);

anisoTexture.setWrap(Texture.WM_WRAP_S_WRAP_T);

tss.setTexture(anisoTexture,1);


AlphaState as = display.getRenderer().createAlphaState();
as.setBlendEnabled(true);
as.setSrcFunction(AlphaState.SB_SRC_ALPHA);
as.setDstFunction(AlphaState.SB_ONE_MINUS_SRC_ALPHA);
as.setTestEnabled(true);
as.setTestFunction(AlphaState.TF_GREATER);

AlphaState as2 = display.getRenderer().createAlphaState();
as2.setBlendEnabled(true);
as2.setSrcFunction(AlphaState.SB_SRC_ALPHA);
as2.setDstFunction(AlphaState.SB_ONE_MINUS_SRC_ALPHA);
as2.setTestEnabled(true);
as2.setTestFunction(AlphaState.TF_GREATER);

Circuit.getChild(2).setRenderState(as);
Circuit.getChild(3).setRenderState(as2);

Circuit.getChild(2).setRenderState(tss);
Circuit.getChild(3).setRenderState(tss);



I guess an answer will take a second for an experienced JME user that's why I permit me to ask  8)

Thanks !

more precisely I don't want the second texture alphas to replace the first one's pixel values but blend … :slight_smile:

kine

Newbie

*

Posts: 49



Yes I'm gonna be a junior member !  :smiley:

It depends on what you want the alpha of the result to be. If you want it to use the alpha from the first texture, then use the replace combine function:


anisoTexture.setCombineFuncAlpha(Texture.ACF_REPLACE);
anisoTexture.setCombineSrc0Alpha(Texture.ACS_TEXTURE0);
anisoTexture.setCombineOp0Alpha(Texture.ACO_SRC_ALPHA);

Hi !



my problem with blending alphas is now solved, thanks !

And I'm experiencing others ones … ( it seems to be a cyclic state  XD  )


  1. I have a trismesh with two textures, and I want to repeat the first one ans slide show it…

    do I have to use someting like ((TriMesh) Circuit.getChild(2)).copyTextureCoords(0,0,1);

    or do I have to make a copy of my first texture and play with translations and blendings again… ?


  2. I have another trimesh with two textures on it … I want the second one applied as a decal, but the lighting seems to affect the first one only,

    whereas the second is always full-lighted  … I gues it's all about RTT_SOURCE_LUMINANCE … could you tell me more about it ?


kine said:

Hi !

my problem with blending alphas is now solved, thanks !
And I'm experiencing others ones ... ( it seems to be a cyclic state  XD  )

1) I have a trismesh with two textures, and I want to repeat the first one ans slide show it...
do I have to use someting like ((TriMesh) Circuit.getChild(2)).copyTextureCoords(0,0,1);
or do I have to make a copy of my first texture and play with translations and blendings again... ?

2) I have another trimesh with two textures on it ... I want the second one applied as a decal, but the lighting seems to affect the first one only,
whereas the second is always full-lighted  ... I gues it's all about RTT_SOURCE_LUMINANCE ... could you tell me more about it ?



I don't understand the first question..

for #2
It's not about RTT_SOURCE_LUMINANCE, RTT is render to texture, which has nothing to do with multitexturing..

If you apply it as a decal, then it will not be modulated by lighting values (http://www.jmonkeyengine.com/wiki/doku.php?id=texture), you must use combine modes, and do the operation in reverse. The original texture must be interpolated with the 1st using the alpha values of the decal, then the result must be modulated by light color.


tex.setApply(Texture.AM_COMBINE);

tex.setCombineFuncRGB(Texture.ACF_INTERPOLATE);

tex.setCombineSrc0RGB(Texture.ACS_TEXTURE1);
tex.setCombineOp0RGB(Texture.ACO_SRC_COLOR);

tex.setCombineSrc1RGB(Texture.ACS_TEXTURE);
tex.setCombineOp0RGB(Texture.ACO_SRC_COLOR);

tex.setCombineSrc2RGB(Texture.ACS_TEXTURE1);
tex.setCombineOp2RGB(Texture.ACO_SRC_ALPHA);

// op2
decal.setApply(Texture.AM_COMBINE);

decal.setCombineFuncRGB(Texture.ACF_MODULATE);

decal.setCombineSrc0RGB(Texture.ACS_PREVIOUS);
decal.setCombineOp0RGB(Texture.ACO_SRC_COLOR);

decal.setCombineSrc1RGB(Texture.ACS_PRIMARY_COLOR);
decal.setCombineOp1RGB(Texture.ACO_SRC_COLOR);


Thanks a lot Momoko_Fan !