# graphics3d/toon/toonvfx (vanilla.js 0.4.0)

> https://vanillapunch.com/docs/vanilla.js/0.4.0/api/graphics3d/toon/toonvfx/

툰 3D GPU 효과의 바탕. (외계행성 광부 키우기와 애버런트가 따로 쓰던 판 안 효과의 범용 부분)

예제: 툰 장면 위에 폭발 효과를 내고 한 프레임 그리기

```js
import { ToonRenderer, ToonVfx, ToonVfxLook, ToonVfxShape, ToonVfxDecalMode, MeshBuilder, createBoxGeometry, Matrix4, Vector3 } from "./vanilla.js";
const webGL2RenderingContext = document.createElement("canvas").getContext("webgl2");
const renderer = new ToonRenderer(webGL2RenderingContext);
const builder = new MeshBuilder();
builder.addPart(createBoxGeometry(8, 0.2, 8), Matrix4.createTranslation(0, -0.1, 0), "#708090", { hasOutline: false });
const floorMesh = renderer.createMesh(builder.readArrays());
const vfx = new ToonVfx(webGL2RenderingContext);
vfx.setRamps([["#ffffff", "#ffe080", "#ff8020", "#a02010", "#301008"]]);
vfx.prepare();
vfx.addFireball({ position: [0, 0.8, 0], radius: 0.9, life: 1.2, ramp: 0 });
vfx.addShockwave({ x: 0, z: 0, endRadius: 3, life: 0.6, ramp: 0 });
vfx.addDecal({ x: 0, z: 0, radius: 1.4, life: 8, heatSeconds: 1.5, mode: ToonVfxDecalMode.scorch, ramp: 0 });
vfx.emitParticles({ count: 40, position: [0, 0.6, 0], shape: ToonVfxShape.sphere, radius: 0.3, speed: [2, 5], gravity: 6, size: [0.05, 0.12], life: [0.4, 0.9], look: ToonVfxLook.streak, stretch: 0.05, ramp: 0, isGrounded: true });
const viewMatrix = Matrix4.createLookAt(Vector3.create(4, 3, 5), Vector3.create(0, 0.5, 0), Vector3.create(0, 1, 0));
const projectionMatrix = Matrix4.createPerspective(Math.PI / 4, 1, 0.1, 100);
vfx.update(1 / 60);
renderer.beginFrameWithMatrices(viewMatrix, projectionMatrix);
renderer.drawMesh(floorMesh, Matrix4.createIdentity());
renderer.endFrame();
vfx.draw(viewMatrix, projectionMatrix);
```

## ToonVfx

툰 3D GPU 효과의 바탕. (외계행성 광부 키우기와 애버런트가 따로 쓰던 판 안 효과의 범용 부분)
- 텍스처: 그림 파일 없이 처음 그릴 때 코드로 짓는 아틀라스 한 장. 왼쪽 반은 연기 플립북 16 칸, 오른쪽 반은 ToonVfxSlot 칸과 색 램프 여덟 줄.
  램프 색은 게임이 정한다. (setRamps, 줄마다 흰 심에서 어둠으로 가는 색들, 효과의 ramp 는 줄 번호, -1 이면 램프 없이 color 만)
- 파티클: 인스턴스로 그리는 GPU 파티클. 낼 때 한 번 버퍼에 쓰고 자리, 크기, 색은 정점 셰이더가 나이로 셈한다. (끌림, 중력, 바닥에서 멈춤, 속도 쪽으로 늘인 줄기, 색 램프)
  상한(setParticleCapacity)을 넘으면 가장 오래 전에 낸 것부터 덮고, setCountRatio 로 내는 수에 몫을 곱한다. (폰과 가벼운 길)
- 효과 메쉬: 잡음으로 끓다 연기로 식는 불덩이(addFireball), 바깥으로 흐르며 찢기고 말려 오르는 충격파 띠와 그 밑 바닥 빛(addShockwave),
  바닥 자국(addDecal, queueDecal), 말려 오르는 연기 기둥(addPlume), 결이 흐르고 겉이 일렁이는 회전체 빔(queueBeam),
  카메라 쪽으로 편 리본(queueRibbon)과 그것을 감아 내린 번개(queueLightning), 사는 동안 다시 꺾이는 번개(addLightning), 그 자리의 빛 점(queueGlint).
- 테: 빛 파티클의 rim, 리본의 glow 와 rim, 불덩이와 충격파의 rim 은 가장자리를 테 색(setRimColor)으로 덮어 밝은 바탕에서도 보이게 한다. (기본은 더하는 빛만)
- 밝기 배: setLookGain(꼴, 배) 로 파티클과 빛 점의 꼴마다 밝기를 곱한다. (기본 1, HDR 판에서 불꽃 줄기, 빛살, 불씨를 선형 몇 배로 할 때)
- 나이와 열쇠: emitParticles, addFireball, addShockwave, addDecal, addPlume, addLightning, addFlash 는 options.age(이미 지난 초, 음수면 그만큼 늦게)와
  options.key(사건 열쇠, 이미 낸 열쇠면 다시 내지 않음, clear 가 잊음)를 받는다. 장면이 매 프레임 상태에서 사건을 다시 내도 한 번만, 늦게 보인 효과는 그 나이부터 튼다.
  흔들림(addShake)은 Shaker 의 지수 감쇠(초당 9)라 늦게 보인 사건은 세기 x exp(-9 x 나이) 로 넘기면 같다.
- 발밑 그늘: queueBlobShadow 는 그 프레임의 둥근 그늘 자국(ToonVfxDecalMode.shade)이다.
- 화면: 섬광(addFlash)은 draw 끝에 지금 뷰포트(가위가 걸려 있으면 그 안)를 그 색으로 덮고 걷힌다.
  카메라 흔들림(addShake)은 엔진 Shaker 로 셈하고, readShake 가 준 오프셋을 게임이 카메라의 오른쪽과 위쪽으로 더한다.
