threejs-ghibli-toon-shading
Skill4 starsChanged 19 days agoMITView on GitHub
Adds Studio Ghibli–style anime shading to existing three.js MeshStandardMaterial/MeshPhysicalMaterial objects via one onBeforeCompile patch helper — banded toon diffuse that keeps soft PCF shadows and GGX specular (RE_Direct wrapper), warm never-grey shadow fill, spherical "puff" normals for foliage clumps (k-means clusterCenter for baked GLB leaves), backlit subsurface glow, rim light, painterly leaf flecks, warm grained bark, and world-space wind with matching customDepthMaterial so dappled shadows move. Use when the user asks for Ghibli/anime/cel/toon look on trees, bushes or props, painterly foliage, puffy canopies, toon ramp without banded shadows, leaf wind sway, or moving leaf shadows.
In this repository30 other files it gives its agents.
- threejs-blender-glb-pipelineSkill
- threejs-boat-buoyancy-steeringSkill
- threejs-camera-guided-tourSkill
- threejs-cinematic-loading-screenSkill
- threejs-day-cycle-lightingSkill
- threejs-dreamy-glass-hudSkill
- threejs-first-person-bvh-walkSkill
- threejs-fish-school-boidsSkill
- threejs-floating-island-landmarkSkill
- threejs-ghibli-night-modeSkill
- threejs-ghibli-sky-cloudsSkill
- threejs-glb-realism-pipelineSkill
- threejs-gpu-butterfliesSkill
- threejs-headless-visual-verificationSkill
- threejs-hud-objective-markersSkill
- threejs-night-lights-lanternsSkill
- threejs-object-interactionSkill
- threejs-open-world-streamingSkill
- threejs-postprocessing-anime-gradeSkill
- threejs-procedural-vegetationSkill
- threejs-shell-fur-renderingSkill
- threejs-skeletonless-character-animationSkill
- threejs-stylized-rock-materialSkill
- threejs-webaudio-generative-soundtrackSkill
- threejs-webgl-performance-profilingSkill
- threejs-webgl-rain-effectSkill
- threejs-webgl-realistic-waterSkill
- threejs-webgl-underwater-effectSkill
- threejs-webgl-wake-simulationSkill
- threejs-webgl-waterfall-effectSkill
The file
We split this skill into the rules it gives an agent
2 rules. About 0 are common, 1 is distinctive, and 1 is very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈1
Distinctive · estimate
This author's own choices. Worth a look.
1
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 72
Don't gamma-lift ndl in a ramp(ndl)/ndl ramp below ~0.85 — grazing light gets boosted ~3× and the scene washes out.
- Distinctive: line 87
Look toward the sun through leaves: warm yellow-green glow, not white.
≈ “Common” is an estimate: at least 1 in 5 of the 408,460 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Ghibli toon shading for foliage, bark and props
Turns physically lit foliage into the soft-banded, sun-glowing canopy of a Ghibli background: each leaf clump shades as one puffy volume, light falls in 2–3 soft steps, leaves glow yellow-green when backlit, shadows are warm brown instead of grey, and everything sways with shadows that move in sync.
Stack: three.js WebGLRenderer (proven on r186), vanilla or R3F. Built materials (MeshStandardMaterial, MeshPhysicalMaterial, MeshDepthMaterial) are patched with onBeforeCompile so they keep three's shadows, fog, instancing and tone mapping. One shared uniform object means one lil-gui slider re-tunes every material at once.
When to use
- Foliage from GLBs or procedural cards looks like green noise or plastic.
- You want a toon look but three's
MeshToonMaterialloses soft shadows/specular. - Leaves move in the main pass but their shadows are frozen.
Paste-ready prompt
Give the trees, bushes and leaves in
{{entry file}}an authentic Studio Ghibli look matching{{reference image}}. Use onepatch(material, options)helper aroundonBeforeCompilewith a single shared uniform object (options:toon,puff,flecks,rim,sss,bark,wind,flutter,fill), every value in a lil-gui "Ghibli Tune" folder.
- Puff normals: blend each leaf normal toward the vector from its clump centre,
normalize(mix(normal, sphereNormal, 0.6–0.8)). Baked GLB foliage has no clump data: derive a per-vertexclusterCenterwith seeded k-means over triangles (~36 clusters, 10 iterations). Blend afternormal_fragment_maps.- Banded toon light without banded shadows: inline
THREE.ShaderChunk.lights_fragment_begin,replaceAll('RE_Direct( directLight,', 'RE_Direct_Toon( directLight,'), scaledirectLight.colorbytoonRamp(ndl)/ndland call the stockRE_Direct_Physical. Inject the helper after#include <lights_physical_pars_fragment>.- Backlight SSS
pow(saturate(dot(-V, L)), 3) * translucencyin a warm yellow-green, a saturated rim on silhouettes, painterly object-space leaf flecks.- Warm shadow fill: record
gLit = ndl·shadowin the wrapper; afterlights_fragment_endaddalbedo · fillColour · fill · (1 − gLit).- Wind in a replaced
project_vertex, in world space afterinstanceMatrix: slow height-weighted sway + high-frequency flutter. Give every foliage mesh acustomDepthMaterialpatched with the identical wind.- Bark: warm painterly wood, vertical grain noise, darker at the roots and up inside the canopy. Screenshot close-up, eye-level and wide after each step and compare with the reference.
Implementation
The complete helper is in references/ghibli-patch.js; k-means is in references/cluster-centers.js.
Patch helper structure
mat.customProgramCacheKey = () => JSON.stringify(options)— otherwise three shares one program between differently patched materials.- Vertex: add noise + wind GLSL after
#include <common>; setvLocal = positionafterbegin_vertex(object-space coords for flecks/bark); replaceproject_vertexwith instance → world → wind offset → view; replaceworldpos_vertexso shadow lookups use the displacedwPos. - Fragment injection points:
common(defines + uniforms),lights_physical_pars_fragment(toon/SSS wrapper),lights_fragment_begin(inlined, withRE_Directswapped — 4 call sites in r186: directional, point, spot, sun),lights_fragment_end(fill + rim),color_fragment(flecks, bark),normal_fragment_maps(puff).
Toon ramp
float toonRamp(float x){ float n = max(uBands,1.); float s = pow(x,.85)*n; float f = floor(s);
float t = smoothstep(.5-uSoft, .5+uSoft, fract(s)); return mix(x, clamp((f+t)/n,0.,1.), uToonMix); }
tl.color *= clamp(toonRamp(ndl)/max(ndl,1e-3), 0., 4.); // RE_Direct re-applies the cosineSpecular, clearcoat, sheen and PCF shadows stay stock. Values: bands 3, soft 0.10, mix 0.85.
Starting values
| Uniform | Value | Note |
| puff blend | 0.72 | 0.6–0.8; >0.9 = plastic balls |
| translucency / SSS colour | 0.55 / 0xd6ff6a | natural GLB foliage: 0.24 / 0xc4dc8c |
| rim / colour | 0.30 / 0xbfff8a | pow(1-N·V,3), brighter toward the sun |
| fleck strength / scale | 0.55 / 3.2 per m | object space |
| shadow fill / colour | 0.14 / 0xffb27a | >~0.2 turns sunlit grass lime |
| hemisphere | sky 0xd9e6ff, ground 0x7d6a36, 0.55 | keep ambient strong and warm |
| bark warm / mix / grain | 0x8a5a36 / .35 / .45 | root AO .45 (0–1.8 m), canopy AO .30 (3.2–6.5 m) |
| wind sway / flutter | 1.0 / 0.035 m | flutter at outer leaf edges |
Wind weights
Pass GLSL expressions: e.g. trees wind: 'clamp((position.y-2.)*.06,0.,.6)*.22', flutter: '.55'; grass wind: 'position.y*position.y*.16'. The depth material:
leaves.customDepthMaterial = patch(new THREE.MeshDepthMaterial({ depthPacking: THREE.RGBADepthPacking,
side: THREE.DoubleSide, map: mat.map, alphaTest: mat.alphaTest }), { wind: w, flutter: fl })Puff normals for baked GLB foliage
k-means per triangle (so a card never straddles two clusters), seeded, 10 iterations, ~36 clusters → per-vertex clusterCenter in object space. In the vertex shader sN = normalize(position - clusterCenter), rotated by mat3(instanceMatrix) and normalMatrix; in the fragment shader blend after normal_fragment_maps so the double-sided face flip of the card survives.
Pitfalls
- Un-synced shadows: wind in the main material but not in
customDepthMaterialleaves shadows frozen. - Declare every attribute the depth material's wind expression uses (e.g.
clusterCenter) there too; weight displacement fromposition, never by reading a varying back in the vertex shader. - Don't gamma-lift
ndlin aramp(ndl)/ndlramp below ~0.85 — grazing light gets boosted ~3× and the scene washes out. - Inject the toon helper after
lights_physical_pars_fragment, never into a shared noise block that depth materials and custom ShaderMaterials also include (they have noPhysicalMaterialtype → compile error). onBeforeCompilesees unexpanded#includes — that's whylights_fragment_beginmust be inlined fromTHREE.ShaderChunkbefore thereplaceAll.- In
onBeforeCompile, inject helper GLSL before any code that calls it. - Flecks and bark grain read object-space
position(vLocal). Compress GLBs with Draco, not meshopt: meshopt's quantisation movespositioninto a normalised range under a node transform. - Opt out materials that need their clearcoat path intact (wet fish) and keep grass on plain Lambert-ish shading: uniform blade normals band into one flat tone under a toon ramp.
- Over-dark foliage shadows ruin the look; keep ambient/hemisphere strong and warm and use the fill term.
- Leaf cards need
alphaTest(~0.5), nottransparent: true(sorting glitches). - The fleck tint (×(1.55,1.45,.65)) turns pink blossoms orange — turn
flecksoff for flowers/sakura. - A linear sun colour normalised to its max channel reads orange; blend halfway to white for tints.
- Known limit: puff normals fix shading, not silhouettes — close up, cards still read as angular slivers. A low-opacity ink outline was tried and judged not worth it.
Verify
- Close-up of a canopy: clumps read as soft volumes, 2–3 visible light steps, shadow edges still soft.
- Look toward the sun through leaves: warm yellow-green glow, not white.
- Shadows under trees: warm brown, never flat grey or black; they move with the leaves.
- Drag each GUI slider: every patched material responds (one shared uniform object).
Related skills
threejs-procedural-vegetation, threejs-ghibli-sky-clouds, threejs-postprocessing-anime-grade, threejs-ghibli-night-mode, threejs-stylized-rock-material.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

