Hi all,
I’ve been working with WMS and have successfully been able to load those images. My question is a little more complicated – I have two cameras in my scene and I only want one of those cameras to be able to see the WMS overlay (one camera would show just terrain, and the other would have terrain with WMS OR just WMS).
Is there an easy way to add this kind of functionality to my project outside of making two separate 3D tileset objects on different layers for the cameras to cull?
I’d appreciate any kind of advice or additional info on this. Thanks!
This is a tricky situation! In Cesium for Unity, raster overlays must be draped on geometry, so they can’t be rendered without terrain. And when overlays are draped on terrain, their textures are baked into the tiles that stream in.
I don’t see a way of toggling the WMS overlay for a given view without some shader magic. But it seems possible. This Reddit thread has a few suggestions for how that might happen:
You might have to create a custom material with a parameter that enables this. You can do so by finding Resources in the com.cesium.unity folder. Then, make a copy of CesiumDefaultTilesetMaterial and CesiumDefaultTilesetShader, and modify them as you see fit. Make sure your copied CesiumDefaultTilesetMaterial references the new shader copy, instead of the one provided by the plugin.
I just had one more quick question about working with multiple cameras though – one of the cameras I’m using is typically more zoomed in and actively moving around. I noticed that as the cameras move, tiles get loaded and unloaded, which causes the display on the other camera to look a little distorted sometimes.
Is there a way to control or clean up the way that tiles are loaded with multiple cameras?
I’m glad you were able to get the material working!
Regarding multiple cameras, I just want to confirm: are you using adding the second camera to the CesiumCameraManager component on the CesiumGeoreference? That could be why tiles are unloading from one camera when the other is moving.
It’s also possible—and likely—that this behavior is simply a product of the screen space algorithm we use for tile selection.
In short, each camera selects tiles based on its view, in order to meet the Maximum Screen Space Error set on the tileset. If the one camera is closer to the terrain than the other, it may require that a higher LOD. is loaded. But once it moves away, the other camera is still farther from the terrain, and perhaps has no need for that high LOD. Thus you end up losing that detail as the first camera moves.
Currently there isn’t a way to add some per-camera behavior that would prevent this from happening, but we do have a Github issue open for it. But it’s not an easy issue to solve, so I can’t make any promises about the timeline for a solution. I hope at least that the explanation makes sense.
Thanks for getting back to me! I can’t seem to find a CesiumCameraManager component… Is this a more recently added feature? I did try adding a CesiumCameraController component to the second camera though, but it didn’t seem to help the issue.
I do think it’s most likely related to what you mentioned with the Maximum Screen Space Error though. It does seem like a more complex issue – I appreciate the explanation and hope you guys are able to resolve it soon!