- Home /
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.
Answer by impbox · Oct 16, 2017 at 12:32 PM
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
Any idea on how to do this with HDRP 7.5 for Unity 2019.4 LTS?
Answer by aastha10678 · May 15, 2018 at 05:25 AM
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
Your answer
Follow this Question
Related Questions
Obscuring / not rendering parts of an object on camera 2 Answers
CommandBuffer.SetViewProjectionMatrices() does not have any effect, regardless of input 0 Answers
Using custom RenderTexture in ImageEffects. 1 Answer
RenderTexture on RawImage does not render anything 1 Answer
How to read self when CustomRenderTexture dimension is Tex2DArray 0 Answers