← Pixel Dreamer Studio

Get a hard cel-shaded light edge from StandardMaterial3D's Toon mode

In Toon mode, roughness is the softness of the line between light and shadow. The default of 1 makes it softer than no toon at all.

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.

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 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