- 어느 사건에 어느 효과를 어떤 값으로 낼지(처방)는 게임 몫이다. 엔진은 매개변수만 받는다.
- 바닥: setFloorHeightReader((x, z) => 높이) 로 게임이 바닥 높이를 알려 주면 자국, 충격파, 연기 기둥은 그 높이에, isGrounded 파티클은 그 높이에서 멈춘다. (없으면 0)
- 시계: update(초) 가 이 바탕의 시계를 나아가게 한다. 판이 멈추면 효과도 멈춘다. queue 로 넘긴 것은 그 프레임에 한 번 그리고 비운다.
- 그리기: draw(보기, 투영) 를 툰 모형을 그린 뒤 부른다. 깊이 시험은 켜고 깊이는 쓰지 않으며 미리 곱한 알파로 섞는다. 앞의 상태를 적어 두었다 돌린다.

예제: 매 프레임 상태에서 사건을 다시 내도 열쇠로 한 번만 내기

```js
import { ToonVfx, ToonVfxLook, ToonVfxShape, Matrix4, Vector3 } from "./vanilla.js";
const webGL2RenderingContext = document.createElement("canvas").getContext("webgl2");
const vfx = new ToonVfx(webGL2RenderingContext, 2000);
vfx.setRamps([["#ffffff", "#ffd070", "#ff7020", "#802010", "#200808"]]);
const viewMatrix = Matrix4.createLookAt(Vector3.create(0, 3, 6), Vector3.create(0, 0.5, 0), Vector3.create(0, 1, 0));
const projectionMatrix = Matrix4.createPerspective(Math.PI / 4, 1, 0.1, 100);
for (let frameIndex = 0; frameIndex < 3; ++frameIndex) {
	vfx.addFireball({ position: [0, 0.8, 0], radius: 0.7, life: 1, ramp: 0, key: "explosion-1" });
	vfx.emitParticles({ count: 24, position: [0, 0.8, 0], shape: ToonVfxShape.sphere, radius: 0.2, speed: [2, 4], look: ToonVfxLook.ember, ramp: 0, life: 0.8, key: "explosion-1-sparks" });
	vfx.queueBlobShadow({ x: 1, z: 0, radius: 0.4 });
	vfx.update(1 / 60);
	vfx.draw(viewMatrix, projectionMatrix);
}
const counts = vfx.getActiveCounts();
vfx.destroy();
```

- `constructor(webGL2RenderingContext, particleCapacity = TOON_VFX_DEFAULT_PARTICLE_CAPACITY)` (constructor, since 0.4.0): 생성. (셰이더와 메쉬, 파티클 버퍼를 지음, 아틀라스는 처음 그릴 때)
  - `webGL2RenderingContext` WebGL2RenderingContext: 효과를 그릴 WebGL2 컨텍스트.
  - `particleCapacity` number: 한꺼번에 떠 있는 파티클의 상한.
- `static readProgramSources()` (static, since 0.4.0): 셰이더 소스 반환. (ShaderWarmer 로 미리 링크할 때)
  - returns Array<object>: { vertexShader, fragmentShader, attributeLocationTable } 의 배열.

  예제: 켤 때 효과 셰이더를 미리 링크해 두기

  ```js
  import { ToonVfx, ShaderWarmer } from "./vanilla.js";
  const webGL2RenderingContext = document.createElement("canvas").getContext("webgl2");
  const shaderWarmer = new ShaderWarmer(webGL2RenderingContext, ToonVfx.readProgramSources());
  shaderWarmer.update();
  if (shaderWarmer.isFinished()) {
  	const vfx = new ToonVfx(webGL2RenderingContext);
  	vfx.prepare();
  }
  ```

- `createBuffer()` (method, since 0.4.0): 버퍼 하나 만들기. (지울 목록에 넣는다)
  - returns WebGLBuffer: 새 버퍼.
- `setRamps(ramps)` (method, since 0.4.0): 색 램프 설정. (줄마다 흰 심에서 어둠으로 가는 "#rrggbb" 나 [r, g, b] 의 배열, 여덟 줄까지, 효과의 ramp 는 이 차례)
  - `ramps` Array<Array<string | Array<number>>>: 줄마다 흰 심에서 어둠으로 가는 색들. (여덟 줄까지, 빈 줄은 버림)

  예제: 불과 얼음 램프 두 줄을 주고 줄 번호로 고르기

  ```js
  import { ToonVfx, ToonVfxLook } from "./vanilla.js";
  const vfx = new ToonVfx(document.createElement("canvas").getContext("webgl2"));
  vfx.setRamps([
  	["#ffffff", "#ffe080", "#ff8020", "#801808", "#200804"],
  	["#ffffff", [0.7, 0.95, 1], [0.3, 0.6, 1], [0.05, 0.1, 0.3]],
  ]);
  vfx.emitParticles({ count: 20, position: [0, 1, 0], ramp: 0, look: ToonVfxLook.ember, speed: [1, 3], life: 0.8 });
  vfx.emitParticles({ count: 20, position: [2, 1, 0], ramp: 1, look: ToonVfxLook.star, speed: [0.5, 1], life: 0.6 });
  ```

- `prepare()` (method, since 0.4.0): 아틀라스를 미리 지어 두기. (처음 터질 때 멈칫하지 않게, 판에 들어갈 때)
- `setParticleCapacity(particleCapacity)` (method, since 0.4.0): 파티클 상한 설정. (떠 있던 파티클은 지운다)
  - `particleCapacity` number: 한꺼번에 떠 있는 파티클의 상한. (1 이상)
- `getParticleCapacity()` (method, since 0.4.0): 파티클 상한 반환.
  - returns number: 한꺼번에 떠 있는 파티클의 상한.
