www.jpct.net

jPCT-AE - a 3d engine for Android => Support => Topic started by: AugTech on March 19, 2014, 06:23:47 pm

Title: Object/ Polygon draw order
Post by: AugTech 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.
Title: Re: Object/ Polygon draw order
Post by: EgonOlsen 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.
Title: Re: Object/ Polygon draw order
Post by: AugTech 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?
Title: Re: Object/ Polygon draw order
Post by: AugTech 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.
Title: Re: Object/ Polygon draw order
Post by: EgonOlsen on March 20, 2014, 01:19:52 pm
You have to use this config chooser: http://www.jpct.net/jpct-ae/doc/com/threed/jpct/util/NVDepthConfigChooser.html (http://www.jpct.net/jpct-ae/doc/com/threed/jpct/util/NVDepthConfigChooser.html)
Title: Re: Object/ Polygon draw order
Post by: AugTech on March 20, 2014, 03:17:39 pm
Okay, turns out its an Adreno GPU, but I can't see a relevant config chooser...
Title: Re: Object/ Polygon draw order
Post by: EgonOlsen 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.
Title: Re: Object/ Polygon draw order
Post by: AugTech 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!

(http://www.awila.co.uk/files/z-fighting.png)
Title: Re: Object/ Polygon draw order
Post by: EgonOlsen on March 20, 2014, 04:18:26 pm
And you are using OpenGL ES 2.0?

Edit: Which device are you using exactly?
Title: Re: Object/ Polygon draw order
Post by: AugTech on March 20, 2014, 04:31:13 pm
Yep GLES2.0oin Sony Experia Z
Title: Re: Object/ Polygon draw order
Post by: EgonOlsen 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.
Title: Re: Object/ Polygon draw order
Post by: AugTech on March 20, 2014, 07:20:25 pm
Thanks for the info Egon. I'll have a think around how to proceed...!
Title: Re: Object/ Polygon draw order
Post by: Lobby 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.
Title: Re: Object/ Polygon draw order
Post by: EgonOlsen 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.
Title: Re: Object/ Polygon draw order
Post by: Lobby 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 .