Render object ID to texture

Hi, I’m wanting to render a texture containing a unique ID (colour) for each object of interest.
This doesn’t have to be realtime so performance isn’t critical.

In pure OpenGL this is trivial (set a uniform for each object to a different ID and render that to a texture), but I’m unsure about how to do this in Unity.

This is to determine both is an object is visible to the camera, but also to see how much of the screen it takes up for a “photography” mechanic.

Ok, managed to figure this out through a lot of trial and error.

Ended up using a cloned camera writing to a rendertexture with “Camera.SetReplacementShader” and a custom shader which just draws solid colours based on the object using [PerRendererData].

hi impbox

how did you solve that i need something like that .
i need a material which i apply on a object which i need as cutout in render and need a alpha image when i render it or any unique object id need to render as image which render same shape which appear in camera view, not the actual object shape.
like my attachment a tree overlap my object so some part of object hide so i need only view part which is shown in my camera render as png image.
guys is there any idea how to do it ,
please help me i am new in unity now