- `setCountRatio(countRatio)` (method, since 0.4.0): 내는 파티클 수의 몫 설정. (폰이나 가벼운 길에서 짜임은 그대로 두고 수만 줄임, 0 ~ 1, 내면 적어도 하나)
  - `countRatio` number: 내는 파티클 수에 곱하는 몫. (0 ~ 1)
- `getCountRatio()` (method, since 0.4.0): 내는 파티클 수의 몫 반환.
  - returns number: 내는 파티클 수에 곱하는 몫. (0 ~ 1)
- `setGlintCapacity(glintCapacity)` (method, since 0.4.0): 빛 점 상한 설정. (프레임마다 queueGlint 로 넘기는 수, 기본 96, 이번 프레임에 넘긴 빛 점은 지운다)
  - `glintCapacity` number: 프레임마다 넘기는 빛 점의 상한. (1 이상)
- `getGlintCapacity()` (method, since 0.4.0): 빛 점 상한 반환.
  - returns number: 프레임마다 넘기는 빛 점의 상한.
- `setLookGain(look, gain)` (method, since 0.4.0): 꼴마다 밝기 배 설정. (ToonVfxLook 의 꼴, 파티클과 빛 점의 밝기에 곱함, 기본 1)
  - `look` number: 꼴. (ToonVfxLook)
  - `gain` number: 밝기 배. (0 이상, 기본 1)

  예제: HDR 판에서 불꽃 줄기와 빛살과 불씨만 더 밝게

  ```js
  import { ToonVfx, ToonVfxLook } from "./vanilla.js";
  const vfx = new ToonVfx(document.createElement("canvas").getContext("webgl2"));
  vfx.setLookGain(ToonVfxLook.streak, 3);
  vfx.setLookGain(ToonVfxLook.star, 4);
  vfx.setLookGain(ToonVfxLook.ember, 2.5);
  const streakGain = vfx.getLookGain(ToonVfxLook.streak);
  ```

- `getLookGain(look)` (method, since 0.4.0): 꼴마다 밝기 배 반환.
  - `look` number: 꼴. (ToonVfxLook)
  - returns number: 그 꼴의 밝기 배. (꼴이 범위 밖이면 1)
- `registerEventKey(key)` (method, since 0.4.0): 사건 열쇠 적기. (열쇠가 없으면 늘 true, 처음 보는 열쇠면 적고 true, 이미 낸 열쇠면 false, clear 가 잊는다)
  - `key` number | string | undefined | null: 사건 열쇠. (없으면 늘 낸다)
  - returns boolean: 내도 되면 true, 이미 낸 열쇠면 false.

  예제: 효과 밖의 일도 같은 사건 열쇠로 한 번만

  ```js
  import { ToonVfx } from "./vanilla.js";
  const vfx = new ToonVfx(document.createElement("canvas").getContext("webgl2"));
  let playCount = 0;
  for (let frameIndex = 0; frameIndex < 3; ++frameIndex) {
  	if (vfx.registerEventKey("door-7-open")) {
  		playCount += 1;
  	}
  }
  vfx.clear();
  const isNewAfterClear = vfx.registerEventKey("door-7-open");
  ```

- `setRimColor(rimColor)` (method, since 0.4.0): 효과 테의 색 설정. ([r, g, b] 0 ~ 1, 테를 두른 파티클과 번짐 리본의 가장자리, 기본은 ToonRenderer 의 기본 바깥선 색)
  - `rimColor` Array<number>: 테의 색. ([r, g, b] 0 ~ 1)

  예제: 밝은 바탕에서도 보이게 테를 두른 빛 알갱이와 불덩이

  ```js
  import { ToonVfx, ToonVfxLook } from "./vanilla.js";
  const vfx = new ToonVfx(document.createElement("canvas").getContext("webgl2"));
  vfx.setRimColor([0.12, 0.06, 0.03]);
  vfx.emitParticles({ count: 12, position: [0, 1, 0], look: ToonVfxLook.soft, color: [1, 0.8, 0.3], rim: 1, size: 0.3, speed: 1.5, life: 0.6 });
  vfx.addFireball({ position: [0, 1, 0], radius: 0.8, life: 1, rim: 0.7 });
  ```

- `getRimColor()` (method, since 0.4.0): 효과 테의 색 반환.
  - returns Array<number>: 효과 테의 색. ([r, g, b] 0 ~ 1)
- `setFloorHeightReader(floorHeightReader)` (method, since 0.4.0): 바닥 높이를 읽는 함수 설정. ((x, z) → 높이, null 이면 0)
  - `floorHeightReader` function | null: (x, z) 로 바닥 높이를 돌려주는 함수. (null 이면 늘 0)

  예제: 울퉁불퉁한 바닥 높이를 알려 주기

  ```js
  import { ToonVfx, ToonVfxLook } from "./vanilla.js";
  const vfx = new ToonVfx(document.createElement("canvas").getContext("webgl2"));
  vfx.setFloorHeightReader((x, z) => {
  	return Math.sin(x * 0.5) * 0.3 + Math.cos(z * 0.5) * 0.2;
  });
  vfx.addDecal({ x: 1, z: 2, radius: 1, life: 4 });
  vfx.emitParticles({ count: 16, position: [1, 1, 2], isGrounded: true, gravity: 9, speed: [1, 2], look: ToonVfxLook.grit, color: [0.4, 0.3, 0.2] });
  const floorHeight = vfx.readFloorHeight(1, 2);
  vfx.setFloorHeightReader(null);
  ```

- `readFloorHeight(x, z)` (method, since 0.4.0): 그 자리의 바닥 높이.
  - `x` number: 장면의 x.
  - `z` number: 장면의 z.
  - returns number: 그 자리의 바닥 높이.
- `getTime()` (method, since 0.4.0): 이 바탕의 시계. (초)
  - returns number: 이 바탕의 시계. (초, update 로 나아감)
