polygonOffset and logarithmic depth

198 views
Skip to first unread message

Kevin Ring

unread,
Nov 21, 2018, 6:08:41 PM11/21/18
to cesium-dev
Hi,

I'm rendering some outlined solids via glTF. The outlines are just separate line primitives. Of course, it looks bad due to Z-fighting:

outlined-solid-before.png


As a proof of concept, I hacked up Model.js to render the filled faces with a polygonOffset (0.75 / 1.0), and it looks great:

outlined-solid-after.png


But that screenshot above is with logarithmic depth disabled. When it's enabled, the fragment shader writes depth, overriding the effect of the polygonOffset, and we're back at the first screenshot above.

Looking at other parts of the Cesium code that use polygonOffset, it seems like the Vector3DTilePolygons will have the same problem. Perhaps it was written before Cesium used logarithmic depth?

In any case, I was wondering if you guys have already thought about how to combine polygonOffset with logarithmic depth. Presumably the fragment shader needs to apply the depth offset manually, but the code to mimic the fixed-function behavior isn't at all obvious to me, and the internet is surprisingly unhelpful.

If I get this working reasonably well, my plan is to define a glTF extension for outline rendering in my fork. Happy to PR it upstream if it's something others might be interested in.

Kevin

Kevin Ring

unread,
Nov 21, 2018, 6:09:47 PM11/21/18
to cesium-dev

Kevin Ring

unread,
Nov 21, 2018, 6:11:02 PM11/21/18
to cesium-dev
I meant to say Vector3DTilePolylines would have the same problem, not Vector3DTilePolygons.


On Thursday, November 22, 2018 at 10:08:41 AM UTC+11, Kevin Ring wrote:

Omar Shehata

unread,
Dec 5, 2018, 11:12:10 AM12/5/18
to cesium-dev
Hey Kevin,

I pinged Dan to take a look at this since he's most familiar with log depth. Hopefully you'll get a response soon!

Kevin Ring

unread,
Dec 8, 2018, 6:33:25 AM12/8/18
to cesiu...@googlegroups.com
Thanks Omar. I've been using this super cheesy but mostly good enough solution:

It basically just subtracts a fixed amount of the depth value. It works well when the polygons are facing the camera, but it's not great when the polygons are at an angle to the camera because it doesn't scale the depth adjustment with the Z slope the way polygonOffset does.

Kevin


--
You received this message because you are subscribed to the Google Groups "cesium-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cesium-dev+...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


--

Chris Wang

unread,
Apr 10, 2019, 10:34:33 PM4/10/19
to cesium-dev
Hi Kevin

I render the outline with your method. 
gl_FragDepthEXT -= 5e-5;
It looks well. BUT the problem is when I can pick the outline, the position is alaways undefined. 
It seems that Cesium calculate the position by depth(here). So if I minus the depth by 5e-5, it become zero.

I wonder if you have ever met the problem?

if so, did you find a solution? 

THANKS.
Chris.

在 2018年12月8日星期六 UTC+8下午7:33:25,Kevin Ring写道:
Thanks Omar. I've been using this super cheesy but mostly good enough solution:

It basically just subtracts a fixed amount of the depth value. It works well when the polygons are facing the camera, but it's not great when the polygons are at an angle to the camera because it doesn't scale the depth adjustment with the Z slope the way polygonOffset does.

Kevin


On Thu, Dec 6, 2018 at 3:12 AM Omar Shehata <omar.sam...@gmail.com> wrote:
Hey Kevin,

I pinged Dan to take a look at this since he's most familiar with log depth. Hopefully you'll get a response soon!

On Wednesday, November 21, 2018 at 6:11:02 PM UTC-5, Kevin Ring wrote:
I meant to say Vector3DTilePolylines would have the same problem, not Vector3DTilePolygons.

On Thursday, November 22, 2018 at 10:08:41 AM UTC+11, Kevin Ring wrote:
Hi,

I'm rendering some outlined solids via glTF. The outlines are just separate line primitives. Of course, it looks bad due to Z-fighting:

outlined-solid-before.png


As a proof of concept, I hacked up Model.js to render the filled faces with a polygonOffset (0.75 / 1.0), and it looks great:

outlined-solid-after.png


But that screenshot above is with logarithmic depth disabled. When it's enabled, the fragment shader writes depth, overriding the effect of the polygonOffset, and we're back at the first screenshot above.

Looking at other parts of the Cesium code that use polygonOffset, it seems like the Vector3DTilePolygons will have the same problem. Perhaps it was written before Cesium used logarithmic depth?

In any case, I was wondering if you guys have already thought about how to combine polygonOffset with logarithmic depth. Presumably the fragment shader needs to apply the depth offset manually, but the code to mimic the fixed-function behavior isn't at all obvious to me, and the internet is surprisingly unhelpful.

If I get this working reasonably well, my plan is to define a glTF extension for outline rendering in my fork. Happy to PR it upstream if it's something others might be interested in.

Kevin

--
You received this message because you are subscribed to the Google Groups "cesium-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cesiu...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

Kevin Ring

unread,
Apr 11, 2019, 9:56:55 PM4/11/19
to cesiu...@googlegroups.com
Sorry Chris, I haven't run into that as I'm not using pickPosition for much of anything. I suspect that will be a difficult problem to solve completely. Perhaps choosing the value to subtract more carefully would help, but if you're adjusting depth at all then certainly a position computed from depth will be affected.

To unsubscribe from this group and stop receiving emails from it, send an email to cesium-dev+...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.


--

Kevin Ring

unread,
May 14, 2019, 1:25:56 AM5/14/19
to cesium-dev
Hi Chris,

I just realized I overlooked a simple solution when I responded before. We just need to disable the depth adjustment during the `pick` rendering pass. Unfortunately the pass isn't a parameter to the function where the adjustment is added, but it should be possible to weave it down through.

Kevin
Reply all
Reply to author
Forward
0 new messages