Author Topic: Object/ Polygon draw order  (Read 1990 times)

Offline AugTech

  • int
  • **
  • Posts: 64
    • View Profile
    • Augmented Technologies
Object/ Polygon draw order
« on: March 19, 2014, 06:23:47 pm »
Hi.
Is there anyway to specify a drawing order for objects?

Think of a plane used for the ground with a texture on it. I'm adding a 2D object on top of the ground - for example a puddle. Currently there is a lot of 'flickering' of the two objects during rendering. I'm guessing the GPU (?) can't decide what should be on top of what.

Any suggestions would be great!

Thanks.

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11748
    • View Profile
    • http://www.jpct.net
Re: Object/ Polygon draw order
« Reply #1 on: March 19, 2014, 07:30:04 pm »
No, you can't...at least not for opaque objects. And there's no point in doing this anyway, because it won't solve your problem. The rendering order of opaque objects doesn't matter. What is in front and what is behind is determined by the zbuffer regardless of the order in which objects are being rendered. In your case, the depth buffer's accuracy isn't sufficient, which leads to common problem called z-fighting. To avoid this, you can move the two objects further apart or split rendering of the plane and the puddle by moving them into different worlds and clear the depth buffer between rendering both worlds. However, this can cause others problems if the plane is supposed to hide some objects or parts of them.
Another option is to check if your depth buffer's accuracy can be increased. This is possible on Tegra and Adreno gpus. Are you using one of these?
Btw: This only applies if at least one object is opaque. If the plane and the puddle are both transparent, then it's another story.
« Last Edit: March 19, 2014, 07:32:27 pm by EgonOlsen »

Offline AugTech

  • int
  • **
  • Posts: 64
    • View Profile
    • Augmented Technologies
Re: Object/ Polygon draw order
« Reply #2 on: March 20, 2014, 10:16:15 am »
Thanks for the explanation Egon.
I remember the z-fighting explanation now.

I'm pretty sure I'm on Tegra, but obviously this cant be guaranteed on all devices, so it looks like the best solution is to move the objects further apart. Any suggestion on a value?

Offline AugTech

  • int
  • **
  • Posts: 64
    • View Profile
    • Augmented Technologies
Re: Object/ Polygon draw order
« Reply #3 on: March 20, 2014, 12:31:02 pm »
Okay, tried that but to no avail. Even with -5f offset, still getting z-fighting.

Also tried   Config.stateOrientedSorting=false; but it didn't help.

How does one alter the accuracy of the GPU (as you mentioned)?

Ta.

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11748
    • View Profile
    • http://www.jpct.net
Re: Object/ Polygon draw order
« Reply #4 on: March 20, 2014, 01:19:52 pm »

Offline AugTech

  • int
  • **
  • Posts: 64
    • View Profile
    • Augmented Technologies
Re: Object/ Polygon draw order
« Reply #5 on: March 20, 2014, 03:17:39 pm »
Okay, turns out its an Adreno GPU, but I can't see a relevant config chooser...

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11748
    • View Profile
    • http://www.jpct.net
Re: Object/ Polygon draw order
« Reply #6 on: March 20, 2014, 03:21:50 pm »
That's the same one. That's why the last sentence in the docs says:

Quote
This might also help to improve depth buffer accuracy on other chips than Tegra, because the default config that it chooses will have a depth higher than 16bit if possible.

Adreno is the only GPU (that i know of), that defaults to a 16bit zbuffer.

Offline AugTech

  • int
  • **
  • Posts: 64
    • View Profile
    • Augmented Technologies
Re: Object/ Polygon draw order
« Reply #7 on: March 20, 2014, 03:26:26 pm »
Fair comment. It doesn't appear to be making any difference, although the following lines are in logcat;

Code: [Select]
03-20 14:24:14.246: W/Adreno-EGL(7707): <qeglDrvAPI_eglChooseConfig:824>: EGL_BAD_ATTRIBUTE
03-20 14:24:14.246: I/jPCT-AE(7707): No nonlinear depth buffer config found...using default mode!
03-20 14:24:14.246: I/jPCT-AE(7707): Unable to find a matching config...using default!

« Last Edit: March 20, 2014, 03:31:05 pm by AugTech »

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11748
    • View Profile
    • http://www.jpct.net
Re: Object/ Polygon draw order
« Reply #8 on: March 20, 2014, 04:18:26 pm »
And you are using OpenGL ES 2.0?

Edit: Which device are you using exactly?
« Last Edit: March 20, 2014, 04:21:45 pm by EgonOlsen »

Offline AugTech

  • int
  • **
  • Posts: 64
    • View Profile
    • Augmented Technologies
Re: Object/ Polygon draw order
« Reply #9 on: March 20, 2014, 04:31:13 pm »
Yep GLES2.0oin Sony Experia Z

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11748
    • View Profile
    • http://www.jpct.net
Re: Object/ Polygon draw order
« Reply #10 on: March 20, 2014, 05:39:39 pm »
Well, then maybe it just doesn't help in this case. It helps most on far away objects, which might not apply here. If your map stays flat, it might be feasible to split rendering into two world that are using the same camera and clear the depth buffer between both world render as i suggested above.

Offline AugTech

  • int
  • **
  • Posts: 64
    • View Profile
    • Augmented Technologies
Re: Object/ Polygon draw order
« Reply #11 on: March 20, 2014, 07:20:25 pm »
Thanks for the info Egon. I'll have a think around how to proceed...!

Offline Lobby

  • int
  • **
  • Posts: 66
    • View Profile
    • flowersoft
Re: Object/ Polygon draw order
« Reply #12 on: March 21, 2014, 12:40:24 pm »
I would really appreciate to see a feature to define a draw order for transparent objects. It would be helpful for the 2D (3D based) engine I'm currently working on.
« Last Edit: March 21, 2014, 12:42:02 pm by Lobby »

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11748
    • View Profile
    • http://www.jpct.net
Re: Object/ Polygon draw order
« Reply #13 on: March 21, 2014, 01:46:04 pm »
You can apply a sort offset to transparent objects. If you do this with some foresight, you can use it to define an order.

Offline Lobby

  • int
  • **
  • Posts: 66
    • View Profile
    • flowersoft
Re: Object/ Polygon draw order
« Reply #14 on: March 21, 2014, 04:00:23 pm »
You mean Object3D.setSortOffset()? I didn't know that method yet but it works good. Thank you very much :D .