- `getActiveCounts()` (method, since 0.4.0): 떠 있는 효과의 수. ({ particleCount (아직 살아 있을 수 있는 칸), fireballCount, shockwaveCount, decalCount, plumeCount, lightningCount, flashCount })
  - returns object: { particleCount, fireballCount, shockwaveCount, decalCount, plumeCount, lightningCount, flashCount }.

  예제: 효과가 다 사라졌는지 보기

  ```js
  import { ToonVfx } from "./vanilla.js";
  const vfx = new ToonVfx(document.createElement("canvas").getContext("webgl2"));
  vfx.addFireball({ position: [0, 1, 0], radius: 1, life: 0.5 });
  vfx.emitParticles({ count: 10, position: [0, 1, 0], life: 0.3 });
  vfx.update(1);
  const counts = vfx.getActiveCounts();
  const isQuiet = counts.particleCount === 0 && counts.fireballCount === 0;
  ```

- `clear()` (method, since 0.4.0): 다 지우기. (판이 바뀔 때, 사건 열쇠도 잊는다)
- `clearQueue()` (method, since 0.4.0): 이번 프레임에 넘긴 것 비우기. (그린 뒤)
- `update(deltaTime)` (method, since 0.4.0): 한 프레임 나이 먹이기. (시계를 나아가게 하고 다 된 불덩이, 띠, 자국, 기둥, 번개, 섬광을 지움, 흔들림을 잦아들게 함)
  - `deltaTime` number: 초.
- `emitParticles(options)` (method, since 0.4.0): 파티클 내기.
    options: { count, position([x, y, z], 기본 [0, 0, 0]), shape(ToonVfxShape), radius, direction, spread(라디안), length, isUpward, isInward,
               speed, rise, gravity, drag, size, sizeEnd(시작 크기에 곱함), sizeCurve, life, delay,
               color, ramp, look(ToonVfxLook), stretch, spin, floor, isGrounded, brightness, alpha, fadeIn, rim(빛의 꼴의 테, 0 이면 더하는 빛만, 1 이면 테로 덮음, 음수면 엷게 덮는 빛무리),
               age(이미 지난 초, 음수면 그만큼 늦게), key(사건 열쇠, 이미 낸 열쇠면 내지 않음) }
    범위가 되는 값(speed, rise, size, sizeEnd, life, delay, spin)은 수 하나나 [최소, 최대] 다. 색은 0 ~ 1 의 [r, g, b], 램프는 줄 번호(없으면 -1)다.
    floor 를 주면 그 높이에서, isGrounded 면 낸 자리의 바닥 높이에서 멈춘다. isInward 면 속도를 무시하고 나이가 다할 때 낸 자리로 빨려 든다.
  - `options` object: 내는 값. (꼴은 위 머리 주석의 options)

  예제: 원뿔로 튀는 불꽃 줄기, 같은 열쇠로 다시 내면 무시

  ```js
  import { ToonVfx, ToonVfxLook, ToonVfxShape } from "./vanilla.js";
  const vfx = new ToonVfx(document.createElement("canvas").getContext("webgl2"));
  const sparkOptions = {
  	count: 30, position: [0, 1, 0],
  	shape: ToonVfxShape.cone, direction: [0, 1, 0], spread: 0.4,
  	speed: [3, 6], gravity: 9, drag: 1.5, size: [0.04, 0.08], sizeEnd: 0.3,
  	life: [0.5, 1], look: ToonVfxLook.streak, stretch: 0.04, color: [1, 0.7, 0.3],
  	isGrounded: true, age: 0.1, key: "spark-12",
  };
  vfx.emitParticles(sparkOptions);
  vfx.emitParticles(sparkOptions);
  ```

- `addFireball(options)` (method, since 0.4.0): 불덩이 더하기. (잡음으로 끓는 구가 부풀며 식어 연기가 되고 위로 떠오름)
    options: { position([x, y, z], 기본 [0, 0, 0]), radius, life, ramp, smokeColor, rise, growSeconds, boil, rim(덮는 꼴의 몫, 0 이면 더하는 빛만), age, key }
  - `options` object: 불덩이 값. (꼴은 위 머리 주석의 options)

  예제: 부풀어 식으며 떠오르는 불덩이

  ```js
  import { ToonVfx } from "./vanilla.js";
  const vfx = new ToonVfx(document.createElement("canvas").getContext("webgl2"));
  vfx.setRamps([["#ffffff", "#ffe080", "#ff8020", "#801808", "#200804"]]);
  vfx.addFireball({ position: [0, 1, 0], radius: 1.2, life: 1.5, ramp: 0, rise: 1, growSeconds: 0.25, boil: 0.4, smokeColor: [0.2, 0.18, 0.16], key: "barrel-3" });
  ```

- `addShockwave(options)` (method, since 0.4.0): 충격파 띠 더하기. (빠르게 퍼지다 천천히, 바깥 끝이 말려 오르고 잡음으로 찢기며 엷어짐, 밑의 바닥이 잠깐 밝아짐, 바닥 높이에 놓임)
    options: { x, z, startRadius, endRadius, width, life, ramp, color, lift(말려 오르는 높이), height(바닥 위 띄움), delay, rim(덮는 꼴의 몫, 0 이면 더하는 빛만), age, key }
  - `options` object: 충격파 값. (꼴은 위 머리 주석의 options)

  예제: 조금 늦게 퍼지며 말려 오르는 충격파 띠

  ```js
  import { ToonVfx } from "./vanilla.js";
  const vfx = new ToonVfx(document.createElement("canvas").getContext("webgl2"));
  vfx.addShockwave({ x: 0, z: 0, startRadius: 0.2, endRadius: 4, width: 0.8, life: 0.7, ramp: 0, color: [1, 0.9, 0.7], lift: 0.4, delay: 0.05, rim: 0.5 });
  ```

