Author Topic: Transparent plane and Polyline overlap  (Read 1496 times)

Offline atreyu64

  • byte
  • *
  • Posts: 44
    • View Profile
Transparent plane and Polyline overlap
« on: July 31, 2013, 11:45:06 am »
Hi,


I'm very new with jPCT and this is my first post.
So first congratulations for this great framework, easy to use even for a person not familiar at all with opengl like me, I really appreciate !

I'm planning to develop a kind of "virtual hiking guide" (for a french mountain), showing pathes with polylines and interest points (like mountain huts, lake names, ...) using plane billboards.
It works great and even an old android phone with sdk 2.3.3 can handle my 20000 polygons terrain, which is awesome. To be honest I've tried first another android opengl framework but it couldn't take that amount of polygons. JPCT seems the most performant one !

Anyway, the point is I have a transparency problem with my planes. When a polyline is behind a billboard plane, it is displayed as if it was "in front" of the plane.
I gess the problem comes from my plane transparency, which I have set this way (I need alpha channel) :

Code: [Select]
Object3D plane = Primitives.getPlane(1, size);
if(TextureManager.getInstance().containsTexture(textureName) == false)
TextureManager.getInstance().addTexture(textureName, new Texture(bitmap, true));
plane.setTexture(textureName);
plane.setBillboarding(true);
plane.setTransparency(100);

Note that I also scale the planse according to their distance to camera to make them look always at the same size on the screen, but I don't think it has a link with the issue.

And here is how I create my polylines :

Code: [Select]
Polyline pathLine = new Polyline(pointsArray, color);
pathLine.setWidth(8f);
world.addPolyline(pathLine);

Thanks in advance, and tell me if you need a screenshot, I don't know if what I'm saying is clear, my native language is french.

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11777
    • View Profile
    • http://www.jpct.net
Re: Transparent plane and Polyline overlap
« Reply #1 on: July 31, 2013, 10:24:03 pm »
I see...that's caused by the way in which transparent objects work in combination with the render order. Polylines will be drawn last, i.e. over the transparent objects. They do take the depth buffer into account, but transparent objects don't write into the depth buffer, so for the Polyline, they simply don't exist at all.
How many transparent objects are you using? If it's feasible, you can move them into a separate world instance (which uses the same camera settings as the main world) and render them after the opaque objects and the Polylines. That should fix the problem, but depending on how you are using transparent objects, it might not be very comfortable...i that case, i would have to change something in the render pipeline itself to fix this.

Offline atreyu64

  • byte
  • *
  • Posts: 44
    • View Profile
Re: Transparent plane and Polyline overlap
« Reply #2 on: August 01, 2013, 02:22:03 am »
Hi, thanks a lot for your answer.

Well, if you want to have an idea of how many transparent planes I need :



Is there a way to create transparency without alpha channel, using the setTransparency method but with another color than #0f0f0f ? I mean like if we were using a green screen ? It would be great because I need black color for my textures but I don't need some colors like green. I'll try to replace black pixels with a color a very little bit brighter than #0f0f0f. But antialiasing might ruin it all...

I'll keep you in touch if I find a solution, thanks again !

Offline atreyu64

  • byte
  • *
  • Posts: 44
    • View Profile
Re: Transparent plane and Polyline overlap
« Reply #3 on: August 01, 2013, 02:50:49 am »
Ok what I just said is stupid, if I use a "green screen" or any other color, it would be the same problem because we would still be dealing with transparent objects.
Sorry I'm not familiar at all with rendering concepts, it's very new for me.

Offline atreyu64

  • byte
  • *
  • Posts: 44
    • View Profile
Re: Transparent plane and Polyline overlap
« Reply #4 on: August 01, 2013, 12:16:47 pm »
Hi, I tried what you suggested, using a second world for only transparent objects, and it works great !

Is it the correct way to do it ?

Code: [Select]
fb.clear(back);
world.renderScene(fb); // my initial world
world2.renderScene(fb); // my world for transparent billboards
world.draw(fb);
world2.draw(fb);
fb.display();

What about the performance hit of this method in terms of process and memory ? I didn't notice any change but I'm testing it on a Galaxy S3.

Anyway, thanks a lot for your help !

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11777
    • View Profile
    • http://www.jpct.net
Re: Transparent plane and Polyline overlap
« Reply #5 on: August 01, 2013, 12:36:18 pm »
Yes, that's what i meant. Performance and memory impact are neglectable.

Offline atreyu64

  • byte
  • *
  • Posts: 44
    • View Profile
Re: Transparent plane and Polyline overlap
« Reply #6 on: August 01, 2013, 01:52:37 pm »
Ok so this trick is fine for me, thanks.