Generated banner for 3d Cloth Material
Generated logo for 3d Cloth Material

3d Cloth Material

Meng ToCommunityCreated by Meng To

  • Skill
  • Guidelines
  • Software development
  • MIT
  • No issues found

From the author

Build convincing woven cloth in Three.js, with a thread-level weave normal map, sheen and anisotropic highlights, folds that never stretch the texture, hems with thickness, stitches, seams, frayed edges, fold occlusion, dye and wear variation, and light passing through thin fabric. Use for linen, silk, wool, canvas, curtains, banners, cloaks, tablecloths, tapestries or any 3D drape that currently looks like a plastic sheet, a stretched texture, or a flat coloured plane.
— the description by Meng To

AutoGineer summary

Written by AutoGineer from the skill’s own files, not by the author

This skill provides a technical framework for creating realistic woven fabric materials within Three.js. It focuses on achieving visual fidelity for various textiles like linen, silk, and wool by addressing weave interlacement, fold geometry, sheen, and light transmission. The approach uses custom shader logic via MeshPhysicalMaterial and onBeforeCompile to simulate thread-level details, hem thickness, and wear patterns without relying on full cloth simulation.

What it does

  • Implements thread-level weave normal maps and interlacement patterns.
  • Calculates fold geometry based on tangent angles to prevent texture stretching.
  • Adds physical fabric features like hem thickness, stitches, seams, and frayed edges.
  • Configures sheen, anisotropy, and light transmission for specific fabric types.
  • Applies wear and dye variation to avoid uniform, artificial appearances.
  • Provides constants for material properties across linen, silk, and wool.

When to use it

  • When you need to render convincing curtains, banners, or draped fabric in a Three.js scene.
  • When existing textures look like flat planes or stretched plastic sheets.
  • When you require specific fabric behaviors like backlit transmission or anisotropic highlights.
  • When you have pre-simulated or static cloth geometry that needs a high-fidelity material shader.

Advantages

  • Avoids texture swimming and stretching by using material-space coordinates.
  • Provides a structured approach to rendering complex fabric details like stitches and hems.
  • Includes specific configurations for different fabric types to ensure visual accuracy.
  • Uses shader-based techniques to handle fold occlusion and light interaction.

Usage examples

“How do I set up a linen material in Three.js using the cloth material rules?”
The agent provides the specific weave, pitch, roughness, and sheen constants for linen, along with the shader implementation steps for the fold and normal map logic.
“My cloth texture looks like it is stretching when it folds. How do I fix this?”
The agent explains the fold-from-angle technique, advising to use the tangent angle for fold signals rather than height fields to maintain consistent arc length.

Install

  1. Download the skill as a ZIP:

    https://autogineer.com/agent-skills/mengto/3d-cloth-material/download
  2. Unzip it into the cross-client skills folder of your project:

    mkdir -p .agents/skills && unzip 3d-cloth-material.zip -d .agents/skills

Documentation by Meng To

3D Cloth Material

Mechanism: hang the cloth as rows whose tangent angle is the fold signal, so arc length equals the rest coordinate s and the weave never stretches. Then let a thread-level weave, sheen, hem thickness and light through the gaps do the reading of "fabric".

Nearest neighbours: 3d-high-resolution-textures chooses texel density, mipmaps and delivery for any material; use it for the budget and stay here for what makes cloth different (weave interlacement, folds, sheen, hems). 3d-wood-material, 3d-paper-material and 3d-metal-material cover their own surfaces; this skill owns woven and sewn fabric only. It is not a cloth simulation: for a character's flowing cape or a flag that collides, simulate (Verlet or Blender cloth) and bake, then keep the material rules below.

Extracted from KIBORI 木彫, a dark WebGL workshop where a roll of indigo canvas (the dōgu-maki) lies under a warm key light and had to survive a macro close-up. Ported from there: the weave bake, the stitch shader, half-circle hem turn-under, wear on thread tops, the sheen constants. Newly built for this skill (Kibori has one indigo canvas, not three fabrics): the tangent-angle fold curve, satin and twill interlacements, silk/wool/linen tables, tabs on the rod, raw-edge fray, fold AO, backlit transmission, wind. demo.html is the reference.

Demo: Three.js r169 · WebGL · GLSL (MeshPhysicalMaterial + onBeforeCompile), vanilla JavaScript, no post chain.