- `addDecal(options)` (method, since 0.4.0): 바닥 자국 더하기. (그을음은 열기에서 식고 끝 1 초에 엷어짐, startRadius 에서 growSeconds 동안 radius 로 퍼질 수 있음, 바닥 높이에 놓임)
    options: { x, z, radius, startRadius, growSeconds, life, heatSeconds, slot(ToonVfxSlot), mode(ToonVfxDecalMode), ramp, tint, alpha, angle, ring, flicker(깜빡이는 반주기 초, 0 이면 없음), age, key }
  - `options` object: 자국 값. (꼴은 위 머리 주석의 options, life 를 주지 않으면 바로 사라짐)

  예제: 퍼지며 식는 그을음과 깜빡이는 얼룩

  ```js
  import { ToonVfx, ToonVfxSlot, ToonVfxDecalMode } from "./vanilla.js";
  const vfx = new ToonVfx(document.createElement("canvas").getContext("webgl2"));
  vfx.addDecal({ x: 0, z: 0, radius: 1.5, startRadius: 0.4, growSeconds: 0.3, life: 10, heatSeconds: 2, slot: ToonVfxSlot.scorch, mode: ToonVfxDecalMode.scorch, ramp: 0 });
  vfx.addDecal({ x: 3, z: 0, radius: 0.8, life: 6, mode: ToonVfxDecalMode.stain, tint: [0.2, 0.45, 0.1], alpha: 0.7, flicker: 0.25 });
  ```

- `queueBlobShadow(options)` (method, since 0.4.0): 이번 프레임에만 그리는 발밑 그늘 넘기기. (가운데 alpha 에서 바깥으로 둥글게 엷어지는 그늘, 바닥 높이에 놓임)
    options: { x, z, radius, alpha(기본 0.45) }
  - `options` object: 그늘 값. (꼴은 위 머리 주석의 options)

  예제: 캐릭터마다 발밑 그늘을 매 프레임 넘기기

  ```js
  import { ToonVfx, Matrix4, Vector3 } from "./vanilla.js";
  const vfx = new ToonVfx(document.createElement("canvas").getContext("webgl2"));
  const viewMatrix = Matrix4.createLookAt(Vector3.create(0, 4, 6), Vector3.create(0, 0, 0), Vector3.create(0, 1, 0));
  const projectionMatrix = Matrix4.createPerspective(Math.PI / 4, 1, 0.1, 100);
  const characterPositions = [[0, 0], [1.5, -0.5], [-1, 1]];
  for (const position of characterPositions) {
  	vfx.queueBlobShadow({ x: position[0], z: position[1], radius: 0.5 });
  }
  vfx.draw(viewMatrix, projectionMatrix);
  ```

- `queueDecal(options)` (method, since 0.4.0): 이번 프레임에만 그리는 바닥 자국 넘기기. (꼴이 프레임마다 정해지는 것, addDecal 과 같고 나이 대신 heat(0 ~ 1)를 바로 준다, 돎과 씨앗은 주지 않으면 0)
  - `options` object: 자국 값. (addDecal 의 값에 heat(0 ~ 1)와 seed)

  예제: 고른 자리에 흐르는 테와 빛 자국을 매 프레임 넘기기

  ```js
  import { ToonVfx, ToonVfxSlot, ToonVfxDecalMode } from "./vanilla.js";
  const vfx = new ToonVfx(document.createElement("canvas").getContext("webgl2"));
  vfx.queueDecal({ x: 0, z: 0, radius: 1.2, mode: ToonVfxDecalMode.ring, tint: [0.4, 0.9, 1], heat: 1, alpha: 1, ring: [0.8, 0.06, 3, 0.6], seed: 4 });
  vfx.queueDecal({ x: 2, z: 0, radius: 0.9, slot: ToonVfxSlot.glow, mode: ToonVfxDecalMode.glow, tint: [1, 0.6, 0.2], heat: 0.8, alpha: 0.9, angle: 0.5 });
  ```

- `addPlume(options)` (method, since 0.4.0): 연기 기둥 더하기. (기둥이 솟고 갓이 말려 오르며 커지고, 갓 밑이 달아올랐다 식으며 엷어짐, 바닥 높이에 섬)
    options: { x, z, height, capRadius, stemRadius, life, ramp, smokeColor, age, key }
  - `options` object: 연기 기둥 값. (꼴은 위 머리 주석의 options)

  예제: 큰 폭발 뒤에 솟는 연기 기둥

  ```js
  import { ToonVfx } from "./vanilla.js";
  const vfx = new ToonVfx(document.createElement("canvas").getContext("webgl2"));
  vfx.addPlume({ x: 0, z: 0, height: 4, capRadius: 1.6, stemRadius: 0.35, life: 5, ramp: 0, smokeColor: [0.3, 0.28, 0.26], key: "blast-9-plume" });
  ```

- `queueBeam(options)` (method, since 0.4.0): 이번 프레임에만 그리는 회전체 빔 넘기기.
    options: { start, end([x, y, z], 결은 start 에서 end 쪽으로 흐름), radius, isCore(심이면 흰빛, 아니면 램프의 겉집), alpha(기본 1), brightness, ramp, wobble, flowSpeed, grainRepeat(길이 한 칸마다의 결), time, seed }
  - `options` object: 빔 값. (꼴은 위 머리 주석의 options, radius 와 alpha 가 0 보다 커야 넘어감)

  예제: 흰 심과 램프 겉집 두 겹의 빔

  ```js
  import { ToonVfx, Matrix4, Vector3 } from "./vanilla.js";
  const vfx = new ToonVfx(document.createElement("canvas").getContext("webgl2"));
  const viewMatrix = Matrix4.createLookAt(Vector3.create(4, 3, 4), Vector3.create(0, 1, -4), Vector3.create(0, 1, 0));
  const projectionMatrix = Matrix4.createPerspective(Math.PI / 4, 1, 0.1, 100);
  const start = [0, 1, 0];
  const end = [0, 1, -8];
  vfx.queueBeam({ start: start, end: end, radius: 0.12, isCore: true, alpha: 1, brightness: 1.5 });
  vfx.queueBeam({ start: start, end: end, radius: 0.3, alpha: 0.8, ramp: 0, wobble: 0.15, flowSpeed: 6, grainRepeat: 0.6, seed: 2 });
  vfx.draw(viewMatrix, projectionMatrix);
  ```

