Transparency problem:

Hi, i’m becaming REAL crazy to solve this problem:

http://picasaweb.google.it/marco.servetto/JmeData#5289341299944680546

As you can see the face and the hair are an unique trimesh.

there is a unique big texture contianing both face and hair.

some part of the hair is transparent.

I’ts the problem.  :expressionless:



I would like to see the face under the hair, non “directly” the trees under the hair and the face.

what’s the error?



tnx a lot  :smiley:

to make transparency work, you need:

  • render the objects in the transparent renderqueue
  • have a BlendState in your scene
  • maybe use TwoPassTransparency to get th desired result



    see jmetest.renderer.TestRenderQueue for an example.

In your particular case you will need to render the head first and then the hair; I see you do have a blendstate on the hair by the 'bleed through' from the trees.  The order of rendering that is going on is like this: render terrain/trees, render hair, render head.  The depth accumulation buffer from the hair is only getting filled by the trees…



You might just have add your head to a node first then your body…



OR create a custom 'person' node, add the hair and body to it; then override the draw method like this:


public void draw( Renderer renederer ) {
   //super.draw( renderer );  <- Don't call super it will draw it as is...

   // Might have to apply the renderstate here, I don't remember

   hair.draw( renderer );
   person.draw( renderer );
}


No hei!just a moment!

Hair and head are THE SAME mesh!

You want to say that I have to divide they into two mesh???

I was tring to do exactly the opposite, keeping all the pg in one mesh.

Wanna send me a copy of your model? (and no its just for helping purposes, I can model so no worries there…)

basixs said:

Wanna send me a copy of your model? (and no its just for helping purposes, I can model so no worries there...)

Lol, do not worry, I'm for sharing everyting.
I can send you my model, but it will be non sense without the related code :) cause I'm working on an system to
make dressable pg in one mesh: that is it takes lots of trimesh/jointmesh with a texture for model,
and it combine all in a single trimesh /jointmesh with a whole texture,
working on the texture coordinates and composing images on the fly.

My project is hosted on sourgeforge,
http://randomworld.cvs.sourceforge.net
you have to checkout randomworld2 (version for jme2) and EasyJ

In the game you will see a men with transparent legs and hair, use p to pause the game.

Thanks!
is it takes lots of trimesh/jointmesh with a texture for model,
and it combine all in a single trimesh /jointmesh with a whole texture,
working on the texture coordinates and composing images on the fly.


That would make me think there must be something with the way you are building/attaching them.

(the first picture you showed really looks like the hair is being rendered, then land, then body.  what does anyone else think?)

To be honest, I have no idea what's going on… The picture is very small and the hair is alpha-blended with the background. I think the issue is with the hair texture not having alpha in the right places? Check your model in the modeling tool and compare it to jME.

I have prepared a minimal test set showing the problem.

that is a zip with all is needed to run it, and as follow there is the code i use.



that is a bugShot, as you can see, the white and black distinction continue even inside the hair.



http://picasaweb.google.it/marco.servetto/JmeData#5292631290577611874



public class TryBug extends SimpleGame {

  public static void main(String[] args) {
    TryBug app = new TryBug();
    app.setConfigShowMode(ConfigShowMode.AlwaysShow, null);
    app.start();
  }

