[SOLVED] Need help with alpha channel for texture

Hi
I am using a free .max model. I exported it to OBJ . Opened in blender (.blend) . then import to JME3.1.
Here is how model looks like in JME .


The black part is transparent in texture.png .

Here is how it looks like in blender render mode .

after changing alpha to 0 it seems Ok :

But when I import it to JME :

I tried to get material inside code and changed it like this:

 Spatial s43=c4.getChild("DrawCall_05691");
        Material m43=((Geometry)s43).getMaterial();
       m43.getAdditionalRenderState().setAlphaTest(true);
       m43.getAdditionalRenderState().setBlendMode(RenderState.BlendMode.Alpha);        
       s43.setQueueBucket(RenderQueue.Bucket.Transparent);
       s43.setMaterial(m43);

But no difference .

Can you help with it ?

First, that requires that you also set alpha falloff or it won’t really do much.

Second, in 3.1 this does nothing as it’s been disabled. Use the alphaDiscardThreshold material parameter instead.

In that last pic, is his head supposed to look transparent like that? It’s hard to compare pictures that are taken under different conditions so sometimes it’s worth explaining what we should have expected.

WoW ! You are the best . It worked . thanksssssssssssssssss @pspeed . :joy:
I added this code m43.setFloat("AlphaDiscardThreshold", 0.1f);

1 Like

Looks like the background is showing through the eys, ears, and nostrils? Is that intentional?

It is not a big deal . Not JME’s fault at all . I used this online editor to make some part of my texture transparent . I increased threshold a bit more and that caused this problem . It can be fixed if I decrease threshold .

Now I know why the hair and facial hair in Starcraft 2 look so bad. ^^
I always thought they use a 1 bit alpha channel, but most certainly they use this alpha threshold.

If some lower frames per second are okay - you might render this guy twice:
First you render him to the Opaque bucket with alpha threshold = 0.999999.
Second render him to the Transparent bucket which will add the hair (and other transparent parts).

To further improve that, you could make use of a custom shader which uses the ‘discard’ operation:
In the first render you discard() every pixel that has alpha < 1.0
In the second render you discard() every pixel that has alpha >= 1.0

1 Like

Thanks @Ogli for your guide . I will try that . About shader , actually I have no knowledge of shader programming. (learning shaders is in my plan) . Anyway thanks so much . :grinning: