I have seen innumerable examples on how to perform this, yet none of them work anymore, or they only allow one instance of this intersection to appear.
I would like to recreate the intersection shader from The Divison, as seen here
Characters and world geometry alike are highlighted inside a sphere.
As well, the intensity of the highlight is a gradient, where in the center it is less intense, and on the edges, it is most intense.
How can I start this? Will I need to render a sphere several times and use the stencil buffer?
This shader “colors” an area inside a “rendered” mesh: for you case, simply create a material with it, and apply it to a sphere (or whatever) placed appropriately in worldspace. It DOES lack the gradient you mentioned, but it’s a start. (the sample picture uses 2 concentric spheres with different materials, both using this shader)
Well, since you want the sphere highlighting to not be visible behind the car in the front you have to use the stencil buffer. A common implementation could be done by useng a two pass stencil shader. The first pass would render just the front faces of the sphere (cull back) and set the stencil value on pass. The second pass would only render the backfaces of the sphere (cull front) and do a stencil compare to only pass if the stencil value is “1”. The important part of the second pass is that you now only draw when the ztest fails (ztest greater). That means when the backfaces are actually behind something else. The second pass would use alpha blending to render those backfaces. Note that you would need to do the fading based on the distance of each fragment from the center of the sphere.
Note that this technique may give you problems when your camera would “enter” the sphere area. If you want / need to support this case you basically have to implement the usual depth fail stencil shadows. It works similar to this one but instead of actual rendering the sphere we only increment / decrement the stencil value. You would need a thrid pass to actually rendering the sphere visually.