  @Override
  protected void simpleInitGame() {
    try {
      Renderer r = DisplaySystem.getDisplaySystem().getRenderer();
      Quad qB = new Quad("b", 500, 500);
      rootNode.attachChild(qB);
      qB.setDefaultColor(ColorRGBA.white);
      qB.setLocalTranslation(-20, -20, -20);

      MilkToJme formatConverter = new MilkToJme();
      ByteArrayOutputStream BO = new ByteArrayOutputStream();
      //URL url = new URL("data/men/animationStart1.ms3d");
      URL url = new File("data/men/minimumBug.ms3d").toURI().toURL();
      formatConverter.setProperty("mtllib", url);
      formatConverter.convert(url.openStream(), BO);
      Node n = (Node) BinaryImporter.getInstance().load(new ByteArrayInputStream(BO.toByteArray()));
      // Node n = EnchantedLoader.loadModel("men/animationStart1.ms3d");
      Spatial s = n.getChild("Head");
      n.detachAllChildren();
      n.attachChild(s);
      n.setLocalTranslation(0, -50, 0);
      TextureState t2 = r.createTextureState();
      Texture tex2 = TextureManager.loadTexture("data/men/faceHuman3.png", Texture.MinificationFilter.BilinearNearestMipMap, Texture.MagnificationFilter.Bilinear);
      t2.setTexture(tex2);
      n.setRenderState(t2);
      BlendState vegetationAlpha = r.createBlendState();
      vegetationAlpha.setBlendEnabled(true);
      vegetationAlpha.setSourceFunction(BlendState.SourceFunction.SourceAlpha);
      vegetationAlpha.setDestinationFunction(BlendState.DestinationFunction.OneMinusSourceAlpha);
      vegetationAlpha.setTestEnabled(true);
      vegetationAlpha.setReference(0.7f);
      vegetationAlpha.setTestFunction(BlendState.TestFunction.GreaterThan);
      vegetationAlpha.setEnabled(true);
      vegetationAlpha.setBlendEnabled(true);
      n.setRenderState(vegetationAlpha);
      rootNode.attachChild(n);
    } catch (Exception e) {
      assert false : e;
    }
  }
}



Thanks to all for the attention.

Is there a link for the zip file?



(My forums settings are screwed up and I cant view/download attachments…)

no zip but 4 attachements

—>>> minimumBug_ms3d_renameMe.txt <<<—:slight_smile:

ok i have a little news:

using the new attached png image i have discovered something intresting:

i have maked 3 part of the image:

totally transparent

totally opaque

half transparent.

The half transparent part is the bugged one.



see here for the result.

http://picasaweb.google.it/marco.servetto/JmeData#5293084229191716994




Umm, am I missing something? 



I now do see attachments (thanx mojo :)) but I don't get where the MS3D file is?

Okay, after a quick glance it seems like there is something wrong with your normals and/or the depth precision.

(When I set a CullState, on the model, with the faces set to none half of the hair was right)



I think remodeling the head with the hair as a separate mesh would solve the issue, but I am fairly certain its something with the model…



(you know now that I think about it I wonder if its not actual the triangle ordering that is screwing it up. basically the hair triangles themselves are rendered before the rest of the head. separate meshes would fix that, or you might be able to change the triangle order with some clever extending/coding…)

basixs said:

Okay, after a quick glance it seems like there is something wrong with your normals and/or the depth precision.
(When I set a CullState, on the model, with the faces set to none half of the hair was right)

I think remodeling the head with the hair as a separate mesh would solve the issue, but I am fairly certain its something with the model...

(you know now that I think about it I wonder if its not actual the triangle ordering that is screwing it up. basically the hair triangles themselves are rendered before the rest of the head. separate meshes would fix that, or you might be able to change the triangle order with some clever extending/coding...)

umm... just a moment, do you want to say that the triangle ordering (inside tha same mesh) cares in the rendering?

The order in which things are drawn is key to getting (semi)transparency to work, because transparent pixels are blended with what is underneath. That is why there is a transparent render queue - to specify that things in it should be drawn last.



To me it looks like you have the hair being drawn before the head, and writing to the z-buffer thus preventing the head underneath from being drawn at all. I don't see how you will be able to get it working with everything in one mesh, but I'd be interested to know if you do.

Alric said:

The order in which things are drawn is key to getting (semi)transparency to work, because transparent pixels are blended with what is underneath. That is why there is a transparent render queue - to specify that things in it should be drawn last.

To me it looks like you have the hair being drawn before the head, and writing to the z-buffer thus preventing the head underneath from being drawn at all. I don't see how you will be able to get it working with everything in one mesh, but I'd be interested to know if you do.

umm... i was thinking that the graphical engine will care about it, but in effect i have difficoult to imagine how, i suppose the best "statistically" ordered of triangle is the one where triangles nearest the epicenter of the object are drowen before, but it is really not a silver bullet.
What really leave me with a strange feeling is that half transparency is managed in a different way wrt total transparency.
basixs said:

Okay, after a quick glance it seems like there is something wrong with your normals and/or the depth precision.
(When I set a CullState, on the model, with the faces set to none half of the hair was right)

I'm sorry but I really ignore what is the dept precision.