Loosely inspired by the Unity-chan shaders with a few extra niceties like MSDF ink lines and geometry-shader outline emission.
Above: MSDF for the black lines inside, 3 step tone-map, white rim-highlight, and GS-emitted outline.
Requirements
- Colormap (texture 0)
- ToneMap (texture 7)
- controls the shade falloff
- leftmost is perpendicular, rightmost is aligned to the light direction
Options
- Hair highlight ring (cylindrical matcap basically)
- tex 4
- Matcap / Spherical environment map
- tex 4
- Rim highlight (TOON_RIMLIGHT)
- MSDF Linework map for sharp sketch lines (TOON_LINE_MAP)
- tex 5
- Control map (force light/dark)
- tex 3
- R: min allowed shade, G: max allowed shade, B: unused, A: matcap mask
- Vertical shade map
- Clips maximum possible lighting, like the control map can
- Nx1 texture is silly quick to update at runtime for changes (hat shadow, etc)
- provide size coordinates for normalization to
VerticalRampShift
parameter
- Clips maximum possible lighting, like the control map can
- Specular is used as per legacy pipeline
- not toon clipped in any way, it’s special
Toon.hlsl
contains documentation at the top.
Outlines
- Geometry shader outlines included (if you have GS support)
- emits flipped winding triangles
-
Toon_Outline.hlsl
can be used in an additional render-path pass (with the culling flipped) to do outlines with the same config-
OutlinePower
: x = offset along normal, y = offset along view-vector
-
https://gist.github.com/JSandusky/4f9a4f00110691eb45104f69abd32f75
Shouldn’t be too much cruft in there. Tessellation (lots of code no one can use) and light-prepass stripped out (not for stock prepass, would be confusing to look at).
I’ll probably port to GLES3 and GL3.1 (interface blocks)