The rules, each with the failure it prevents

  1. Integrate folds from an angle, not a height. α(s) = a·(sinθ + 0.16 sin(2θ+0.8)) + …, then x += ds·cos α, z += ds·sin α. Failure: a height field z = A·sin(kx) gives arc length 1 + slope², so the weave swims and stretches 30–80% on every fold. With the angle form uv = (s, v) in metres is exact. Keep |α| < 1.45 rad; past that it clamps into flat plateaus and folds become tubes with black seams.

  2. Uv is material metres, never re-fitted per frame. Do not recompute uv from the moving surface. Failure: weave shimmers and crawls in wind. Set texture.repeat = 1/(threads × pitch) so one texel tile is NT threads; linen 1.6 mm, silk 0.7 mm, wool 2.6 mm pitch.

  3. Bake interlacement, not noise. Each thread has its own width (0.80–0.97), tone and a slub (Gaussian thickening up to 0.34). Warp height blends over/under across cell borders by 0.5·smoothstep(0.05, 0.5, |t|). Plain = (A+B)&1, twill 2/1 = (A+B)%3 < 2, 5-harness satin = (2A+B)%5 != 0 warp-over. NT must be a multiple of the repeat (32, 24, 40) or the tile shows a seam. Failure: a tiled noise normal map reads as stucco or leather.

  4. Spun yarn gets a twist. Add 0.22·twist·sin(2π(5·along + 1.3·across)) to each thread height (twist 0.10–0.14 for linen and wool, 0 for silk). Failure: linen looks like wire mesh.

  5. Two dyes, per-thread tone. Colour mix(warpDye, weftDye, weftOnTop·shot); silk uses shot 1.0 (madder red warp, gold weft), the rest 0. Tone mix(0.86, 1.14, threadTone), cavity mix(0.5, 1, smoothstep(0.05, 0.85, height)), blotch + warp-direction streaks 1 + var·((blot−0.5)·0.62 + (streak−0.5)·0.22). Failure: one flat albedo on a woven map looks printed.

  6. Sheen is the fabric, and it must be small. sheen 0.5–1.0, sheenRoughness 0.28 (silk) – 0.82 (wool), and sheenColor = dye lightened × 0.62. Failure: near-white sheenColor blows out to a milky rim under a warm key. Never set sheen to exactly 0 at runtime (0.0001); crossing zero recompiles the program and hitches 200+ ms.

  7. Silk gets anisotropy, wool gets fuzz. Silk anisotropy 0.85, roughness 0.36; linen 0.90 rough with sheen 0.55; wool 0.96 rough with sheen 1.0. Keep anisotropy above 0 at creation (0.0001) so the define never flips.

  8. Fold occlusion is not optional. Cast and receive the key's shadow map (normalBias 0.012, bias −0.0004, DoubleSide shadows) and add a vertex AO from the fold depth 0.62 + 0.38·smoothstep(−0.075, 0.035, zFold) on indirect light. Failure: without both, valleys light up like the crests and the folds look painted.

  9. Edges have thickness. Turn every free edge under on a half circle, P = edge + out·r·sinφ − N·r(1−cosφ), φ ∈ [0, 0.94π], r = 1.1 mm silk, 2.2 mm linen, 4.6 mm wool. Return the bottom hem up the back at 2r + 0.2 mm with flipped normals. Failure: a zero-thickness cut edge is the loudest tell for CG cloth in a close-up.

  10. Stitch in the shader, in cloth metres. Thread arches between holes (4·x(1−x) over 74% of the pitch), the needle groove and pucker feed the normal by finite difference, faded by fwidth. Hem 3 cm up, sides 2.2 cm in, seam ±7 mm with a proud ridge that puckers every 4 pitches. Failure: geometry stitches z-fight and alias; texture-painted ones do not follow the folds.

  11. Raw edge: draw out the weft. Beyond the cut, discard fragments except the warp threads (|fract(u/pitch)−0.5| < 0.36), each with a random length F·(0.3+0.7·hash). Failure: an alpha fringe texture has no thread structure.

  12. Thin cloth passes light. emissive += trans · lightColour · dye·(1.7,1.2,0.85) · pow(max(0, −N·L), 1.15) · gap · thin with gap = mix(1, 0.42, height) so threads block and gaps pass. Silk 1.05, linen 0.6, wool 0.06. Failure: without it a lit window behind a curtain does nothing.

  13. Wear where cloth is touched. wear = clamp(aWear·(0.25+height) + (fbm−0.5)·0.3, 0, 1) → mix dye toward a pale colour by wear·threadTop. Hems +0.4, crests +0.3. Failure: uniform dye reads brand new.

Constants

linensilkwool
weave / NT / pitchplain / 32 / 1.6 mm5-harness satin / 40 / 0.7 mmtwill / 24 / 2.6 mm
normal strength S · normalScale2.6 · 1.151.5 · 0.62.9 · 1.45
roughness · sheen · sheenR0.90 · 0.55 · 0.550.36 · 0.5 · 0.280.96 · 1.0 · 0.82
fold λ · amax · wind gain0.34 m · 0.98 · 1.00.40 · 1.02 · 1.90.32 · 0.86 · 0.55
edgeraw fray 3 cmhem 3.5 cmhem 5 cm

