Repos & Downloads:
IMPORTANT: Unreal’s source code is not a public repository, so all forks of it (such as this one) also are not public. You HAVE to read Downloading Unreal Engine Source Code to link your Epic account to Github or the links will give you a 404 error.
@kusogaki77’s fork (4.27): https://github.com/kusogaki77/UnrealEngine/tree/4.27Toon
Github fork link (4.20) (Outdated): https://github.com/SaimonMa/UnrealEngine
Example Project: ToonMaterialProjects - Google Drive
Hello! I just wanted to share some custom shading models I’ve been working on. I’m aware of the shading models that have already been posted on the forum (1)](Toon shading model - Game Development - Epic Developer Community Forums) (2)](Toon shading model for UE 4.20 - Rendering - Epic Developer Community Forums), but I wanted more control over the shading on a per-material or per-pixel basis, so I decided to fork the engine, teach myself HLSL, and take a stab at it. The idea for these models is to have soft indirect lighting but controllable direct lighting so it’s possible to mix the default materials with the custom stylized ones. Note that the code does include a version of stororokw’s anisotropic shader ported to 4.20 since I wanted to build on top of the anisotropic shading to create a toon version.
I’m going to post my upcoming experiments as I try making some manga-style stuff in it, but I’d appreciate any feedback.
Since Offset is a parameter in every Toon material, you can drive it with some screen-oriented masks for halftone or crosshatch effects:
Also, materials have separate controls for specular and diffuse, which I find useful for stylized stuff:
If GBuffers weren’t limited, I could have just made a ubershader with all the features in one shader. Since there’s not many unused GBuffer channels, here’s a couple shading models that (hopefully) cover a wide range of uses, and their controls:
Toon:
General-purpose toon shader. Most control over the shadow and highlight locations.
- Offset: controls the location of the shadow terminator. For faces, a vertex color channel or a texture can be used to push shadows away from the front of the face, or to increase how quickly the shadow appears in crevices, etc.
- Roughness: controls the range of the shadow terminator. Roughness has been decoupled from specular. Max hardness for the terminator is reached at 0.5 roughness. Reflections are still rendered and will be visible at values below 0.5, if you want them.
- Shadow Lightener: a float that lightens the shadow towards the base color of the material.
- Specular Offset: Same as Offset, but for the specular highlight.
- Specular Range: Same as Offset, but for the specular highlight.
Skin:
Skin toon shader with an adjustable SSS color. SSS calculation is based on the Subsurface shading model.
- Subdermal Color: Takes a color. Note that the value for this color drives the strength of the effect, not the Opacity slot like in the standard Subsurface shading mode. I recommend multiplying your color or color texture by a scalar for easy iteration. If you are using a texture to drive the color of the SSS, I recommend multiplying it by a scalar, especially if you want really low SSS values. You’ll get more control this way without texture compression crunching your values too much at low value ranges in the texture.
- Offset: Same as Toon.
- Roughness: Same as Toon.
- Specular: For skin, the specular intensity and sharpness is linked, higher specular values also tighten the specular lobe, and vice versa.
- Specular Offset: Same as Toon.
Hair:
Based on the built in Hair shading model for Unreal, so it will be fairly similar- though it lacks a Backlit parameter (since we’re out of GBuffers again…). Has dual anisotropic highlights.
- Roughness: Same as Toon.
- Specular: Same as Toon.
- Specular Lobe2 Strength: The second lobe is broader and more saturated. This parameter drives the strength of it
- Tighten Specular: Higher values will make the specular highlight narrower.
- Scatter: Works the same way as the built-in Hair shading model. Increase this value to lighten the hair.
- Tangent: Takes the first two values of a vector to assign the anisotropic direction of the hair in UV space, same as the built-in Hair model.
Toon Anisotropic:
Anisotropic shader based on this stororokw’s code, but ported to 4.20.
- Roughness: Same as Toon, but also drives the range of the specular highlight.
- Offset: Same as Toon.
- Specular: Same as Toon.
- Anisotropy: Controls the amount of anisotropy of the material.
- Anisotropic Rotation: Rotates the anisotropy of the material.
- Anisotropic Roughness: Drives the roughness of the anisotropic specular independently from the material’s lighting range.
- Aniso Tangent: 2D vector that controls the Anisotropy using maps like these. This page shows what kind of data the shader expects.
Some of the known issues include:
- odd behavior with point lights with inverse square falloff and area lights with 0 width and height dimensions. I’m not sure what causes this, so if you have insight it would greatly help. Current workaround is to make sure point lights have inverse square falloff turned off.
- for Toon shading model, having a metallic material makes the specular color unable to to be turned off. I’m sure I can figure out where it is multiplying metallicity by specular color somewhere, so I’ll fix this in the future.
- completely untested with the forward renderer, but it almost certainly going to be broken. If you’re interested in this and want forward rendering support, I would appreciate some pointers in the right direction as to what files to poke around in.
Also, I couldn’t have done this without these guys’ tutorials paving the way: