How to determine tile color?

Is there a simple way to sample the color of the tiles? I want to make a discrete “heat map” of the vegetation (assume I have a camera “looking down” on earth). Does a ray-based approach work for color sampling?

Thank you.

Hi @beepboop,

When you say “sample the color of the tiles”, do you mean getting the color at a specific point on the tile? I’m not sure how you’re going to construct a continuous heatmap by sampling specific points, but maybe you have a plan :smiley:

I believe it’s possible with Physics.Raycast and the RaycastHit that you get when you hit something. The relevant properties of the Raycast Hit include:

The idea is to get the mesh renderer of the tile that contains the hit collider. You can get this by doing something along the lines of collider.gameObject.GetComponent<MeshRenderer>(). Then, each tile has several textures set in the default material. You can see these parameters if you check out the “CesiumDefaultTilesetMaterial” in the package.

  • If the glTFs in the tileset are textured, they will use the baseColorTexture parameter.
  • If you’re draping a raster overlay onto the tileset (which is what you do for Cesium World Terrain), then the texture is stored in overlay0Texture.

So get the sharedMaterial used by the renderer, and use the UVs from the collision to sample the texture with Texture2D.GetPixelBilinear.

I haven’t tested this code myself, but hopefully it conveys the concept enough for you to make it work!