TempCam = new GameObject().AddComponent() We also need to handle our new RenderTexture, and work with binary briefly. Because we can’t use the same camera to render twice in one frame, we need to make a new camera.
So, our new camera code needs to render the objects that reside on a special layer, rendering them with this shader, to a texture. We can make the object get drawn by using Unity’s Camera.RenderWithShader() function. Now, whenever the object is drawn with this shader, it will be white. VertexToFragment VShader(VertexToFragment i) It just draws the object as white, and has the "Outline" tag. This shader goes on the objects themselves. Then we re-draw the outlined objects, but with this shader. We are going to create a shader that ignores lighting or depth testing, and just draws the object as pure white. There are again many ways to select certain objects to render, but I believe this is the cleanest way. Here’s the scene by itself Step 2: Render only the selected objects to another texture OnRenderImage() works as follows: After the scene is rendered, any component attached to the camera that is drawing receives this message, and a rendertexture containing the scene is passed in, along with a rendertexture that is to be output to, but the scene is not drawn to the screen. Void OnRenderImage(RenderTexture source, RenderTexture destination)
Instead, we need to do this as a simple post-processing effect. And to the beginners: the solution is NOT to apply smoothing groups or smooth normals out, or else it will mess with the lighting of the object. While the capsule on the left looks fine, the cube on the right has artifacts. If you need to have an edge on one of your outlined objects, you will get the following result: The WRONG way to do outlines But, the example demonstrated in the Wiki cannot make a “blurred” outline, and it requires smoothed normals for all vertices. There are a couple of ways to do this, and the Unity Wiki covers one of these. One of the simplest and most useful effects that isn’t already present in Unity is object outlines.