Author Topic: Transparency Problem (and More)  (Read 5848 times)

Offline AGP

  • quad
  • ******
  • Posts: 1726
    • View Profile
Transparency Problem (and More)
« on: June 18, 2012, 02:37:03 am »
I made the ground texture as bright as possible to avoid this issue (no such luck). For some reason if instead of merging all the ground parts I add them as children of one of the parts (in order to test for what's the ground and not calling setTransparency(100) on it) I don't get a collision with the ground (and I am individually calling setTransparencyMode and setCollisionOptimization on the individual parts). Which brings us to this problem: all of the trees in this image are actually set behind the hills ahead and should therefore not be visible. What's odd is that the ground doesn't really appear to be transparent (seems more like a Z-buffer issue).


Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: Transparency Problem (and More)
« Reply #1 on: June 18, 2012, 08:19:51 am »
setTransparency(100) is almost opaque, so you won't see much of a transparency. But you still get the sorting and based on the midpoint, the terrain will be sorted behind the trees...and that's what you are getting here. Why do you set the terrain to transparent at all? Don't do this and the issue with the trees will go away.

Offline AGP

  • quad
  • ******
  • Posts: 1726
    • View Profile
Re: Transparency Problem (and More)
« Reply #2 on: June 18, 2012, 08:55:10 am »
Because the trees have to be part of the terrain. When I tried making them children, I got the aforementioned problem with collision. They HAVE to be merged to the ground, and, naturally, they need their transparency.

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: Transparency Problem (and More)
« Reply #3 on: June 18, 2012, 09:55:52 am »
Quote
They HAVE to be merged to the ground, and, naturally, they need their transparency.
No, they don't have to and shouldn't be part of the terrain. You'll never get correct sorting between the terrain and the trees that way plus you are killing fillrate for no reason by rendering everything with alpha. I don't get the actual problwm with collisions...who collides with what here and what doesn't work if the trees remain separate objects?

Offline AGP

  • quad
  • ******
  • Posts: 1726
    • View Profile
Re: Transparency Problem (and More)
« Reply #4 on: June 18, 2012, 10:04:34 am »
calcMinDistance, for some bizarre reason, doesn't work when I don't merge the trees to the ground. I don't get it either, but when I do merge everything collision works like a charm.

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: Transparency Problem (and More)
« Reply #5 on: June 18, 2012, 10:11:31 am »
calcMinDistance, for some bizarre reason, doesn't work when I don't merge the trees to the ground. I don't get it either, but when I do merge everything collision works like a charm.
Makes no sense to me. Maybe you are missing some operations you are doing on the terrain when merging anything that prevent the collisions from working like not setting the collision state by accident or setting it for the wrong object or something like this.

Offline AGP

  • quad
  • ******
  • Posts: 1726
    • View Profile
Re: Transparency Problem (and More)
« Reply #6 on: June 18, 2012, 10:14:23 am »
No, I looked it over for hours. Only thing that got them to be triggered was treating everything as one model. The loop which added the objects as children of the ground had an exact copy of the code for the merged ground.

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: Transparency Problem (and More)
« Reply #7 on: June 18, 2012, 10:26:13 am »
That can't be. Something has to be different....

Offline AGP

  • quad
  • ******
  • Posts: 1726
    • View Profile
Re: Transparency Problem (and More)
« Reply #8 on: June 18, 2012, 07:13:54 pm »
Here's my loop:

Code: [Select]
ground = Object3D.createDummyObj();
Object3D[] parts = Loader.loadOBJ("NewLevel/Forest.obj", "NewLevel/Forest.mtl", 1f);
for (int i = 0; i < parts.length; i++) {
     if (!parts[i].getName().startsWith("ground"))
parts[i].setTransparency(100);
     parts[i].setCollisionMode(Object3D.COLLISION_CHECK_OTHERS);
     parts[i].setCollisionOptimization(true);
     parts[i].addCollisionListener(this);
     theWorld.addObject(parts[i]);
     if (buffer.usesRenderer(IRenderer.RENDERER_OPENGL))
parts[i].compileAndStrip();
     ground.addChild(parts[i]);
}
ground.rotateX((float)Math.PI);//WHY IS IT UPSIDE DOWN RIGHT OUT OF MAX?
ground.translate(0, 30f, 0);
for (int i = 0; i < parts.length; i++)
     parts[i].enableLazyTransformations();

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: Transparency Problem (and More)
« Reply #9 on: June 18, 2012, 11:02:28 pm »
OK...and how does the merge part looks, i.e. the version in which you merge everything into one large lump?

BTW: Are you calling build() on each part of parts[] somewhere? I just want to be sure, because i don't see it in this code snippet.
« Last Edit: June 18, 2012, 11:44:58 pm by EgonOlsen »

Offline AGP

  • quad
  • ******
  • Posts: 1726
    • View Profile
Re: Transparency Problem (and More)
« Reply #10 on: June 18, 2012, 11:55:22 pm »
Yes, I call world.buildAllObjects() much later in the method. The "original" code looked exactly like that. I'm sure I'm not missing anything. Am I? Perhaps the order of the operations is wrong?

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: Transparency Problem (and More)
« Reply #11 on: June 19, 2012, 12:04:20 am »
Well...i meant the variant that merges all trees with the terrain. That can't be that code snippet, because i don't see any merge operation at all... ???

Offline AGP

  • quad
  • ******
  • Posts: 1726
    • View Profile
Re: Transparency Problem (and More)
« Reply #12 on: June 19, 2012, 12:17:49 am »
Like I said, exactly the same but with mergeAllObjects and without a loop. I didn't comment it out, I moved the original code, not necessarily in the same order, into the new loop (for an older version I have to go home and post it--but other than the order of the operations it is exactly the same).

Offline AGP

  • quad
  • ******
  • Posts: 1726
    • View Profile
Re: Transparency Problem (and More)
« Reply #13 on: June 19, 2012, 01:54:28 am »
This code works (but produces the transparency issue):

Code: [Select]
     private void loadGround() {
ground = Object3D.mergeAll(Loader.loadOBJ("NewLevel/Forest.obj", "NewLevel/Forest.mtl", 1f));
ground.setTransparency(100);
ground.setCollisionMode(Object3D.COLLISION_CHECK_OTHERS);
ground.rotateAxis(ground.getXAxis(), (float)Math.toRadians(180));
ground.translate(0, 30f, 0);
ground.setCollisionOptimization(true);
ground.addCollisionListener(this);

theWorld.addObject(ground);
skyBox = new SkyBox(800);
if (buffer.usesRenderer(IRenderer.RENDERER_OPENGL)) {
     skyBox.compile();
     ground.compileAndStrip();
}

theWorld.buildAllObjects();
ground.enableLazyTransformations();
     }

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: Transparency Problem (and More)
« Reply #14 on: June 19, 2012, 08:07:42 am »
The main difference between the two seems to be the use of a common parent object in the upper one. Albeit this should work, maybe there is some problem related to it.

Please try:

  • remove the calls to enableLazy...
  • get rid of the common parent object

to see if any of that helps.