Set Shading > Diffuse Mode to Toon and lower Roughness to 0.1 or less (mat.roughness = 0.05): in Toon mode roughness sets how soft the light edge is. In our Godot 4.7 test, Toon at the default roughness of 1 spread the edge across 121 px of a 176 px ball, wider than the 66 px of the normal shading it replaced, and lifted the dark side from 1.7 to 27.0 brightness. Roughness 0.1 gave a 15 px edge and roughness 0 a hard 1 px line.
The code
Save it as toon_edge.gd. make_toon() switches one material to Toon with the edge you choose and turns the shiny spot off, or makes it a toon spot with highlight = true. make_all_toon() does the same to every StandardMaterial3D under a node, once per material even when meshes share it. For example: const ToonEdge := preload("res://toon_edge.gd") and ToonEdge.make_all_toon($Level, 0.05).
extends RefCounted
## Hard cel-shaded light on a StandardMaterial3D, no shader needed.
## In Toon mode the material's roughness sets how soft the light edge is.
## Switches a material to toon light. edge 0 = a hard line, higher = softer.
## highlight = true adds a toon specular spot, false turns the shiny spot off.
static func make_toon(mat: BaseMaterial3D, edge := 0.1, highlight := false) -> void:
mat.diffuse_mode = BaseMaterial3D.DIFFUSE_TOON
mat.specular_mode = BaseMaterial3D.SPECULAR_TOON if highlight else BaseMaterial3D.SPECULAR_DISABLED
mat.roughness = edge
## Every StandardMaterial3D used by the meshes under root, switched to toon light.
## Materials shared by several meshes are changed once. Returns how many it changed.
static func make_all_toon(root: Node, edge := 0.1, highlight := false) -> int:
var done := {}
for node in root.find_children("*", "MeshInstance3D", true, false):
var mi := node as MeshInstance3D
if mi.mesh == null:
continue
for i in mi.mesh.get_surface_count():
var mat := mi.get_active_material(i) as BaseMaterial3D
if mat and not done.has(mat):
make_toon(mat, edge, highlight)
done[mat] = true
return done.size()
What we measured
An orange sphere, 176 px across, lit from the side by a DirectionalLight3D, with the specular spot off unless noted. We read the brightness (0 to 255) of 161 pixels across its middle and counted how many pixels sat between 10% and 90% of the way from dark to light. Two runs gave the same numbers.
- Default material (Diffuse Mode Burley, roughness 1): edge 66 px.
- Toon, roughness 1: 121 px, and the dark side at 27.0 instead of 1.7.
- Toon, roughness 0.5: 73 px. 0.2: 30 px. 0.1: 15 px. 0.05: 7 px. 0: 1 px, with only 3 brightness values across the whole row.
- The default specular spot left on, Toon at roughness 0.2 and 0.1: a shiny spot reached full white, 255, on the lit side.
- make_all_toon() on two meshes sharing one material: 1 material changed, edge 15 px. make_toon() with edge 0: 1 px. With highlight on at edge 0.1: a toon spot up to 207.3.
Why it happens
Toon mode keeps the material's roughness and reuses it as the width of the step between lit and unlit, so a material left at roughness 1 gets a wide, soft step that even wraps light around into the shadow side. Roughness also still drives the specular spot, which is why a smooth toon material can show a soft, shiny highlight unless you turn specular off or set it to Toon too. We tested with the Compatibility renderer only.
What to change
- A slightly soft anime edge: try 0.05 to 0.1. A comic-book hard line: 0.
- Outlines to go with it: 3D outline shader without gaps at the corners.
- Toon mode gives one step from light to shadow. Shadows in a color of their own, or a middle tone between light and shadow, need a shader.
A shader that does those: PD Toon World Starter Kit for Godot 4 has a cel shader with lit and shadow bands, colored shadows, an optional middle tone, one hard specular spot and rim light, and its own shadow softness setting, plus an outline, toon water and wind grass in a playable island.
Tested in Godot 4.7 with the Compatibility renderer.
Ready-made: PD Toon World Starter Kit for Godot 4 has a cel shader with colored shadows, a middle tone, rim light and a hard specular spot, in a playable anime-style island.
More how-tos for PD Toon World Starter Kit for Godot 4: Hover a 3D object inside a SubViewport
More how-tos: Shaders, materials and lights
- A 3D outline that stays the same width on screen
- Find and fix the seam in a repeating texture
- PS1 vertex wobble that is the same near and far
- Snow that stays on the roofs
- Packed ORM maps on a StandardMaterial3D
- Neon signs that share a material but not a colour
- A MatCap that stays the right way up from every side
- Scroll or tile a 2D texture without stretched edge lines
- Keep floors, roads and roofs sharp when the camera looks along them
- Make WorldEnvironment color grading apply to a 2D game
- Make metallic materials stop looking black or flat
- Make a glowing sign or screen actually light the wall around it
- Use a LUT strip for color grading in Godot 4
- Tiling textures that keep their size on any mesh
- A sharp low-resolution PS1 look
- Only 8 lights show on a long wall in Compatibility
- Hit flash shader for 2D sprites
- Flash a 3D enemy white when it takes a hit
- Dissolve shader for 3D models
- 2D outline shader that is not cut off
- 3D outline shader without gaps at the corners
- A force field shield with a hit ripple
- Normal map inverted: DirectX vs OpenGL
- Full-screen post-process shader in 3D
- Scroll a shader texture for hours without the once-an-hour jump