- `queueRibbon(options)` (method, since 0.4.0): 이번 프레임에만 그리는 리본 넘기기. (점열을 카메라 쪽으로 편 띠)
    options: { points([[x, y, z], ...], 둘 이상), width, taper(0 이면 고른 너비, 1 이면 두 끝이 0), color, ramp, alpha(기본 1), brightness, grainRepeat, flow,
               glow(번짐 색 [r, g, b], 주면 흰 심과 그 색 둘레와 테 색 가장자리로 덮는다, 없으면 더하는 빛), rim(glow 가 없을 때 몸을 테 색으로 덮고 심은 색인 꼴의 몫, 0 이면 더하는 빛만) }
  - `options` object: 리본 값. (꼴은 위 머리 주석의 options, 점이 둘 이상이고 width 와 alpha(주지 않으면 1) 가 0 보다 커야 넘어감)

  예제: 휘두른 자취를 번짐 리본과 더하는 빛 리본으로

  ```js
  import { ToonVfx } from "./vanilla.js";
  const vfx = new ToonVfx(document.createElement("canvas").getContext("webgl2"));
  const trailPoints = [[-1, 1, 0], [-0.5, 1.3, -0.4], [0, 1.4, -0.6], [0.5, 1.3, -0.4], [1, 1, 0]];
  vfx.queueRibbon({ points: trailPoints, width: 0.25, taper: 1, alpha: 1, brightness: 1.2, glow: [0.4, 0.8, 1] });
  vfx.queueRibbon({ points: trailPoints, width: 0.1, color: [1, 0.9, 0.6], alpha: 0.8, grainRepeat: 2, flow: vfx.getTime() * 4 });
  ```

- `queueLightning(options)` (method, since 0.4.0): 이번 프레임의 번개 넘기기. (축을 감아 내려가는 리본 여럿, 0.08 초마다 다시 꺾임, 같은 시각과 씨앗이면 같은 꼴)
    options: { start, end, radius(감는 반지름), count, width, turns(감는 바퀴), color, ramp, alpha, brightness, time(주지 않으면 이 바탕의 시계), seed, glow(리본의 번짐 색), rim(리본의 rim) }
  - `options` object: 번개 값. (꼴은 위 머리 주석의 options, radius 와 width 는 꼭 준다)

  예제: 하늘에서 내리치는 번개 셋을 이번 프레임에

  ```js
  import { ToonVfx } from "./vanilla.js";
  const vfx = new ToonVfx(document.createElement("canvas").getContext("webgl2"));
  vfx.queueLightning({ start: [0, 4, 0], end: [0, 0, 0], radius: 0.15, count: 3, width: 0.06, turns: 1.5, color: [0.8, 0.9, 1], alpha: 1, brightness: 1.5, seed: 7 });
  ```

- `queueGlint(options)` (method, since 0.4.0): 이번 프레임에만 그리는 빛 점 넘기기. (파티클과 같은 꼴, 나이 없이 그 자리에 그대로, setGlintCapacity 까지(기본 96))
    options: { position([x, y, z], 기본 [0, 0, 0]), size(기본 0.2), color, ramp, look, brightness, alpha(기본 1), angle, rim(파티클의 rim 과 같음) }
  - `options` object: 빛 점 값. (꼴은 위 머리 주석의 options, size 는 꼭 준다)

  예제: 보석 위에 반짝이는 빛살을 매 프레임

  ```js
  import { ToonVfx, ToonVfxLook } from "./vanilla.js";
  const vfx = new ToonVfx(document.createElement("canvas").getContext("webgl2"));
  vfx.setGlintCapacity(32);
  const twinkle = 0.5 + 0.5 * Math.sin(vfx.getTime() * 6);
  vfx.queueGlint({ position: [0.5, 1.2, 0], size: 0.4 * twinkle, look: ToonVfxLook.star, color: [1, 0.95, 0.7], angle: 0.3, brightness: 1.5 });
  ```

- `addLightning(options)` (method, since 0.4.0): 사는 동안 다시 꺾이는 번개 더하기. (그릴 때마다 queueLightning 으로 넘긴다, 끝 0.1 초에 엷어짐, age 가 음수면 그만큼 늦게 나타남)
    options: { start, end, life(초), age, radius, count, width, turns, color, ramp, alpha, brightness, seed(주지 않으면 무작위), glow, rim, key }
  - `options` object: 번개 값. (꼴은 위 머리 주석의 options)

  예제: 0.4 초 동안 다시 꺾이며 사는 번개

  ```js
  import { ToonVfx, Matrix4, Vector3 } from "./vanilla.js";
  const vfx = new ToonVfx(document.createElement("canvas").getContext("webgl2"));
  const viewMatrix = Matrix4.createLookAt(Vector3.create(0, 2, 6), Vector3.create(0, 2, 0), Vector3.create(0, 1, 0));
  const projectionMatrix = Matrix4.createPerspective(Math.PI / 4, 1, 0.1, 100);
  vfx.addLightning({ start: [0, 4, 0], end: [0.5, 0, 0.2], life: 0.4, count: 2, width: 0.08, radius: 0.2, glow: [0.5, 0.7, 1], key: "strike-5" });
  for (let frameIndex = 0; frameIndex < 3; ++frameIndex) {
  	vfx.update(1 / 60);
  	vfx.draw(viewMatrix, projectionMatrix);
  }
  ```

