is it possible at all to apply a culling mask to a camera for a specific object rather than a layer? It’s important to my game that there are lots of cameras and each can only render one object. I know I can do this by adding a layer for each object and then doing something like:
But it doesn’t seem very efficient to make a layer for each object. It’s important that a lot of the objects which need to be rendered to separate cameras will be close together so I do need some sort of masking.
One, not ideal, way to do this is by using a custom shader on each object.
If you write a shader with a particular, unique, “tag” for each object, you can then use Camera.RenderWithShader, rather than Camera.Render, to specify the particular tag value of the object you want drawn. Only objects that use a shader containing the specified tag will be drawn. All other shaders are ignored.
Unfortunately, I do not know of anyway to do this dynamically (since the Shader constructors that allows one to to provide a string compiled at runtime, are now depreciated). I think you would need to copy the original shader code into a new shader file, and change the tag manually, for EVERY object you wish rendered separately. (I use this for previews, so I only have one object at a time that need such a shader. Your case sounds quite different, so this may not be the best solution.)