Blending issue with a palm

hello there,



i’m setting up my project structure using jme and loaded a model (a palm) from opengamearts (dummy & test purpose) which has diffuse,normal and spec. pics.

It looks really nice but there is one blend error i do not understand.

I hope someone can help me and here we go:



I use a jython to setup my level. i dont know jet if i keep it but for modularity of my project it would be great.

thats why i will post python code here.

The code is still really self explaining:



[java]



#import stuff is above



loadable_assets = [

(“http://” + host + “/trees/palm/palm.zip”,“com.jme3.asset.plugins.HttpZipLocator”),

]



for asset in loadable_assets:

print “loading”,asset[0]

assetManager.registerLocator(asset[0],asset[1]);



palm = assetManager.loadModel(“palm_tree.mesh.xml”)

mat = assetManager.loadMaterial(“palm.j3m”)

mat.getAdditionalRenderState().setBlendMode(BlendMode.Alpha)

mat.getAdditionalRenderState().setFaceCullMode(FaceCullMode.Off)



palm.setMaterial(mat)

palm.setLocalTranslation(0,0,-10.0)

palm.scale(0.1)

rootNode.attachChild(palm)



#the light

sun = DirectionalLight()

sun.setDirection(Vector3f(1, -1, 0))

rootNode.addLight(sun);

[/java]



rootNode, assetManager are in the global context accessible



What i get is this:



http://i.imgur.com/L1Inz.jpg



1: two leaves overlap and there is black where it should be a leave

2: displayed correct (palm trunk) cause there is no leave under that one



the model+pics are here

i forgot to post my palm.j3m:



[java]

Material Palm : Common/MatDefs/Light/Lighting.j3md {

MaterialParameters {

DiffuseMap: diffuse.tga

NormalMap: normal.tga

SpecularMap: specular.tga

}

}

[/java]



thx

It’s hard to tell for sure in this picture but it’s probably a polygon sorting issue. Since the lower leaf extends towards the camera then it sorts as being ahead of the other leaves and so will be drawn last when in the transparent bucket.



Even though the other leaves have transparent fringe, it’s still drawing pixels there and filling the Z-buffer… so when the lower leaf is drawn, it can only be seen where those other leaf polygons weren’t.



One way to mitigate this is to set the alpha falloff stuff on the extended render state.

http://hub.jmonkeyengine.org/javadoc/com/jme3/material/RenderState.html#setAlphaTest(boolean)

http://hub.jmonkeyengine.org/javadoc/com/jme3/material/RenderState.html#setAlphaFallOff(float)



This controls which pixels are drawn based on an alpha threshold… so the leaf fringe that is transparent will be discarded instead of being drawn fully transparent. In other words, the z-buffer won’t get filled. It’s still not a perfect solution if there is a part with lots of partial alpha as sometimes you will still see a halo around the leaves but it should be better than what is happening for you now.

1 Like

Another option is to enable alpha to coverage



http://hub.jmonkeyengine.org/javadoc/com/jme3/renderer/Renderer.html#setAlphaToCoverage(boolean)



It is similar to how the alpha test works, except it does this testing per sample rather than per pixel so you get smoother results.

To use alpha to coverage, you must have antialiasing enabled in the rendering options.

1 Like

Thx for the fast reply!



Both methods worked and coverage gave the better result!

Alpha to coverage will give a better result. The reason I usually don’t use it is because it requires AA… and with AA off it doesn’t seem to do anything at all so you are back to your original big black borders.



Maybe there is some threshold of the alpha test that isn’t visible when alpha to coverage is active but will be a nice fallback if AA is disabled. Or you can just force AA on always.