Cloth 2.0 × 1.95 m, grid 160 × 120 (≈ 21k verts, 45k tris). Key SpotLight 0xffd0a0 × 3.0, angle 0.44, decay 0; cool fill 1.0; window back light 0.2–1.8; environment intensity 0.42; ACES, exposure 1.0.

Gotchas, symptom first

  • Weave crawls or shimmers when it moves → uv was rebuilt from arc length or scrolled; keep it as the rest metres.

  • Horizontal moire stripes at wide view → bump/crease term uses dFdx of a high-frequency noise; keep crease octaves below 17 cycles/m and scale by 0.016. Mipmaps + 16× anisotropy handle the weave itself.

  • Folds are flat panels with black slits → |α| clamped. Lower amax so a·env·1.28 < 1.45, do not add more darkness.

  • Everything glows orange when backlit → transmission colour multiplied by a warm light and a warm dye. Tint by (1.7,1.2,0.85), not (2.1,1.35,0.72).

  • envMapIntensity does nothing → in r163+ it only applies with material.envMap; with scene.environment use scene.environmentIntensity.

  • onBeforeCompile shader is shared between two meshes with different uniforms → set customProgramCacheKey, and put uniforms on the material, not the mesh.

  • Winding wrong on a hem strip (lit inside-out) → pick each strip's index order from the sign of its first triangle normal against the attribute normal, once, after the first update.

  • Turn-under leaves a dark gap → the return strip must sit at 2r + 0.2 mm, not r.

  • Shadow acne on a double-sided sheet → normalBias, not a bigger bias; a large bias detaches the fold shadows.

Lifecycle

prefers-reduced-motion: render one designed still at t = 7.3 (gust mid-swell), stop the loop, keep every control live and re-render on change. Pause on document.hidden; reset last on resume. Clamp dt to 1/30 s, cap DPR at 2 and step it down by 0.25 when a 60-frame average exceeds 26 ms. Size from a ResizeObserver. Expose no per-frame allocation in the cloth loop: reuse typed arrays and update position/normal only.

Cost (measured, headless Chrome for Testing, Apple GPU, 1440×900 at DPR 2)

  • Cloth CPU (folds + normals + hems + tabs + fringe): 3.7–4.9 ms at 160×120. Halving the row count (190 → 120) bought −40%, and no fold was lost, because folds vary slowly down the drop.

  • Whole frame: 10–11 ms wide, 15 ms macro. The macro's extra 4 ms is the fragment shader (weave + stitch + fbm) over the whole screen, not geometry.

  • Boot: 0.8 s to first frame including three 512² weave bakes. Fabric switch 25 ms. Layer toggles 14 ms.

  • Not the bottleneck: triangle count, the 2048 shadow map, tabs, fringe (520 strands).

