0%

Tone-based shading is a common method to implement Non-Photorealistic Rendering. The core idea is using the diffuse coefficient to sample a ramp texture.

1
2
3
fixed diff = dot(normal, lightDir);
fixed halfLambert = diff * 0.5 + 0.5;
fixed3 diffuse = _LightColor0.rgb * albedo * tex2D(_Ramp, float2(halfLambert, halfLambert)).rgb;

Here has a problem that the Ramp texture’s Wrap Mode should be set to “Clamp.” Although the halfLambert value is clamped to 0.0 and 1.0, due to the accuracy issue of float, some values will be slightly larger then 1.0. And in repeat mode the sample result will be error.

  • The final effect.

This is one of the most common interview questions. I used to said that new/delete will call constructor and deconstructor, but malloc/free not. However, except this, there are many other differences.

Read more »