zOffset doesn't work for billboards

Hi,

I’ve tried creating a mesh with billboards as instances. I needed to adjust zOffset to fix some visual artifacts, but “zOffset” doesn’t work in the billboard mode. Maybe that is by design but looks like a bug to me. If there is an alternative approach, please let me know.

Playground

Hey! yeah this seems weird. cc @Cedric to see if he can have a look

add @sebavan as well
I quickly checked the Spector trace and nothing seems obviously wrong

It’s expected. According to the specs (glPolygonOffset - OpenGL 4 Reference Pages):

each fragment's depth value will be offset after it is interpolated from the depth 
values of the appropriate vertices. The value of the offset is factor×DZ+r×units, 
where DZ is a measurement of the change in depth relative to the screen area of the 
polygon, and r is the smallest value that is guaranteed to produce a resolvable 
offset for a given implementation.

In the BILLBOARDMODE_ALL mode, DZ is always 0 so the zOffset value has no impact (it is the factor term in factor×DZ+r×units,). However, you can use the new material.zOffsetUnits to offset the depth (it’s the units term in the factor×DZ+r×units expression). As r is small, you will need a very small zOffsetUnits value to see a difference (something like -1000000).

3 Likes

Man! You nailed it. We did not have time to look into it

Thanks a ton @Evgeni_Popov

Thanks a lot for the explanation!