Codrops 원본
WebGPU Gommage Effect: Dissolving MSDF Text into Dust and Petals with Three.js & TSL
텍스트 · MIT
갤러리 안에서는 화면을 벗어나거나 움직임을 멈추면 예제도 닫힙니다. 다시 재생할 때는 처음부터 시작해요.
SOURCE FILES
원본 코드 읽기
수집한 원본 소스와 실행 안내를 함께 제공합니다.
css/base.css
*,
*::after,
*::before {
box-sizing: border-box;
}
:root {
font-size: 12px;
--color-text: #d5cbb2;
--color-bg: #000;
--color-link: #a9161b;
--color-link-hover: #d5cbb2;
--page-padding: 1.5rem;
}
body {
margin: 0;
color: var(--color-text);
background-color: var(--color-bg);
font-family: 'Helvetica Neue', 'Segoe UI', sans-serif;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
}
canvas {
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
}
@media (scripting: enabled) {
.loading {
&::before,
&::after {
content: '';
position: fixed;
z-index: 10000;
}
&::before {
top: 0;
left: 0;
width: 100%;
height: 100%;
background: var(--color-bg);
}
&::after {
top: 50%;
left: 50%;
width: 100px;
height: 1px;
margin: 0 0 0 -50px;
background: var(--color-link);
animation: loaderAnim 1.5s ease-in-out infinite alternate forwards;
}
}
}
@keyframes loaderAnim {
0% {
transform: scaleX(0);
transform-origin: 0% 50%;
}
50% {
transform: scaleX(1);
transform-origin: 0% 50%;
}
50.1% {
transform: scaleX(1);
transform-origin: 100% 50%;
}
100% {
transform: scaleX(0);
transform-origin: 100% 50%;
}
}
a {
text-decoration: none;
color: var(--color-link);
outline: none;
cursor: pointer;
&:hover {
text-decoration: underline;
color: var(--color-link-hover);
}
&:focus {
outline: none;
background: lightgrey;
&:not(:focus-visible) {
background: transparent;
}
&:focus-visible {
outline: 2px solid red;
background: transparent;
}
}
}
.frame {
padding: 3rem var(--page-padding) 0;
display: grid;
z-index: 1000;
position: relative;
grid-row-gap: 1rem;
grid-column-gap: 2rem;
pointer-events: none;
justify-items: start;
grid-template-columns: auto auto auto 1fr;
grid-template-areas:
'title title title title'
'back archive github ...'
'demos demos demos demos'
'tags tags tags tags'
'sponsor sponsor sponsor sponsor';
#cdawrap {
justify-self: start;
grid-area: sponsor;
}
a,
button {
pointer-events: auto;
}
.frame__title {
grid-area: title;
font-size: inherit;
margin: 0;
}
.frame__back {
grid-area: back;
justify-self: start;
}
.frame__archive {
grid-area: archive;
justify-self: start;
}
.frame__github {
grid-area: github;
}
.frame__tags {
grid-area: tags;
display: flex;
flex-wrap: wrap;
gap: 1rem;
}
.frame__demos {
grid-area: demos;
display: flex;
flex-wrap: wrap;
gap: 1rem;
}
@media screen and (min-width: 53em) {
padding: var(--page-padding);
height: 100%;
position: fixed;
top: 0;
left: 0;
width: 100%;
grid-template-columns: auto auto auto auto 1fr;
grid-template-rows: auto auto;
align-content: space-between;
grid-template-areas:
'title back github archive demos'
'tags tags tags sponsor sponsor';
.frame__tags {
align-self: end;
}
.frame__demos,
#cdawrap {
justify-self: end;
text-align: right;
max-width: 300px;
}
}
}
.content {
padding: var(--page-padding);
display: flex;
flex-direction: column;
width: 100vw;
position: relative;
@media screen and (min-width: 53em) {
min-height: 100vh;
justify-content: center;
align-items: center;
}
}
css/controlUI.css
@font-face {
font-family: 'Cinzel';
src: url('/fonts/Cinzel/Cinzel-Regular.ttf') format('truetype');
font-weight: normal;
font-style: normal;
}
#control-ui-container {
position: fixed;
bottom: 200px;
z-index: 9999;
width: 100%;
left: 50%;
display: flex;
align-items: center;
justify-content: center;
gap: 24px;
transform: translateX(-50%);
--e33-color: #d5cbb2;
}
.E33-button {
font-family: 'Cinzel', serif;
padding: 12px 30px;
cursor: pointer;
background-color: rgba(0, 0, 0, 0.7);
color: var(--e33-color);
border: none;
position: relative;
clip-path: polygon(0% 50%, 15px 0%, calc(100% - 15px) 0%, 100% 50%, calc(100% - 15px) 100%, 15px 100%);
transition: transform 0.15s ease-out 0.05s;
font-size: 2rem;
transition: opacity 0.15s ease-out 0.05s;
&.disabled {
opacity: 0.4;
cursor: default;
}
}
.E33-button::before {
content: '';
position: absolute;
inset: 0;
background: var(--e33-color);
--borderSize: 1px;
clip-path: polygon(
0% 50%,
15px 0%,
calc(100% - 15px) 0%,
100% 50%,
calc(100% - 15px) 100%,
15px 100%,
0% 50%,
var(--borderSize) 50%,
calc(15px + 0.5px) calc(100% - var(--borderSize)),
calc(100% - 15px - 0.5px) calc(100% - var(--borderSize)),
calc(100% - var(--borderSize)) 50%,
calc(100% - 15px - 0.5px) var(--borderSize),
calc(15px + 0.5px) var(--borderSize),
var(--borderSize) 50%
);
z-index: -1;
}
함께 쓰는 파일 11개 보기
index.html
<!DOCTYPE html>
<html lang="en" class="no-js">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Clair Obscur: Expedition 33 WebGPU Gommage Effect | Codrops</title>
<link rel="icon" type="image/svg+xml" href="https://tympanus.net/favicon/favicon.svg" />
<link rel="shortcut icon" href="https://tympanus.net/favicon/favicon.ico" />
<link rel="stylesheet" type="text/css" href="./css/base.css" />
<link rel="stylesheet" type="text/css" href="./css/controlUI.css" />
<script>
document.documentElement.className = 'js';
</script>
<script src="//tympanus.net/codrops/adpacks/analytics.js"></script>
</head>
<body class="demo-1">
<main>
<header class="frame">
<h1 class="frame__title">Clair Obscur: Expedition 33 WebGPU Gommage Effect</h1>
<a class="frame__back" href="https://tympanus.net/codrops/?p=107900">Tutorial</a>
<a class="frame__archive" href="https://tympanus.net/codrops/hub/">All demos</a>
<a class="frame__github" href="https://github.com/WallabyMonochrome/WebGPU-clair-obscur-gommage-codrops">GitHub</a>
<nav class="frame__tags">
<a href="https://tympanus.net/codrops/demos/?tag=three-js">#three.js</a>
<a href="https://tympanus.net/codrops/demos/?tag=tsl">#TSL</a>
<a href="https://tympanus.net/codrops/demos/?tag=webgpu">#webgpu</a>
</nav>
</header>
<div id="canvas-container"></div>
<div id="control-ui-container">
<button class="E33-button" id="gommage-button">Start</button>
</div>
</main>
<script src="https://tympanus.net/codrops/adpacks/cda_sponsor.js"></script>
<script type="module" src="./src/experience.js"></script>
</body>
</html>src/debug.js
//debug.js
import { Pane } from 'tweakpane';
export const DEBUG_FOLDERS = {
MSDF_TEXT: 'MSDFText',
};
class Debug {
static instance = null;
static ENABLED = false;
#pane = null;
#baseFolder = null;
#folders = new Map();
static getInstance() {
if (Debug.instance === null) {
Debug.instance = new Debug();
}
return Debug.instance;
}
constructor() {
if (Debug.ENABLED) {
this.#pane = new Pane();
this.#baseFolder = this.#pane.addFolder({ title: 'Debug' });
this.#baseFolder.expanded = false;
}
}
createNoOpProxy() {
const handler = {
get:
() =>
(..._args) =>
this.createNoOpProxy(),
};
return new Proxy({}, handler);
}
getFolder(name) {
if (!Debug.ENABLED) {
return this.createNoOpProxy();
}
const existing = this.#folders.get(name);
if (existing) {
return existing;
}
const folder = this.#baseFolder.addFolder({ title: name });
this.#folders.set(name, folder);
return folder;
}
}
export default Debug;
src/dustParticles.js
//dustParticles.js
import * as THREE from 'three/webgpu';
import {
attribute,
uniform,
positionLocal,
texture,
vec4,
uv,
mrt,
time,
vec2,
vec3,
clamp,
sin,
smoothstep,
float,
} from 'three/tsl';
export default class DustParticles {
constructor() {}
#spawnPos;
#birthLifeSeedScale;
#currentDustIndex = 0;
#dustMesh;
#MAX_DUST = 100;
async initialize(perlinTexture, dustParticleTexture) {
const dustGeometry = new THREE.PlaneGeometry(0.02, 0.02);
this.#spawnPos = new Float32Array(this.#MAX_DUST * 3);
// Combined 4 attributes into one to not go above the 9 attribute limit for webgpu
this.#birthLifeSeedScale = new Float32Array(this.#MAX_DUST * 4);
this.#currentDustIndex = 0;
dustGeometry.setAttribute('aSpawnPos', new THREE.InstancedBufferAttribute(this.#spawnPos, 3));
dustGeometry.setAttribute('aBirthLifeSeedScale', new THREE.InstancedBufferAttribute(this.#birthLifeSeedScale, 4));
const material = this.createDustMaterial(perlinTexture, dustParticleTexture);
this.#dustMesh = new THREE.InstancedMesh(dustGeometry, material, this.#MAX_DUST);
return this.#dustMesh;
}
debugSpawnDust() {
for (let i = 0; i < 10; i++) {
this.spawnDust(new THREE.Vector3((Math.random() * 2 - 1) * 0.5, (Math.random() * 2 - 1) * 0.5, 0));
}
}
spawnDust(spawnPos) {
if (this.#currentDustIndex === this.#MAX_DUST) this.#currentDustIndex = 0;
const id = this.#currentDustIndex;
this.#currentDustIndex = this.#currentDustIndex + 1;
this.#spawnPos[id * 3 + 0] = spawnPos.x;
this.#spawnPos[id * 3 + 1] = spawnPos.y;
this.#spawnPos[id * 3 + 2] = spawnPos.z;
this.#birthLifeSeedScale[id * 4 + 0] = performance.now() * 0.001; // Birth time
this.#birthLifeSeedScale[id * 4 + 1] = 4; // Life time
this.#birthLifeSeedScale[id * 4 + 2] = Math.random(); // Random seed
this.#birthLifeSeedScale[id * 4 + 3] = Math.random() * 0.5 + 0.5; // Scane
this.#dustMesh.geometry.attributes.aSpawnPos.needsUpdate = true;
this.#dustMesh.geometry.attributes.aBirthLifeSeedScale.needsUpdate = true;
}
createDustMaterial(perlinTexture, dustTexture) {
const material = new THREE.MeshBasicMaterial({
transparent: true,
depthWrite: false,
depthTest: false,
});
const aSpawnPos = attribute('aSpawnPos', 'vec3');
const aBirthLifeSeedScale = attribute('aBirthLifeSeedScale', 'vec4');
const aBirth = aBirthLifeSeedScale.x;
const aLife = aBirthLifeSeedScale.y;
const aSeed = aBirthLifeSeedScale.z;
const aScale = aBirthLifeSeedScale.w;
const uDustColor = uniform(new THREE.Color('#8A8A8A'));
const uWindDirection = uniform(new THREE.Vector3(-1, 0, 0).normalize());
const uWindStrength = uniform(0.3);
const uRiseSpeed = uniform(0.1); // constant lift
const uNoiseScale = uniform(30.0); // start small (frequency)
const uNoiseSpeed = uniform(0.015); // scroll speed
const uWobbleAmp = uniform(0.6); // vertical wobble amplitude
// Age of the dust in seconds
const dustAge = time.sub(aBirth);
const lifeInterpolation = clamp(dustAge.div(aLife), 0, 1);
// Use noise
const randomSeed = vec2(aSeed.mul(123.4), aSeed.mul(567.8));
const noiseUv = aSpawnPos.xz
.mul(uNoiseScale)
.add(randomSeed)
.add(uWindDirection.xz.mul(dustAge.mul(uNoiseSpeed)));
// Return a value between 0 and 1.
const noiseSample = texture(perlinTexture, noiseUv).x;
const noiseSammpleBis = texture(perlinTexture, noiseUv.add(vec2(13.37, 7.77))).x;
// Convert to turbulence values between -1 and 1.
const turbulenceX = noiseSample.sub(0.5).mul(2);
const turbulenceY = noiseSammpleBis.sub(0.5).mul(2);
const swirl = vec3(clamp(turbulenceX.mul(lifeInterpolation), 0, 1.0), turbulenceY.mul(lifeInterpolation), 0.0).mul(
uWobbleAmp
);
const windImpulse = uWindDirection.mul(uWindStrength).mul(dustAge);
const riseFactor = clamp(noiseSample, 0.3, 1.0);
const rise = vec3(0.0, dustAge.mul(uRiseSpeed).mul(riseFactor), 0.0);
const driftMovement = windImpulse.add(rise).add(swirl);
// 0 at creation, 1 at death
const scaleFactor = smoothstep(float(0), float(0.05), lifeInterpolation);
const fadingOut = float(1.0).sub(smoothstep(float(0.8), float(1.0), lifeInterpolation));
const dustSample = texture(dustTexture, uv());
material.colorNode = vec4(uDustColor, dustSample.a);
material.positionNode = aSpawnPos.add(driftMovement).add(positionLocal.mul(aScale.mul(scaleFactor)));
material.opacityNode = fadingOut;
material.mrtNode = mrt({
bloomIntensity: float(0.5).mul(fadingOut),
});
return material;
}
}
src/experience.js
//experience.js
import * as THREE from 'three/webgpu';
import GommageOrchestrator from './gommageOrchestrator.js';
import { float, mrt, pass, output } from 'three/tsl';
import { bloom } from 'three/examples/jsm/tsl/display/BloomNode.js';
export class Experience {
#threejs = null;
#scene = null;
#camera = null;
#webgpuComposer = null;
constructor() {}
async initialize(container) {
await this.#setupProject(container);
window.addEventListener('resize', this.#onWindowResize_.bind(this), false);
await this.#setupPostprocessing();
this.#raf();
}
async #setupProject(container) {
this.#threejs = new THREE.WebGPURenderer({ antialias: true });
await this.#threejs.init();
this.#threejs.shadowMap.enabled = false;
this.#threejs.toneMapping = THREE.ACESFilmicToneMapping;
this.#threejs.setClearColor(0x111111, 1);
this.#threejs.setSize(window.innerWidth, window.innerHeight);
this.#threejs.setPixelRatio(Math.min(window.devicePixelRatio, 2));
container.appendChild(this.#threejs.domElement);
// Camera Setup !
const fov = 45;
const aspect = window.innerWidth / window.innerHeight;
const near = 0.1;
const far = 25;
this.#camera = new THREE.PerspectiveCamera(fov, aspect, near, far);
this.#camera.position.set(0, 0, 5);
// Call window resize to compute FOV
this.#onWindowResize_();
this.#scene = new THREE.Scene();
// Test MSDF Text
const gommageOrchestratorEntity = new GommageOrchestrator();
await gommageOrchestratorEntity.initialize(this.#scene);
}
async #setupPostprocessing() {
this.#webgpuComposer = new THREE.PostProcessing(this.#threejs);
const scenePass = pass(this.#scene, this.#camera);
scenePass.setMRT(
mrt({
output,
bloomIntensity: float(0),
})
);
let outNode = scenePass;
const outputPass = scenePass.getTextureNode();
const bloomIntensityPass = scenePass.getTextureNode('bloomIntensity');
const bloomPass = bloom(outputPass.mul(bloomIntensityPass), 0.8);
outNode = outNode.add(bloomPass);
this.#webgpuComposer.outputNode = outNode.renderOutput();
this.#webgpuComposer.needsUpdate = true;
}
#onWindowResize_() {
const HORIZONTAL_FOV_TARGET = THREE.MathUtils.degToRad(45);
this.#camera.aspect = window.innerWidth / window.innerHeight;
const verticalFov = 2 * Math.atan(Math.tan(HORIZONTAL_FOV_TARGET / 2) / this.#camera.aspect);
this.#camera.fov = THREE.MathUtils.radToDeg(verticalFov);
this.#camera.updateProjectionMatrix();
this.#threejs.setSize(window.innerWidth, window.innerHeight);
}
#render() {
//this.#threejs.render(this.#scene, this.#camera);
this.#webgpuComposer.render();
}
#raf() {
requestAnimationFrame((t) => {
this.#render();
this.#raf();
});
}
}
new Experience().initialize(document.querySelector('#canvas-container'));
src/gommageOrchestrator.js
//gommageOrchestrator.js
import * as THREE from 'three/webgpu';
import MSDFText from './msdfText.js';
import { uniform } from 'three/tsl';
import DustParticles from './dustParticles.js';
import PetalParticles from './petalParticles.js';
import Debug, { DEBUG_FOLDERS } from './debug.js';
import { GLTFLoader } from 'three/addons/loaders/GLTFLoader.js';
import gsap from 'gsap';
export default class GommageOrchestrator {
#uProgress = uniform(0.0);
#MSDFTextEntity = null;
#DustParticlesEntity = null;
#PetalParticlesEntity = null;
#dustInterval = 0.125;
#petalInterval = 0.05;
#gommageTween = null;
#spawnDustTween = null;
#spawnPetalTween = null;
constructor() {}
async initialize(scene) {
const { perlinTexture, dustParticleTexture, fontAtlasTexture } = await this.loadTextures();
const petalGeometry = await this.loadPetalGeometry();
const debugFolder = Debug.getInstance().getFolder(DEBUG_FOLDERS.MSDF_TEXT);
this.#MSDFTextEntity = new MSDFText();
const msdfText = await this.#MSDFTextEntity.initialize(
'Gommage',
new THREE.Vector3(0, 0, 0),
this.#uProgress,
perlinTexture,
fontAtlasTexture
);
scene.add(msdfText);
this.#DustParticlesEntity = new DustParticles();
const dustParticles = await this.#DustParticlesEntity.initialize(perlinTexture, dustParticleTexture);
scene.add(dustParticles);
this.#PetalParticlesEntity = new PetalParticles();
const petalParticles = await this.#PetalParticlesEntity.initialize(perlinTexture, petalGeometry);
scene.add(petalParticles);
const GommageButton = debugFolder.addButton({
title: 'GOMMAGE',
});
const ResetButton = debugFolder.addButton({
title: 'RESET',
});
const DustButton = debugFolder.addButton({
title: 'DUST',
});
const PetalButton = debugFolder.addButton({
title: 'PETAL',
});
GommageButton.on('click', () => {
this.triggerGommage();
});
ResetButton.on('click', () => {
this.resetGommage();
});
DustButton.on('click', () => {
const randomPosition = this.#MSDFTextEntity.getRandomPositionInMesh();
this.#DustParticlesEntity.spawnDust(randomPosition);
});
PetalButton.on('click', () => {
this.#PetalParticlesEntity.debugSpawnPetal();
});
// Use HTML buttons
this.gommageButton = document.getElementById('gommage-button');
this.gommageButton.addEventListener('click', () => {
console.log('gommage button clicked');
this.triggerGommage();
});
}
async loadPetalGeometry() {
const modelLoader = new GLTFLoader();
const petalScene = await modelLoader.loadAsync('./models/petal.glb');
const petalMesh = petalScene.scene.getObjectByName('PetalV2');
return petalMesh.geometry;
}
async loadTextures() {
const textureLoader = new THREE.TextureLoader();
const dustParticleTexture = await textureLoader.loadAsync('./textures/dustParticle.png');
dustParticleTexture.colorSpace = THREE.NoColorSpace;
dustParticleTexture.minFilter = THREE.LinearFilter;
dustParticleTexture.magFilter = THREE.LinearFilter;
dustParticleTexture.generateMipmaps = false;
const perlinTexture = await textureLoader.loadAsync('./textures/perlin.webp');
perlinTexture.colorSpace = THREE.NoColorSpace;
perlinTexture.minFilter = THREE.LinearFilter;
perlinTexture.magFilter = THREE.LinearFilter;
perlinTexture.wrapS = THREE.RepeatWrapping;
perlinTexture.wrapT = THREE.RepeatWrapping;
perlinTexture.generateMipmaps = false;
const fontAtlasTexture = await textureLoader.loadAsync('./fonts/Cinzel/Cinzel.png');
fontAtlasTexture.colorSpace = THREE.NoColorSpace;
fontAtlasTexture.minFilter = THREE.LinearFilter;
fontAtlasTexture.magFilter = THREE.LinearFilter;
fontAtlasTexture.wrapS = THREE.ClampToEdgeWrapping;
fontAtlasTexture.wrapT = THREE.ClampToEdgeWrapping;
fontAtlasTexture.generateMipmaps = false;
return { perlinTexture, dustParticleTexture, fontAtlasTexture };
}
triggerGommage() {
// Don't start if already running
if (this.#gommageTween || this.#spawnDustTween || this.#spawnPetalTween) return;
this.#uProgress.value = 0;
// Disable button while effect is running
this.gommageButton.disabled = true;
this.gommageButton.classList.add('disabled');
this.#spawnDustTween = gsap.to(
{},
{
duration: this.#dustInterval,
repeat: -1,
onRepeat: () => {
const p = this.#MSDFTextEntity.getRandomPositionInMesh();
this.#DustParticlesEntity.spawnDust(p);
},
}
);
this.#spawnPetalTween = gsap.to(
{},
{
duration: this.#petalInterval,
repeat: -1,
onRepeat: () => {
const p = this.#MSDFTextEntity.getRandomPositionInMesh();
this.#PetalParticlesEntity.spawnPetal(p);
},
}
);
this.#gommageTween = gsap.to(this.#uProgress, {
value: 1,
duration: 6,
ease: 'linear',
onComplete: () => {
this.#spawnDustTween?.kill();
this.#spawnPetalTween?.kill();
this.#spawnDustTween = null;
this.#gommageTween = null;
this.#spawnPetalTween = null;
gsap.delayedCall(1, () => {
this.gommageButton.disabled = false;
this.gommageButton.classList.remove('disabled');
});
},
});
}
resetGommage() {
this.#gommageTween?.kill();
this.#spawnDustTween?.kill();
this.#spawnPetalTween?.kill();
this.#gommageTween = null;
this.#spawnDustTween = null;
this.#spawnPetalTween = null;
this.#uProgress.value = 0;
}
}
src/msdfText.js
//msdfText.js
import * as THREE from 'three/webgpu';
import { MSDFTextGeometry, MSDFTextNodeMaterial } from 'three-msdf-text-utils';
import { texture, mix, uniform, clamp, pow, attribute, step, float, smoothstep, mrt } from 'three/tsl';
export default class MSDFText {
constructor() {}
#worldPositionBounds;
async initialize(
text = 'Gommage',
position = new THREE.Vector3(0, 0, 0),
uProgress,
perlinTexture,
fontAtlasTexture
) {
// Load font data
const response = await fetch('./fonts/Cinzel/Cinzel.json');
const fontData = await response.json();
// Create text geometry
const textGeometry = new MSDFTextGeometry({
text,
font: fontData,
width: 1000,
align: 'center',
});
const textMaterial = this.createTextMaterial(fontAtlasTexture, perlinTexture, uProgress);
// Adjust to remove visual artifacts
textMaterial.alphaTest = 0.1;
const mesh = new THREE.Mesh(textGeometry, textMaterial);
// With this we make the height of lineHeight 0.3 world units
const targetLineHeight = 0.5;
const lineHeightPx = fontData.common.lineHeight;
let textScale = targetLineHeight / lineHeightPx;
mesh.scale.set(textScale, textScale, textScale);
const meshOffset = -(textGeometry.layout.width / 2) * textScale;
mesh.position.set(position.x + meshOffset, position.y, position.z);
mesh.rotation.x = Math.PI;
// Compute the world position bounds of our text
textGeometry.computeBoundingBox();
mesh.updateWorldMatrix(true, false);
this.#worldPositionBounds = new THREE.Box3().setFromObject(mesh);
return mesh;
}
getRandomPositionInMesh() {
const min = this.#worldPositionBounds.min;
const max = this.#worldPositionBounds.max;
const x = Math.random() * (max.x - min.x) + min.x;
const y = Math.random() * (max.y - min.y) + min.y;
const z = Math.random() * 0.5;
return new THREE.Vector3(x, y, z);
}
createTextMaterial(fontAtlasTexture, perlinTexture, uProgress) {
const textMaterial = new MSDFTextNodeMaterial({
map: fontAtlasTexture,
transparent: true,
});
const glyphUv = attribute('glyphUv', 'vec2');
const center = attribute('center', 'vec2');
const uNoiseRemapMin = uniform(0.48);
const uNoiseRemapMax = uniform(0.9);
const uCenterScale = uniform(0.05);
const uGlyphScale = uniform(0.75);
const uDissolvedColor = uniform(new THREE.Color('#5E5E5E'));
const uDesatComplete = uniform(0.45);
const uBaseColor = uniform(new THREE.Color('#ECCFA3'));
const customUv = center.mul(uCenterScale).add(glyphUv.mul(uGlyphScale));
const perlinTextureNode = texture(perlinTexture, customUv).x;
const perlinRemap = clamp(perlinTextureNode.sub(uNoiseRemapMin).div(uNoiseRemapMax.sub(uNoiseRemapMin)), 0, 1);
const dissolve = step(uProgress, perlinRemap);
const desaturationProgress = smoothstep(float(0.0), uDesatComplete, uProgress);
const colorMix = mix(uBaseColor, uDissolvedColor, desaturationProgress);
textMaterial.colorNode = colorMix;
const msdfOpacity = textMaterial.opacityNode;
textMaterial.opacityNode = msdfOpacity.mul(dissolve);
textMaterial.mrtNode = mrt({
bloomIntensity: float(0.4).mul(dissolve),
});
return textMaterial;
}
}
src/petalParticles.js
//petalParticles.js
import * as THREE from 'three/webgpu';
import {
attribute,
uniform,
positionLocal,
texture,
vec4,
mrt,
uv,
mix,
normalLocal,
instanceIndex,
normalize,
abs,
dot,
time,
vec2,
vec3,
clamp,
smoothstep,
float,
pow,
cos,
sin,
mat3,
TWO_PI,
} from 'three/tsl';
export default class PetalParticles {
constructor() {}
#spawnPos;
#birthLifeSeedScale;
#currentPetalIndex = 0;
#petalMesh;
#MAX_PETAL = 400;
async initialize(perlinTexture, petalGeometry) {
const petalGeo = petalGeometry.clone();
const scale = 0.1;
petalGeo.scale(scale, scale, scale);
this.#spawnPos = new Float32Array(this.#MAX_PETAL * 3);
// Combined 4 attributes into one to not go above the 9 attribute limit for webgpu
this.#birthLifeSeedScale = new Float32Array(this.#MAX_PETAL * 4);
this.#currentPetalIndex = 0;
petalGeo.setAttribute('aSpawnPos', new THREE.InstancedBufferAttribute(this.#spawnPos, 3));
petalGeo.setAttribute('aBirthLifeSeedScale', new THREE.InstancedBufferAttribute(this.#birthLifeSeedScale, 4));
const material = this.createPetalMaterial(perlinTexture);
this.#petalMesh = new THREE.InstancedMesh(petalGeo, material, this.#MAX_PETAL);
return this.#petalMesh;
}
debugSpawnPetal() {
for (let i = 0; i < 10; i++) {
this.spawnPetal(new THREE.Vector3((Math.random() * 2 - 1) * 0.5, (Math.random() * 2 - 1) * 0.5, 0));
}
}
spawnPetal(spawnPos) {
if (this.#currentPetalIndex === this.#MAX_PETAL) this.#currentPetalIndex = 0;
const id = this.#currentPetalIndex;
this.#currentPetalIndex = this.#currentPetalIndex + 1;
this.#spawnPos[id * 3 + 0] = spawnPos.x;
this.#spawnPos[id * 3 + 1] = spawnPos.y;
this.#spawnPos[id * 3 + 2] = spawnPos.z;
this.#birthLifeSeedScale[id * 4 + 0] = performance.now() * 0.001; // Birth time
this.#birthLifeSeedScale[id * 4 + 1] = 6; // Life time
this.#birthLifeSeedScale[id * 4 + 2] = Math.random(); // Random seed
this.#birthLifeSeedScale[id * 4 + 3] = Math.random() * 0.5 + 0.5; // Scale
this.#petalMesh.geometry.attributes.aSpawnPos.needsUpdate = true;
this.#petalMesh.geometry.attributes.aBirthLifeSeedScale.needsUpdate = true;
}
createPetalMaterial(perlinTexture) {
const material = new THREE.MeshBasicNodeMaterial({
transparent: true,
side: THREE.DoubleSide,
});
function rotX(a) {
const c = cos(a);
const s = sin(a);
const ns = s.mul(-1.0);
return mat3(1.0, 0.0, 0.0, 0.0, c, ns, 0.0, s, c);
}
function rotY(a) {
const c = cos(a);
const s = sin(a);
const ns = s.mul(-1.0);
return mat3(c, 0.0, s, 0.0, 1.0, 0.0, ns, 0.0, c);
}
function rotZ(a) {
const c = cos(a);
const s = sin(a);
const ns = s.mul(-1.0);
return mat3(c, ns, 0.0, s, c, 0.0, 0.0, 0.0, 1.0);
}
const aSpawnPos = attribute('aSpawnPos', 'vec3');
const aBirthLifeSeedScale = attribute('aBirthLifeSeedScale', 'vec4');
const aBirth = aBirthLifeSeedScale.x;
const aLife = aBirthLifeSeedScale.y;
const aSeed = aBirthLifeSeedScale.z;
const aScale = aBirthLifeSeedScale.w;
const uWindDirection = uniform(new THREE.Vector3(-1, 0, 0).normalize());
const uWindStrength = uniform(0.3);
const uRiseSpeed = uniform(0.1); // constant lift
const uNoiseScale = uniform(30.0); // start small (frequency)
const uNoiseSpeed = uniform(0.015); // scroll speed
const uWobbleAmp = uniform(0.6); // vertical wobble amplitude
const uBendAmount = uniform(2.5);
const uBendSpeed = uniform(1.0);
const uSpinSpeed = uniform(2.0);
const uSpinAmp = uniform(0.45); // overall rotation amount
const uRedColor = uniform(new THREE.Color('#9B0000'));
const uWhiteColor = uniform(new THREE.Color('#EEEEEE'));
const uLightPosition = uniform(new THREE.Vector3(0, 0, 5));
// Age of the dust in seconds
const dustAge = time.sub(aBirth);
const lifeInterpolation = clamp(dustAge.div(aLife), 0, 1);
// Use noise
const randomSeed = vec2(aSeed.mul(123.4), aSeed.mul(567.8));
const noiseUv = aSpawnPos.xz
.mul(uNoiseScale)
.add(randomSeed)
.add(uWindDirection.xz.mul(dustAge.mul(uNoiseSpeed)));
// Return a value between 0 and 1.
const noiseSample = texture(perlinTexture, noiseUv).x;
const noiseSammpleBis = texture(perlinTexture, noiseUv.add(vec2(13.37, 7.77))).x;
// Convert to turbulence values between -1 and 1.
const turbulenceX = noiseSample.sub(0.5).mul(2);
const turbulenceY = noiseSammpleBis.sub(0.5).mul(2);
const turbulenceZ = noiseSample.sub(0.5).mul(2);
const swirl = vec3(clamp(turbulenceX.mul(lifeInterpolation), 0, 1.0), turbulenceY.mul(lifeInterpolation), 0.0).mul(
uWobbleAmp
);
// Bending
const y = uv().y;
const bendWeight = pow(y, float(3.0));
const bend = bendWeight.mul(uBendAmount).mul(sin(dustAge.mul(uBendSpeed.mul(noiseSample))));
const B = rotX(bend);
const windImpulse = uWindDirection.mul(uWindStrength).mul(dustAge);
const riseFactor = clamp(noiseSample, 0.3, 1.0);
const rise = vec3(0.0, dustAge.mul(uRiseSpeed).mul(riseFactor), 0.0);
const driftMovement = windImpulse.add(rise).add(swirl);
// Spin
const baseX = aSeed.mul(1.13).mod(1.0).mul(TWO_PI);
const baseY = aSeed.mul(2.17).mod(1.0).mul(TWO_PI);
const baseZ = aSeed.mul(3.31).mod(1.0).mul(TWO_PI);
const spin = dustAge.mul(uSpinSpeed).mul(uSpinAmp);
const rx = baseX.add(spin.mul(0.9).mul(turbulenceX.add(1.5)));
const ry = baseY.add(spin.mul(1.2).mul(turbulenceY.add(1.5)));
const rz = baseZ.add(spin.mul(0.7).mul(turbulenceZ.add(1.5)));
const R = rotY(ry).mul(rotX(rx)).mul(rotZ(rz));
// 0 at creation, 1 at death
const scaleFactor = smoothstep(float(0), float(0.05), lifeInterpolation);
const fadingOut = float(1.0).sub(smoothstep(float(0.8), float(1.0), lifeInterpolation));
// Update local position
const positionLocalUpdated = R.mul(B.mul(positionLocal));
const normalUpdate = normalize(R.mul(B.mul(normalLocal)));
// Compute world position
const worldPosition = aSpawnPos.add(driftMovement).add(positionLocalUpdated.mul(aScale.mul(scaleFactor)));
// Petals color computation
const petalColor = mix(uRedColor, uWhiteColor, instanceIndex.mod(3).equal(0));
const lightDirection = normalize(uLightPosition.sub(worldPosition));
const facing = clamp(abs(dot(normalUpdate, lightDirection)), 0.4, 1);
material.colorNode = petalColor.mul(facing);
material.positionNode = worldPosition;
material.opacityNode = fadingOut;
material.mrtNode = mrt({
bloomIntensity: float(0.7).mul(fadingOut),
});
return material;
}
}
vite.config.js
import { defineConfig } from 'vite';
export default defineConfig({
base: './',
server: {
open: true,
},
build: {
outDir: 'dist',
},
});
Media credits and license evidence실행 안내·자료
README.md
## Credits
- [three-msdf-text-utils](https://github.com/leochocolat/three-msdf-text-utils) by Léo Mouraire
- [msdf-bmfont-xml](https://github.com/soimy/msdf-bmfont-xml) by Shen Yiming
- Perlin Texture from [Screaming Brain Studios](https://screamingbrainstudios.com/downloads/)
## License
[MIT](LICENSE)
LICENSE실행 안내·자료
MIT License
Copyright (c) 2009 - 2025 [Codrops](https://codrops.com)
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
Bundled dependency licenses실행 안내·자료
GSAP standard license snapshot
Source: https://gsap.com/community/standard-license/
Retrieved: 2026-09-22T04:22:49.089Z
Original distribution copyright and version headers remain in the runtime code.
Standard "No Charge" GSAP License
I. DEFINITIONS
“GSAP License” means the terms and conditions of this GSAP Software License Agreement.
"GSAP Products" means any Software made available at gsap.com (https://gsap.com) or any successor sites, including but not limited to the GSAP animation library and related plugins, tools, or extensions.
"Permitted Uses" means the implementation and/or use of GSAP Products on any website, web application, or digital interface by any person or entity (which may include, for clarity, those of companies that compete with Webflow in other areas of business).
"Prohibited Uses" means any implementation and/or use of GSAP Products in tools that allow users to build visual animations without code that encourages, induces, or materially assists in creating a solution that competes with Webflow’s visual animation building capabilities.
"Competitive Products" means any software, tool, or service that enables users to create, edit, or manage animations through a visual interface or builder similar to Webflow (https://webflow.com).
II. GRANT OF LICENSE
Subject to the terms and conditions of this GSAP License, Webflow grants you a non-exclusive, worldwide license to use, reproduce, display, and implement GSAP Products solely for Permitted Uses.
III. RESTRICTIONS
You may not:
Use any GSAP Products for any Prohibited Uses without prior written consent;
Reverse engineer any GSAP Products for the purpose of creating Competitive Products;
Remove or alter any proprietary notices or branding from GSAP Products.
IV. OWNERSHIP AND INTELLECTUAL PROPERTY
All intellectual property rights in GSAP Products, including but not limited to copyright, patents, trademarks, and trade secrets, remain the exclusive property of Webflow. This GSAP License does not transfer any ownership rights in GSAP Products to you.
V. TERMINATION
Webflow may terminate this GSAP License and revoke your access in its discretion if you fail to comply with any of these terms and conditions. Upon termination, you must cease all use of GSAP Products and destroy all copies in your possession.
VI. MISCELLANEOUS PROVISIONS
General: This GSAP License is incorporated into and subject to Webflow’s Terms of Service available here (https://webflow.com/legal/terms) ("Terms of Service"). In the event of any conflict or inconsistency between this GSAP License and the Terms of Service, the terms of this GSAP License shall govern in relation to your use of any GSAP Products.
Amendments: Webflow reserves the right to update or modify this GSAP License at any time by posting the revised terms on this website, provided that any such updates or modifications shall not result in any material degradation to the security, integrity, or functionality of any GSAP Products. You understand and agree that your continued use of any GSAP Products after such revisions to this GSAP License constitutes your acceptance of this GSAP License as revised. If you do not accept the revised GSAP License, you are prohibited from using versions of the GSAP Products released after the effective date of the revised GSAP License (as well as any updates made to previous versions). Notwithstanding, you may continue using previous versions of GSAP Products under the applicable terms licensed to you prior to the effective date of the revised GSAP License (for clarity, excluding any updates made thereto).
No Waiver: Failure of Webflow to enforce any provision of this GSAP License shall not constitute a waiver of future enforcement of that or any other provision.
FAQ
Is it acceptable for AI tools like ChatGPT, Cursor, Lovable, Webstudio, etc. to generate GSAP code?
Absolutely! AI-generated code is not a "Prohibited Use".
What if a WordPress plugin or theme or other niche tool allows users to create GSAP-driven effects through a visual interface? Is that prohibited?
We want to encourage developers to build on top of GSAP, including visual tools that don't directly compete with Webflow's rich animation-building capabilities. If you are not sure if your product might be considered a "Prohibited Use", feel free to contact us (https://gsap.com/contact) so we can talk through it!
Can I really use GSAP in commercial projects without paying anything?
Yes, really! Commercial usage is covered under the standard license. All of GSAP including the plugins that were formerly "members-only" like SplitText (https://gsap.com/docs/v3/Plugins/SplitText/) and MorphSVG (https://gsap.com/docs/v3/Plugins/MorphSVGPlugin) can be used in commercial projects at no charge. Enjoy! 💚
Effective date: April 30, 2025
Last modified date: May 30, 2025
Copyright (©) 2025, Webflow
three@0.181.2 — LICENSE
The MIT License
Copyright © 2010-2025 three.js authors
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
BEHIND THE EXAMPLE
이 장면을 만드는 원리
텍스트 소멸과 입자 생성 예약의 정리
반복 입력에서 현재 의도와 전환의 종료·취소 책임을 명시합니다.
- 이 예제에서는
- triggerGommage는 6초 진행률과 먼지·꽃잎 생성 tween을 시작하고 버튼을 비활성화합니다. 완료 때 생성 tween을 종료한 뒤 1초 delayedCall로 버튼을 다시 켭니다.
코드와 함께 확인하기
코드에서 찾기
resetGommagegommageOrchestrator.js주요 세 tween을 종료하고 진행률을 0으로 되돌립니다.
직접 해보기
완료 직전과 버튼 재활성화 대기 중 reset·화면 제거를 수행합니다.
살펴볼 변화저장되지 않은 지연 콜백이 새 상태의 버튼을 켜거나 제거된 표면을 갱신하지 않는지 확인해야 합니다.
