- Home /
Render everything in black, but the enemies in red
Hello,
i want to make a heat-vision like effect and for that i have a second camera that renders to a texture. What i now want is to render everything in the scene in solid black, except for the enemies. They should appear in solid red. Im looking into Camera.RenderWithShader right now, but i still dont get how to do that. I guess i can turn everything into solid black, but i dont know how to "tag" enemies so they become red.
Any hints?
Thanks in advance chef_seppel
Answer by The-Game-Master · Jun 15, 2015 at 03:53 PM
This is what I'd do. I would make 2 cameras. On camera 1, I would set "Clear Flags" to "Solid Color", set the background color to black, and then set "Culling Mask" to "Nothing". Then, on the second camera, I'd give the enemies their own layer, then set the background to black, set "Clear Flags" to "Solid Color", then set the "Culling Mask" to "Enemies" (or whatever layer you assigned your enemy characters). I'm not sure how to make them red, but I know how to only make the enemies visible. Edit: This is only theoretical, I'm not 100% sure that this will work. I see no reason, however, that it wouldn't.
i tried it and it doesnt work. The second Camera shows exactly what you described. All my enemies on a black background. But the first one is just black. What is pretty much what i was expecting... because it just renders the background and nothing else. Did i miss something?
Answer by suchoparek · Jun 16, 2015 at 05:42 AM
Probably you should create a Camera and set the culling mask to only show the enemies layer, then adding a Color Adjustment Component to render everything in red (you will probably need a Color Correction or something...)
that would be no problem, but then i would always see the enemies. No matter if they are behind an obstacle or not. But i want them to be occluded by obstacles.
$$anonymous$$aybe this is a little overdoing, but you could use Depth$$anonymous$$ask: http://wiki.unity3d.com/index.php/Depth$$anonymous$$ask Basically this shader draws the depth buffer but not the RGBA channel. You can assign this shader to every object that has to cover the enemies, then raise the RenderQueue of the enemies. As a result, the enemies will be drawn behind the objects with the shader.
hmm, assigning a special shader manually to all obstacles is not practical in my case. So could i do it with Camera.RenderWithShader?
Your answer
Follow this Question
Related Questions
CommandBuffer's CameraEvent ordering not in sync with shader rendering queue? 1 Answer
Is it possible to only render on one side of a plane? 4 Answers
RenderTexture to Shader everyframe 0 Answers
"Motion vectors" and "depth with normals" from camera's target texture 1 Answer
Uniform Texture, Rendering Problem 0 Answers