Hello everyone!
I’m very sorry if my question is too banal, I’ve not asked here for any help for years, so I hope I’ll describe my problem sufficiently.
I’m currently trying to fine tune an outline shader… I won’t bother you with all the details and will try to simplify the problem a bit. Basically, I create my custom depth and normal textures with a custom render feature, which works just fine. In order to communicate desired outline colours I’m trying to read the depth from the alpha channel of the depth texture and use the first three channels to represent the desired outline color, something like this:
Right now looks like a normal depth texture:
A photoshop preview of the desired coloured depth texture:
Is it possible to read a color proprety every rendered objects script and imprint it to the depth texture? It actually doesn’t even have to be combined with the depth texture, just generally, is it possible to render all the objects with a simple color shader, but each with a different colour?
Sorry if my language is not technical enough, I can of course share my code, but just a very general tip would be enough of a help, I’ve been studying the manual for days, but I’m probably missing some simple solution.
Thanks a lot for any help, have a good day!
Cheers!
Hi, the (default) Depth Texture doesn’t have any color channel, so I think you can’t.
You can create a custom renderer feature to achieve this. (an example for LWRP, need to change the name space to Universal)
Cons: this will double the draw call so it’s not good for performance. (depends on your scene complexity)
If the color property is the base color (albedo), I will suggest switching to Deferred rendering path.
The albedo color will be stored into the R, G, and B channel of a temporary RT called “_GBuffer0”. (if the shader has a GBuffer pass)
Thank you very much for such a quick response!
The solution you propose is very close to what I’ve been trying to do. I do have a custom shader called something like SuperSimpleColor.shader or whatever which outputs the color property. Then with a custom render feature I create a temporary render texture with all the objects drawn with this shader. The only problem that for some reason I can’t figure out is how to give every object a different colour. I can change the property _Color from the render feature, but it of course changes the color for all the objects. What I’m trying to do is to somehow change the property _Color of each thusly rendered object to a color that is stored for example in a OutlineColorStorage script placed on this object. It doeasn’t even have to be combined with the depth texture, I render my own custom depth texture anyway and overcoming that hurdle later should be easy…
About the second solution, switching to Deferred rendering path would be a pretty radical solution, from the little I know about it, it would mess with the already coded system, but will study it through!
Thanks a lot for all the tips, all this graphics coding is all Greek to me, so please excuse the lack of correct technical terminology…
Cheers!
Are you trying to render something called “Object ID”? (used by some post-processing effects)

Unity’s deferred rendering path doesn’t output this, but you can do it yourself. (some engine’s does this)
- Add an integer property (the Object ID) to the “SuperSimpleColor.shader”.
- Create a C# script that set a unique Object ID to the material in (Skinned) MeshRenderer and attach it to the mesh object(s). ( try this thread )
- In the custom shader pass of “SuperSimpleColor.shader”, output the Object ID (integer) as a color value.
You can add color property instead of integer, but you should make sure that the color value is something that the RT can store accurately. (For “R8G8B8A8”, red channel range is 0-255)