CesiumGS / cesium-unity

Bringing the 3D geospatial ecosystem to Unity
https://cesium.com/platform/cesium-for-unity/
Apache License 2.0
322 stars 75 forks source link

Point clouds render incorrectly on Mac #241

Open j9liu opened 1 year ago

j9liu commented 1 year ago

@joseph-kaile discovered that point clouds don't render correctly on Mac (or more specifically, Metal). Using Unity 2021.3.16f:

I'm seeing some strange behavior in mac. I replaced the Melbourne tileset in the sample scene with the point cloud version. I do see the points, however when I move the camera around, random colors jump around in the screen. out

We tested on main and found that these artifacts happen even with the basic point cloud rendering. I couldn't find any posts about it being a problem with Unity, but I found someone else having this issue: https://github.com/bkaradzic/bgfx/issues/2822

image

I've run into this as well. I know the general solution, but I'm not sure where it would go as a fix within bgfx. Basically on Metal the point size needs to be a vertex shader output. From Apple: The vertex shader must provide [[point_size]], or the point size is undefined. https://developer.apple.com/documentation/metal/mtlprimitivetype/point

I don't think we're doing anything wrong on our side? It seems like something inside Unity's shader code isn't setting the default point size for meshes rendered with MeshTopology::POINTS. I'll submit a bug report and post when / if I get a response.

EDIT: @joseph-kaile also found this Unity forum post confirming it's a Unity and Metal interaction.

j9liu commented 1 year ago

Unity has not acknowledged my bug report, so a workaround we could do is to always enable attenuation on Metal, but set the maximum attenuation size to 1. That way, the point cloud is actually viewable when it is added.