How to tell renderes to use the background image to set their own material.color.

Hi Everyone,
I’m making a game where ants are taking ground/capsules to expand the size of the nest.
Basically I’m using a picture of an underground, as background, with the nest already dug and I added the capsules to hide and simulate a digging effect.

Now here is the tricky part. Right now, every capsules has a material and we see the difference between the capsules and the background. It would look so much nicer if the capsules would each use a different color-material to match the background texture.

I Imagine there could be a way to lay on top of the nest a picture of the Underground with out the nest and tell the Renderes of each capsule to take it’s color depending on the picture set above it.

Maybe world to Screen…
any suggestions?

I’m doing everything in C#

I could use this image to put above or under the capsule group and so give the right texture to each rendere

Not entirely sure I understand your question. The capsule is the blue thing in the lower image right? And you want to tint it with the color of the background texture?

One way to do it is to raycast into the image and get the hit texture coordinate. Read the texture as described in the example. The texture has to be readable.

After you got the color, you could just set capsulesRenderer.material.color.

Obviously you don’t need to perform a raycast, but it’s a convenient way to just get things done. Any way you can map the objects location to texture space would do.