Alpha texture problem

I seem to be having a problem with the alpha channel in my textures. It draws transparently, however, it still gives the underlying polygons a reflective sheen so it looks like there is “glass” over the transparent parts. It also makes the skirt draw “black” over itself (as you can see on the right side of the picture).



I’ve played around with specular map and transparency buckets but I just can’t figure this one out. Any help?



[java]

box = (Node) assetManager.loadModel(“Models/Body1.mesh.j3o”);



Material mat_tt = new Material(assetManager, “Common/MatDefs/Light/Lighting.j3md”);

Texture skin = assetManager.loadTexture(“Models/Body.png”);

Texture skin2 = assetManager.loadTexture(“Models/Body-normal.png”);

mat_tt.setTexture(“m_DiffuseMap”, skin);

mat_tt.setTexture(“m_NormalMap”, skin2);

mat_tt.setFloat(“m_Shininess”, 0.1f);

mat_tt.setBoolean(“m_UseAlpha”, true);



mat_tt.getAdditionalRenderState().setBlendMode(BlendMode.Alpha);



box.setMaterial(mat_tt);

box.setQueueBucket(Bucket.Transparent);



DirectionalLight sun = new DirectionalLight();

sun.setDirection(new Vector3f(-0.1f, -0.0f, -1.0f));

rootNode.addLight(sun);

[/java]



That’s the relevant code snipped. I just modified one of the examples to load my own model.

Are you using the plain alpha 3 JMP or a recent nightly? I’m guessing stock alpha 3.



You may want to upgrade. In the newer version you can set an alpha threshold on the material that will discard the purely invisible ‘pixels’ avoiding most of the issues you have.

I’ll have to give it a shot. However I can’t seem to figure out how to install the nightly builds, so that’s a problem in itself. :slight_smile:

Well… that question is asked about once a week at least. :slight_smile: From earlier today: http://hub.jmonkeyengine.org/groups/general-2/forum/topic/updating-library/

Thanks! I’ll check that out. I spent a little bit googling “installing jmonkey nightly update” and various varients but just had no luck. I’ll see if this works.

Try searching the manual and this site first next time ^^

I did search this forum, but I couldn’t seem to find the relevant information. I do appreciate how friendly this place is without making me feel like a total noob. :slight_smile:



Even though I am…



Anyway, after the update, the error is partially fixed. The white highlight no longer appears, however, there still seems to be a black “shading” problem. I was afraid I was doing it wrong, but if it’s something in the libraries, I’ll move onto other things and worry about the visual bugs later :slight_smile:



The problem is that the invisible pixels are still drawn… now they’re just drawn with different lighting. And if they happen to be drawn before the background stuff then they potentially fill the z-buffer with nearer values preventing those farther things from being drawn.



The new Lighting.j3md has a setting called AlphaDiscardThreshold… if you set this to 0.1f, I imagine your issues will go away.



[java]

mat_tt.setFloat(“AlphaDiscardThreshold”, 0.1f);

[/java]



This causes the shaders not to even render pixels if the alpha is less than 0.1f.

3 Likes
pspeed said:
The problem is that the invisible pixels are still drawn... now they're just drawn with different lighting. And if they happen to be drawn before the background stuff then they potentially fill the z-buffer with nearer values preventing those farther things from being drawn.

The new Lighting.j3md has a setting called AlphaDiscardThreshold... if you set this to 0.1f, I imagine your issues will go away.

[java]
mat_tt.setFloat("AlphaDiscardThreshold", 0.1f);
[/java]

This causes the shaders not to even render pixels if the alpha is less than 0.1f.

I... I love you.

Will you have my babies? :)

To clarify, that did fix the problem. Thanks!
1 Like

oh god…Paul you really got THE thing :wink:

Oh man, this must have been a recent change. Gotta give this discardThreshold a try later. Sounds amazing :smiley:



Cheers!

~FlaH

I haven’t seen it either, I don’t remember when it was added :-o I added it now to the documentation page and updated the materials docs.


digiko said:I spent a little bit googling "installing jmonkey nightly update" and various varients but just had no luck.


Hmm, it seems our documention wiki sucks at being found by Google? :(

In any case, click the word "documentation" on top of the page. The first wiki page has a big box that describes downloading the SDK or the nightly build.

Oh man. Holy shit. This change… I played with it… I love it… Love it love it love it. This shader variable just solved a big technical issue I was having with overlapping quads with transparency and many weird issues I was having involving them, themselves, and interacting with alpha’d geometry.



HAVE MAH BABIES NAO. :stuck_out_tongue:



~FlaH