How to make a cartoon effect

How to make a cartoon effect

This article from the reference tutorial , add their own little experiences.

First, as an object plus diffuse lighting. We can use the light parallel to the normal line direction of the object with the angle, i.e. the vector dot product, to measure the illumination intensity of the object suffered. In order to achieve the effect of cartoon, light intensity will be divided into two sections, 0 and 1, when the vector dot product is greater than 0, the light intensity is 1, and 0 otherwise. Between the two can be smoothed by smoothstep. First look at the results:

No light can be found in a place too dark, add a constant ambient light to increase the brightness of it:

Next, we add the object to specular highlights. Here we use the Blinn-Phong illumination model, the line of sight vector with binary vectors and vector parallel light, the intensity of specular highlights is the angle between the normal analog. Also, since a cartoon style, we smoothed segmented smoothstep with high light intensity, the effect is as follows:

Then, we give the object plus stroke. Region appears to satisfy such a stroke properties: i.e., the angle to the normal line of sight vector is relatively large, the dot product is relatively small. It is also easier to understand, only the line of sight of sight will be stroked. Further, there is light only in the region of the stroke only, to achieve the following:

                fixed nDotV = 1 - dot(normal, viewDir);
                fixed rimIntensity = nDotV * pow(nDotL, _RimThreshold);
                rimIntensity = smoothstep(_RimAmount - 0.01, _RimAmount + 0.01, rimIntensity);
                float4 rimColor = _RimColor * rimIntensity;

Use pow function is to allow rimIntensity value with changes nDotL rapid changes. _RimThreshold is a value ranging between 0 and 1, for controlling the growth of the entire function pow. Curves look different values ​​in the case where the function pow (from top to bottom are 0.1,0.3,0.5):

Can be found, _RimThreshold smaller value, the faster the growth rate.

Finally, we add the shadow effect for the objects. Cast shadows can use legacy shader Unity comes SHADOWCASTER of. Receiving projection may be used unity comes SHADOW_COORDS , TRANSFER_SHADOW , SHADOW_ATTENUATION of shadowmap sampled. SHADOW_ATTENUATION returns a value between 0 and 1, 0 being completely covered by the shadow, represents no shadow. Thus, we get a direct return value by multiplying the light intensity, the stronger the light so that the shadows weaker, is exactly where the shadow of the light intensity is zero. The final results are as follows:

In summary, to implement a simple cartoon effect as follows:

  1. Use Blinn-Phong illumination model object plus diffuse and specular highlights
  2. Use smoothstep the light intensity is divided into two regions, a smooth transition
  3. Using the sight line vector and the normal of the angle of the object stroke effect increases, and only the light only where the stroke by stroke so that the function pow effect as changes in the light intensity changes rapidly
  4. Using the built-in function and a receiving object plus shadow cast shadows effects

Guess you like

Origin www.cnblogs.com/back-to-the-past/p/12602299.html