nmwsharp / polyscope

A C++ & Python viewer for 3D data like meshes and point clouds
https://polyscope.run
MIT License
1.78k stars 191 forks source link

Backface colors flipped when using different and custom backface shading #227

Open sgsellan opened 1 year ago

sgsellan commented 1 year ago

Hi!

I am using polyscope in python on my intel Mac. When I read this mesh and choose the "backface shading -> custom" option, all faces assume the "inverted" color, despite this mesh being definitely not inverted. Here's a MWE:

import igl
import polyscope as ps
V, _, N, F, _, _ = igl.read_obj("test/unit_tests_data/bunny_oded.obj")
ps.init()
ps.register_surface_mesh("bunny", V,F)
ps.show()

Here is what I see:

Screenshot 2023-07-03 at 11 28 37 PM

nmwsharp commented 1 year ago

After some debugging, it seems that this may actually be due to the underlying graphics drivers. This shader is the one place we use gl_FrontFacing There are scattered posts online that gl_FrontFacing is broken on certain OSX openGL driver versions.

We could potentially work around this by rewriting the shader to manually test for front-facingness using screen space derivatives, but that would presumably decrease performance on non-broken platforms.

It would be good to find some fix for this, but I'm not sure what the right fix is. (Also, can we confirm that this is a broken gl_FrontFacing somehow, and figure out which platforms are effected?)