Cartoon rendering -- dot3 cel Shading

Source: Internet
Author: User

The cartoon teapot rendered by the method dot3 cel shading in shadex 3 is simpleCodeThe effect is so good. Because it is a cartoon rendering, most calculations except the final coloring can be moved to the vertex shader, but because my code is modified on the basis of normal rendering, therefore, vertex shader only performs basic transformations. In addition, if the highlight is added, the effect is not true. You can use the diffuse reflection calculated by the common illumination model to adjust the effect.

Normal rendering (diffuse reflection + highlight) + Edge Contour:

Cartoon coloring:

Multiple transition zones:

Complete pixel shader code:

Void pixelshader (Out half4 color: color0,
In float3 worldpos: texcoord0,
In float3 normal: texcoord1)
{
Normal = normalize (normal );
Float3 lightvect = normalize (lightpos-worldpos );
Float diffuse = saturate (dot (normal, lightvect ));

Float3 eyevect = normalize (eyepos-worldpos );
 
Half scale = saturate (dot (normal, eyevect ));
Int scalefactor = floor (scale * shaders );
Scale = scalefactor/shaders;
 
If (scale <exclude/shaders)
{
Color. XYZ = 0;
}
Else
{
Diffusecolor = lightcolor * diffusecolor * diffuse;
Color. XYZ = diffusecolor * scale + DIFFUSE/shaders;
}
Color. W = 1.0;
}

Shaders is the number of color bands, and exclude is the width of the edge contour line. In the middle of the figure above, shaders = 4 and exclude = 1.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.