Object/ Polygon draw order

Started by AugTech, March 19, 2014, 06:23:47 PM

Previous topic - Next topic

AugTech

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.

EgonOlsen

#1
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.

AugTech

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?

AugTech

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.


AugTech

Okay, turns out its an Adreno GPU, but I can't see a relevant config chooser...

EgonOlsen

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.

AugTech

#7
Fair comment. It doesn't appear to be making any difference, although the following lines are in logcat;


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!



EgonOlsen

#8
And you are using OpenGL ES 2.0?

Edit: Which device are you using exactly?

AugTech


EgonOlsen

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.

AugTech

Thanks for the info Egon. I'll have a think around how to proceed...!

Lobby

#12
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.

EgonOlsen

You can apply a sort offset to transparent objects. If you do this with some foresight, you can use it to define an order.

Lobby

You mean Object3D.setSortOffset()? I didn't know that method yet but it works good. Thank you very much :D .