- `addFlash(options)` (method, since 0.4.0): 화면 섬광 더하기. (뷰포트를 그 색으로 잠깐 덮고 빠르게 걷힘)
    options: { color([r, g, b], 기본 흰), strength(처음 덮는 몫, 기본 0.8), life(초, 기본 0.08), age, key }
  - `options` object: 섬광 값. (꼴은 위 머리 주석의 options)

  예제: 터질 때 화면을 잠깐 밝게 덮기

  ```js
  import { ToonVfx } from "./vanilla.js";
  const vfx = new ToonVfx(document.createElement("canvas").getContext("webgl2"));
  vfx.addFlash({ color: [1, 0.9, 0.7], strength: 0.6, life: 0.12, key: "blast-9-flash" });
  ```

- `addShake(strength)` (method, since 0.4.0): 카메라 흔들림 더하기. (장면 길이의 최대 오프셋, 엔진 Shaker 가 위상이 다른 두 사인파와 지수 감쇠로 셈, 흔들리는 중이면 센 쪽)
    자리 3 축과 돌림, 겹쳐 더하기, 나이로 이어 붙이기는 CameraShake 를 쓴다. (Camera3D.setViewOffset 으로 건다)
  - `strength` number: 흔들림의 최대 오프셋. (장면 길이)

  예제: 흔들림을 카메라 오른쪽과 위쪽에 더하기

  ```js
  import { ToonVfx, Matrix4, Vector3 } from "./vanilla.js";
  const vfx = new ToonVfx(document.createElement("canvas").getContext("webgl2"));
  vfx.addShake(0.2);
  vfx.update(1 / 60);
  const shake = vfx.readShake();
  const eye = Vector3.create(shake.x, 1.5 + shake.y, 6);
  const target = Vector3.create(shake.x, 1.5 + shake.y, 0);
  const viewMatrix = Matrix4.createLookAt(eye, target, Vector3.create(0, 1, 0));
  const isStill = !vfx.isShaking();
  ```

- `readShake()` (method, since 0.4.0): 지금의 카메라 흔들림. (장면 길이, x 는 카메라 오른쪽, y 는 카메라 위쪽으로 카메라 자리와 보는 곳에 같이 더한다)
  - returns Vector2: 흔들림 오프셋. (장면 길이, x 는 카메라 오른쪽, y 는 카메라 위쪽)
- `isShaking()` (method, since 0.4.0): 카메라가 흔들리는 중인지.
  - returns boolean: 흔들리는 중이면 true.
- `draw(viewMatrix, projectionMatrix)` (method, since 0.4.0): 그리기. (바닥 자국, 띠, 연기 기둥, 불덩이, 빔, 리본, 파티클, 섬광 차례, 사는 번개는 이번 프레임의 리본으로 넘김, 넘긴 것은 그린 뒤 비움)
    보기 행렬에서 카메라 쪽, 오른쪽, 위쪽, 자리를 읽는다. 투영이 원근이면 빔과 리본은 카메라 자리를 향하고, 직교면 카메라 쪽을 향한다.
  - `viewMatrix` Matrix4: 카메라의 보기 행렬.
  - `projectionMatrix` Matrix4: 투영 행렬. (원근이나 직교)

  예제: 직교 투영 장면에 효과 그리기

  ```js
  import { ToonVfx, ToonVfxLook, Matrix4, Vector3 } from "./vanilla.js";
  const vfx = new ToonVfx(document.createElement("canvas").getContext("webgl2"));
  const viewMatrix = Matrix4.createLookAt(Vector3.create(5, 5, 5), Vector3.create(0, 0, 0), Vector3.create(0, 1, 0));
  const projectionMatrix = Matrix4.createOrthographic(-4, 4, -4, 4, 0.1, 50);
  vfx.emitParticles({ count: 20, position: [0, 0.5, 0], look: ToonVfxLook.glow, color: [0.4, 0.8, 1], speed: 1, size: 0.4, life: 1 });
  vfx.queueBeam({ start: [-2, 0.5, 0], end: [2, 0.5, 0], radius: 0.1, isCore: true, alpha: 1 });
  vfx.update(0.1);
  vfx.draw(viewMatrix, projectionMatrix);
  ```

- `readFrame(viewMatrix, projectionMatrix)` (method, since 0.4.0): 그리는 프레임의 카메라. ({ viewProjectionElements, viewDirection(장면에서 카메라 쪽), cameraRight, cameraUp, cameraPoint([자리, 1] 원근, [카메라 쪽, 0] 직교) })
  - `viewMatrix` Matrix4: 카메라의 보기 행렬.
  - `projectionMatrix` Matrix4: 투영 행렬. (원근이나 직교)
  - returns object: { viewProjectionElements, viewDirection, cameraRight, cameraUp, cameraPoint }.
- `useProgram(shaderProgram, frame)` (method, since 0.4.0): 프로그램을 쓰고 보기와 투영과 아틀라스 유니폼 올리기.
  - `shaderProgram` ShaderProgram: 쓸 효과 셰이더.
  - `frame` object: readFrame 이 돌려준 그리는 프레임의 카메라.
- `destroy()` (method, since 0.4.0): 다 쓴 뒤 지우기.

## Functions and constants

- `TOON_VFX_MAXIMUM_RAMPS = 8` (field, since 0.4.0): 색 램프 줄의 수 상한. (아틀라스의 램프 칸 하나에 여덟 줄)
  - returns number
- `TOON_VFX_DEFAULT_PARTICLE_CAPACITY = 3000` (field, since 0.4.0): 한꺼번에 떠 있는 파티클의 기본 상한. (넘으면 가장 오래 전에 낸 것부터 덮는다)
  - returns number

## ToonVfxSlot (enum)

아틀라스 오른쪽 반의 칸. (셰이더의 readSlot 번호와 같다, 6, 7, 11 ~ 15 는 비어 있다)