Score against the rubric (0 = flat coloured plane, 5 = convincing at arm's length, 10 = photographic macro)

Weave structure 7 · Sheen and dye 6.5 · Fold shape and drape 6 (a hanging curtain, not free cloth with self-contact) · Edges, stitches, seams 7.5 · Light transmission 6 · Wear 5.5 · Motion 5.5 (wind is analytic, no collision) · Performance 8. Overall 6.5. What would lift it: real self-collision folds (simulate and bake), fibre halo geometry on wool, a second normal scale for creases.

Files

PROMPT.md

3D Cloth Material — Demo Prompts

Minimal prompt

Use $3d-cloth-material to make this cloth read as woven linen, not a plastic sheet: a thread-level weave, sheen that stays small, folds that do not stretch the texture, and a hem with visible thickness.

  • Use $3d-cloth-material for a silk banner in a dark room with a lit paper window behind it, so the thin cloth glows where it turns away.

  • Use $3d-cloth-material to add a heavy wool blanket with a twill weave, a stitched seam and a raw fringe.

  • Use $3d-cloth-material to fix a stretched, blurry fabric texture on a draped model: rebuild uv in rest metres and re-bake the weave.

Recreate the demo

Use $3d-cloth-material to recreate Woven Cloth 布織 as one standalone demo.html. Treat the file in this folder as the visual, motion, responsive, accessibility and performance reference.

Scene
  • A dark warm room (#0a0806): plaster wall 0.78 m behind the cloth, a dim floor, a dark wooden rod at y 1.16 with ball finials and two round brackets to the wall, and a paper window with kumiko bars at the right of the wall glowing warm.

  • A 2.0 × 1.95 m cloth hung from nine fabric tabs over the rod, with a slow wind. Key: a warm SpotLight from the front left with a 2048 shadow map, so the folds throw soft shadows on the wall. A cool low fill, and a warm directional "window" light from behind that both lights the folds facing it and shines through thin cloth.

  • Three.js r169 from unpkg via an import map; ACESFilmicToneMapping, PCFSoftShadowMap, sRGB output, anisotropy at the device maximum up to 16.

  • Type: Instrument Serif for the title, Inter for copy and controls, Shippori Mincho for 麻 絹 毛 and 布織, nothing under 11 px. Palette: ink #f2ece2, hairlines rgba(242,236,226,.16), one vermilion accent #c4483a.

Cloth
  • Rows of 160 samples and 120 rows. Per row, a tangent angle α(s) = av·env·(sinθ + 0.16 sin(2θ+0.8)) + 0.26·av·sin(2.7θ+…) + 0.12·av·sin(5.4θ+…), θ = k s + wp·sin(0.43ks+1.7+0.8vn) + 0.6·sin(0.19ks+4vn) + 1.4vn, integrated to x and z; subtract the row's mean z so rows do not walk. Amplitude av = amax·fullness·(0.55+0.45·smoothstep(0,0.3,vn)).

  • Wind: billow w·(0.045+0.10·gust)·sin(πs/W)·vn^1.4, a travelling ripple 0.012·sin(6.5s − 2.4t + 2.1vn)·vn², a pendulum swing and a phase wobble inside θ. Gust 0.55 + 0.45·sin(0.37t + 0.9 sin 0.11t).

  • Free edges turn under on a half circle; the bottom hem returns up the back; linen ends in a raw fray (warp threads kept, weft discarded) plus 520 loose strands.

  • Material: MeshPhysicalMaterial with sheen, sheen roughness, sheen colour, anisotropy (silk) and a baked 512² normal map per fabric. An onBeforeCompile adds: two-tone warp/weft dye, per-thread tone, cavity, dye wear on thread tops, stitches and a seam drawn in cloth metres, an anisotropic wrinkle bump, fold AO on indirect light and backlit transmission.

Controls

Fabric radios (麻 Linen, 絹 Silk, 毛 Wool), sliders for wind, fullness and window light, radios that strip a layer (All, No weave, No sheen, Flat sheet) and a Macro close-up toggle that flies the camera 0.36 m off a fold beside the seam and fades the title copy. Announce every change in an aria-live region. Fabric changes tween fold and material numbers over about 0.6 s and swap the weave at once.

Acceptance
  • The first screen shows folds with soft self-shadow, a visible weave at macro, sheen along the crests and a stitched seam.

  • Flat sheet mode must clearly look worse: no weave, no sheen, no wrinkles, almost no folds.

  • Under reduced motion one still frame is drawn and the controls still re-render it. Hidden tab pauses. DPR cap 2, dt clamp 1/30.

  • Verify at 1440×900 and 390×844 with a clean console, and macro on all three fabrics.

Remix prompt

Use $3d-cloth-material to make a noren shop curtain in a rainy alley at night: cotton twill, indigo with a white stencil-dyed crest, a slit up the middle so the two halves swing separately, cold rim light from a lantern behind, and a cyan-black palette instead of amber. Keep the mechanism: fold curves integrated from a tangent angle so uv stays in rest metres, a baked interlacement normal map, small sheen, half-circle hems and stitches drawn in the shader, and light through the gaps between threads. Keep the budgets: 160×120 rows, DPR cap 2, dt clamp 1/30, reduced-motion still, hidden pause.

Requirements and compatibility

Works with: Claude Code, Claude apps, OpenAI Codex, GitHub Copilot, Cursor, Gemini CLI, Kiro, OpenCode, Goose, Amp, Roo Code, JetBrains Junie, Factory Droid, Devin (ex-Windsurf), Mistral Vibe, OpenHands, Letta

“Works with” means the tool reads the open Agent Skills format; a skill written for one tool may use features others lack.

Security

No issues found by our static scan· No issues found

A static scan is not a guarantee. Skills are third-party content: review a skill before you let an agent use it.

Attribution and licence

Created by
Meng To
Publisher
Meng To (Community)
Source
MengTo/Skills · agent-skills/3d/3d-cloth-material · commit 5ea1661
Licence
MIT License (redistribution allowed)
  • LICENSE (added by AutoGineer from LICENSE)
  • ATTRIBUTION.md (written by AutoGineer)
Synced

AutoGineer is not affiliated with or endorsed by Meng To or Meng To.

Download ZIP

The ZIP holds the skill’s files, its licence files and an ATTRIBUTION.md. Download 3d-cloth-material.zip