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.