

However, due to working in object space, the outline still isn't a perfect equal-width outline.

The result is that now all the vertices get moved an equal distance in object space, usually resulting in an outline that looks more equal-width. PositionOS += normalize (positionOS ) * width Move vertex along normalized vertex position in object space. To fix this, you can normalize the vector along which the movement occurs. However, for other objects, these distances may vary and so vertices that are distanced further away from the center of the object, will get moved more. Move vertex along vertex position in object space.ĭoing this just kind of inflates the mesh.įor a sphere, all of the vertices have the same distance from the center point of the object and so they all get moved an equal amount. For the distance, we use a width parameter. This may sound weird but the vertex position in local space, can be seen as a vector between the center of the object and the vertex position itself and so we can move the original vertex position along that vector. This is done by moving each vertex position along the vertex position. The first method to enlarge the mesh is to simply scale it up. The first step is to pick this direction. We will be moving the vertices a certain distance along a certain direction. In order to make the duplicate mesh larger, we need to change the positions of its vertices. The duplicate object is usually just rendered with a flat color. This duplicate object gets shown behind the original object and its vertices get extruded in order to make the duplicate object larger than the original one. The second technique uses a re-rendered/duplicate version of the original object/mesh to form the outline. 💬 Rim effect outlines are simple but only work well on spherical objects. For a more complex model, you will have the issue of getting lots of uneven line widths, although the overall outline effect can look alright. By controlling the width, power and softness of the outline, it is possible to create hard lines or a more soft/glowy effect.įor a cube for example, the outline will look really bad and not even resemble an outline. The technique produces an outline that is always an inner line and is not visible outside of the object and so maybe shouldn't even be called an outline. Return lerp ( 1, smoothstep (edge1, edge2, fresnel ), step ( 0, edge1 ) ) * _OutlineColor float edge1 = 1 - _OutlineWidth įloat fresnel = pow ( 1.0 - saturate ( dot (normalWS, viewWS ) ), _OutlinePower ) This shader implements the fresnel effect and allows us to set the width, power, softness and color of the outline. Implementationįor this approach, the objects that need to have an outline get rendered using a custom shader. When putting this fresnel-based outline on a sphere, you see that when we approach the grazing angle (the edge/rim of the object), the effect gets stronger. It is important to note that this is only an approximation of the fresnel effect, but it works well for our outlines. Then, this gets exponentiated with a power P P P. The formula takes the dot product between the normalized normal vector N N N and the normalized view direction V V V. O u t = p o w (( 1.0 − s a t u r a t e ( d o t ( N, V ))), P ) O u t = p o w ( ( 1.0 − s a t u r a t e ( d o t ( N, V ) ) ), P ) Out = pow((1.0 - saturate(dot(N, V))), P) The following formula is used to form the outline. However, when using it for rendering outlines, this physical meaning of the effect is not important. The fresnel effect describes the reflection/transmission of light when falling onto a transparent surface. One of the most basic outline effects can be achieved by using a so called fresnel effect which can be used to render an outline on the rim/edge of an object. In this post, I will discuss 5 techniques for rendering an outline around an object.