예제: 바닥 자국에 쓸 칸 고르기

```js
import { ToonVfx, ToonVfxSlot, ToonVfxDecalMode } from "./vanilla.js";
const vfx = new ToonVfx(document.createElement("canvas").getContext("webgl2"));
vfx.addDecal({ x: 0, z: 0, radius: 1.2, life: 8, slot: ToonVfxSlot.dent, mode: ToonVfxDecalMode.scorch });
vfx.queueDecal({ x: 2, z: 0, radius: 1, slot: ToonVfxSlot.glow, mode: ToonVfxDecalMode.glow, tint: [1, 0.6, 0.2], heat: 1 });
```

- `soft` = `0`: 부드러운 알갱이.
- `streak` = `1`: 불꽃 줄기. (v 1 쪽이 머리)
- `star` = `2`: 빛살.
- `shockBand` = `3`: 충격 띠. (u 는 둘레로 이어지는 타일, v 는 안쪽 0 에서 바깥 1)
- `beamGrain` = `4`: 빔 결. (두 방향 타일)
- `scorch` = `5`: 그을음. (알파는 어둡게 덮는 몫, 빨간 채널은 열기)
- `ramps` = `8`: 색 램프 여덟 줄.
- `dent` = `9`: 패인 땅.
- `glow` = `10`: 넓은 둘레 빛.

## ToonVfxLook (enum)

파티클의 꼴.

예제: 덮는 연기와 바닥에 멈추는 흙 알갱이

```js
import { ToonVfx, ToonVfxLook } from "./vanilla.js";
const vfx = new ToonVfx(document.createElement("canvas").getContext("webgl2"));
vfx.emitParticles({ count: 8, position: [0, 0.5, 0], look: ToonVfxLook.smoke, color: [0.5, 0.48, 0.45], speed: 0.4, rise: 0.8, size: 0.6, sizeEnd: 2.5, life: [1.5, 2.5], spin: [-1, 1] });
vfx.emitParticles({ count: 20, position: [0, 0.2, 0], look: ToonVfxLook.grit, color: [0.35, 0.28, 0.2], speed: [2, 4], gravity: 9, isUpward: true, isGrounded: true, size: 0.06, life: 1.2 });
```

- `soft` = `0`: 부드러운 알갱이. (더하는 빛)
- `streak` = `1`: 속도 쪽으로 늘인 불꽃 줄기. (더하는 빛, stretch 가 속도에 곱하는 늘임)
- `smoke` = `2`: 연기 플립북. (덮기)
- `star` = `3`: 빛살. (더하는 빛)
- `ember` = `4`: 깜빡이는 불씨. (더하는 빛)
- `glow` = `5`: 넓은 둘레 빛. (더하는 빛)
- `grit` = `6`: 빛을 내지 않는 돌과 흙 알갱이. (덮기)

## ToonVfxShape (enum)

파티클을 내는 꼴.

예제: 바닥 고리로 퍼지는 먼지와 선을 따라 늘어선 빛

```js
import { ToonVfx, ToonVfxLook, ToonVfxShape } from "./vanilla.js";
const vfx = new ToonVfx(document.createElement("canvas").getContext("webgl2"));
vfx.emitParticles({ count: 32, position: [0, 0.1, 0], shape: ToonVfxShape.ring, radius: 0.5, speed: 3, drag: 4, look: ToonVfxLook.soft, size: 0.15, life: 0.5 });
vfx.emitParticles({ count: 40, position: [0, 1, 0], shape: ToonVfxShape.line, direction: [1, 0, 0], length: 5, radius: 0.05, speed: 0.5, look: ToonVfxLook.glow, size: 0.3, life: 0.4 });
```

- `point` = `point`: 한 점에서 모든 쪽으로.
- `sphere` = `sphere`: 반지름 radius 공 안에서 바깥쪽으로.
- `ring` = `ring`: 바닥과 나란한 고리 위에서 바깥쪽으로.
- `disc` = `disc`: 바닥과 나란한 원판 안에서 바깥쪽으로.
- `cone` = `cone`: direction 을 가운데로 spread 각 안의 원뿔.
- `line` = `line`: direction 쪽으로 length 까지의 선 위(둘레 radius 안)에서 direction 쪽으로.

## ToonVfxDecalMode (enum)

바닥 자국의 꼴.

예제: 기름 윤 자국과 발밑 그늘

```js
import { ToonVfx, ToonVfxSlot, ToonVfxDecalMode } from "./vanilla.js";
const vfx = new ToonVfx(document.createElement("canvas").getContext("webgl2"));
vfx.addDecal({ x: 0, z: 0, radius: 1, life: 6, slot: ToonVfxSlot.soft, mode: ToonVfxDecalMode.sheen, tint: [0.05, 0.05, 0.08] });
vfx.queueDecal({ x: 2, z: 0, radius: 0.6, mode: ToonVfxDecalMode.shade, alpha: 0.5 });
```

- `scorch` = `0`: 알파로 어둡게 덮고 빨간 채널의 금에서 열기가 식는다.
- `glow` = `1`: 칸의 알파만큼 더하는 빛.
- `ring` = `2`: 둘레로 흐르는 잡음 테. (ring 이 (테 반지름, 테 너비, 잡음 잘기, 흐르는 빠르기) 의 반지름 몫)
- `stain` = `3`: 칸의 알파만큼 tint 색으로 덮고, 칸의 가운데 짙기(테 둘레)는 테 색(setRimColor) 쪽으로 물든다. (밝은 바닥의 얼룩, 서리)
- `sheen` = `4`: 칸의 알파 몸을 tint 로 덮고 몸 가장자리에 흰 윤을 두른다. (기름 윤)
- `shade` = `5`: 가운데에서 바깥으로 둥글게 엷어지는 그늘. (알파만큼 어둡게 덮음, 칸은 보지 않음, 발밑 그늘 queueBlobShadow)
