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

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

툰 HDR 마무리. (실수 렌더 타겟에 그린 선형 색을 블룸, 노출, 톤매핑, 감마로 화면에 낸다)

예제: 툰 장면을 실수 판에 그리고 블룸과 톤매핑으로 내기

```js
import { ToonRenderer, ToonPostProcess, MeshBuilder, createSphereGeometry, Camera3D, Matrix4, Vector3 } from "./vanilla.js";
const canvas = Object.assign(document.createElement("canvas"), { width: 640, height: 360 });
const webGL2RenderingContext = canvas.getContext("webgl2");
const postProcess = new ToonPostProcess(webGL2RenderingContext, canvas.width, canvas.height, { sampleCount: 4 });
postProcess.setExposure(1.2);
postProcess.setBloom(true, 0.8, 0.9, 1.6);
const renderer = new ToonRenderer(webGL2RenderingContext);
renderer.setHdrOutput(postProcess.getUseFloatColor());
const builder = new MeshBuilder();
builder.addPart(createSphereGeometry(0.5, 32, 20), Matrix4.createIdentity(), "#ffd080", { glow: 2 });
const mesh = renderer.createMesh(builder.readArrays());
const camera = new Camera3D();
camera.setPerspective(0.8, 0.1, 100);
camera.setAspectRatio(canvas.width / canvas.height);
camera.lookAt(Vector3.create(0, 1, 3), Vector3.create(0, 0, 0), Vector3.create(0, 1, 0));
postProcess.begin([0.02, 0.02, 0.04]);
renderer.beginFrameWithCamera(camera);
renderer.drawMesh(mesh, Matrix4.createIdentity());
renderer.endFrame();
postProcess.end(null, [0, 0, canvas.width, canvas.height]);
```

## ToonPostProcess

툰 HDR 마무리. (실수 렌더 타겟에 그린 선형 색을 블룸, 노출, 톤매핑, 감마로 화면에 낸다)
- RenderTarget(반정밀 실수 색, 깊이), BloomEffect(또는 MultiLevelBloomEffect), FullscreenPass 를 엮는다.
- 사용: ToonRenderer.setHdrOutput(true) 뒤 begin(바탕 선형 색) → ToonRenderer 로 그리기 → end(낼 프레임버퍼, 뷰포트)
  end 는 (멀티샘플이면 풀고) 블룸을 셈하고 톤매핑한 색을 낼 프레임버퍼(null 이면 화면)에 그린다.
- 생성 옵션: new ToonPostProcess(gl, 너비, 높이, { sampleCount, useFloatColor, depthBits, useDepthTexture }) (옵션이 없으면 지금과 같은 RGBA16F, 깊이 16, 멀티샘플 없음)
  sampleCount 가 2 이상이면 씬을 멀티샘플(MSAA) 렌더버퍼에 그리고 end 앞에서 텍스처로 푼다. 기기가 받는 수로 줄인다. (getSampleCount, setSampleCount)
  depthBits 24 는 깊이 24 비트. (먼 면이 먼 장면) useDepthTexture 는 씬 깊이를 텍스처로 남긴다. (setLitArea 가 쓴다)
- 색 공간: 씬 렌더 타겟에는 선형 색을 쓴다. (ToonRenderer.setHdrOutput(true), ToonScreenOutline.setHdrOutput(true), ToonVfx 색도 선형으로 본다)
  감마를 건 색 g 를 실수 판에 쓰고 합성에서 g^2.2 로 되돌리던 게임은 그 값을 미리 선형으로 바꿔 넘긴다. 색은 c^2.2, 감마 쪽에서 곱하던 밝기 배 k 는 선형 k^2.2 다.
  (예: 1.37 은 선형 2, 1.6 은 2.81, 2.08 은 5, 밝기 1.6 에 배 1.6 이면 (1.6 x 1.6)^2.2 = 7.9) 블룸 문턱과 무릎은 선형 밝기다.
  이 예는 감마 쪽(감마를 건 색 g)에서 곱하던 배일 때만 맞다. 선형 색에 곱하던 배와 블룸 문턱, 무릎처럼 처음부터 선형인 값은 바꾸지 않고 그대로 넘긴다.
- 실수 판을 못 쓰는 기기: useFloatColor(기본 true)여도 ToonPostProcess.isFloatColorSupported 가 false 면 RGBA8 판으로 짓는다. (getUseFloatColor 가 false)
  그때와 useFloatColor: false 는 LDR 길이다. 씬에는 화면 색(감마를 건 색, ToonRenderer.setHdrOutput(false))을 그리고, 합성은 톤매핑과 감마 없이 블룸을 더해 색 보정만 건다.
- 캔버스 antialias: 이 후처리가 자기 MSAA 판(sampleCount)에 그리므로 쓰는 게임은 EngineConfiguration.antialias 를 false 로 짓는다.
  true 면 캔버스 자체가 MSAA 라 화면에 옮기는 패스와 UI 가 표본마다 섞여 값이 더 든다. (맥미니 2560x1440 툰 후처리 장면 GPU 처리량 6.89 → 6.49 ms, 끈 판 6.81 → 5.22 ms)
  예: engineConfiguration.antialias = false;
- 블룸: 기본은 반 해상도 9 탭 가우시안(BloomEffect, 문턱 0.9 ~ 1.6, 주고받는 판 RGBA8, setBloomFloatColor 로 RGBA16F).
  setBloomLevels(단 수, 문턱, 무릎) 로 단 수를 1 이상 주면 MultiLevelBloomEffect(반씩 줄였다 천막 꼴로 키우며 더함, 씬과 같은 정밀도의 판)로 바꾼다. 0 이면 기본으로 돌린다. 세기는 setBloom 이 둘 다에 쓴다.
- 톤매핑은 ACES 근사(Krzysztof Narkowicz 2016, 원문이 CC0 또는 MIT 로 쓰게 함)다. 노출(setExposure)을 곱한 뒤 매핑하고 sRGB 감마를 건다.
  감마 색 공간(기본)은 pow(1 / 2.2), 선형 색 공간(options.colorSpace 나 엔진의 ColorSpace.linear)은 sRGB 표준 곡선(IEC 61966-2-1)이다. (ToonRenderer 의 LDR 출력과 같은 곡선)
- 색 보정: 감마를 건 뒤 밝기(setBrightness, 밝힌 자리 setLitArea 안은 1 쪽으로), 채도, 색조(밝기 1 로 맞춘 색을 곱함), 안개빛(어두운 곳을 그 색 쪽으로), 대비, 가장자리 어둡게 차례로 건다. (setColorGrade, setVignette)
  기본은 밝기 1, 채도 1, 대비 1, 색조 0, 안개빛 0, 가장자리 0 이라 보정이 없다.
- 해상도 배율: setResolutionScale(배율) 이면 씬 판을 출력 크기 x 배율로 짓고 end 의 뷰포트로 키워(선형 거르기) 낸다. (3D 만 낮춰 그리고 UI 는 기기 화소 그대로 둘 때, 기본 1)
- 노드 사각형 안에 낼 때: resize(사각형 너비, 높이) → begin → 그리기(ToonRenderer 의 화면 사각형은 풀어 둔다) → end(null, [x, 드로잉 버퍼 높이 - y - 높이, 너비, 높이]).
- 모서리 어둠(화면 공간 AO): setAmbientOcclusion(켬, 세기, 반지름, 해상도 배율, 직접 빛 몫) 로 켠다. (기본 꺼짐, 세기 0.5, 반지름 0.5 월드 길이, 반 해상도, 직접 빛 몫 0)
  GTAO(Jimenez 2016)를 반 해상도로 셈하고, 접평면 거리와 노멀로 가장자리를 지키며 가로로 흐린 뒤 세로로 흐리며 온 해상도로 키운다. (잡음은 고정 무늬라 멈춘 화면은 흔들리지 않는다)
  노멀과 깊이는 화면 바깥선(ToonScreenOutline)의 선의 판을 다시 쓴다. 바깥선이 없는 장면은 선은 긋지 않고 선의 판만 그리는 getAmbientOcclusionPrepass() 를 쓴다.
  ToonDrawQueue.setPostProcess(이것) 이면 큐가 선의 판 뒤, 몸 앞에 drawAmbientOcclusion 을 부르고 렌더러에 결과를 건다. 몸 셰이더는 바탕빛(하늘과 땅 빛)에 곱하고, 직접 빛 몫만큼 해, 채움빛, 점광의 확산과 반사광에도 곱한다. (칸을 고른 뒤라 칸 경계는 그대로, 몫 0 이면 바탕빛에만)
  엔진에 있던 AmbientOcclusionEffect 는 원근의 시야각과 가까운, 먼 면으로만 깊이를 풀고 RGB 월드 노멀과 커버리지 알파를 받는 반구 표본 꼴이라 직교 카메라와 선의 판(팔면체 노멀)에 맞지 않아 따로 짓는다.

예제: 3D 만 낮춰 그리고 색 보정 걸기

```js
import { ToonRenderer, ToonPostProcess } from "./vanilla.js";
const webGL2RenderingContext = document.createElement("canvas").getContext("webgl2");
const postProcess = new ToonPostProcess(webGL2RenderingContext, 1280, 720, { depthBits: 24, useDepthTexture: true });
postProcess.setResolutionScale(0.75);
postProcess.setBloomLevels(5, 1, 0.25);
postProcess.setColorGrade(1.1, 1.05, [1, 0.9, 0.8], 0.3, [0.2, 0.25, 0.35], 0.15);
postProcess.setVignette(0.3);
const renderer = new ToonRenderer(webGL2RenderingContext);
renderer.setHdrOutput(postProcess.getUseFloatColor());
```

- `constructor(webGL2RenderingContext, width, height, options = null)` (constructor, since 0.4.0): 생성. (화면 픽셀 크기, 옵션 { sampleCount = 0, useFloatColor = true, depthBits = 16, useDepthTexture = false })
  - `webGL2RenderingContext` WebGL2RenderingContext: 툰 렌더러와 같은 컨텍스트.
  - `width` number: 출력 너비. (픽셀)
  - `height` number: 출력 높이. (픽셀)
  - `options` object | null: { sampleCount (기본 0), useFloatColor (기본 true), depthBits (16 이나 24), useDepthTexture (기본 false), colorSpace (ColorSpace, 기본은 엔진의 색 공간, ToonRenderer 와 같은 값) }
- `static isFloatColorSupported(webGL2RenderingContext)` (static, since 0.4.0): 실수 컬러 판을 그릴 수 있는지. (EXT_color_buffer_float 나 EXT_color_buffer_half_float 가 있고, 1 x 1 RGBA16F 를 붙인 프레임버퍼가 완성되는지)
  - `webGL2RenderingContext` WebGL2RenderingContext: 알아볼 컨텍스트.
  - returns boolean: RGBA16F 판에 그릴 수 있으면 true.

  예제: 기기에 맞춰 HDR 길과 LDR 길 고르기

  ```js
  import { ToonRenderer, ToonPostProcess } from "./vanilla.js";
  const webGL2RenderingContext = document.createElement("canvas").getContext("webgl2");
  const isHdr = ToonPostProcess.isFloatColorSupported(webGL2RenderingContext);
  const postProcess = new ToonPostProcess(webGL2RenderingContext, 640, 360, { useFloatColor: isHdr });
  const renderer = new ToonRenderer(webGL2RenderingContext);
  renderer.setHdrOutput(isHdr);
  ```

- `createSceneRenderTarget()` (method, since 0.4.0): 씬 렌더 타겟 짓기. (출력 크기 x 해상도 배율, 지금 옵션으로)
  - returns RenderTarget: 새로 지은 씬 렌더 타겟.
- `readSceneWidth()` (method, since 0.4.0): 씬 판의 너비. (출력 너비 x 해상도 배율, 1 이상)
  - returns number: 씬 판의 너비. (픽셀)
- `readSceneHeight()` (method, since 0.4.0): 씬 판의 높이. (출력 높이 x 해상도 배율, 1 이상)
  - returns number: 씬 판의 높이. (픽셀)
- `resize(width, height)` (method, since 0.4.0): 크기 바꾸기. (출력 크기, 씬 판은 해상도 배율을 곱함, 같으면 그대로)
  - `width` number: 출력 너비. (픽셀)
  - `height` number: 출력 높이. (픽셀)

  예제: 캔버스 크기가 바뀔 때 맞추기

  ```js
  import { ToonPostProcess } from "./vanilla.js";
  const canvas = document.createElement("canvas");
  const webGL2RenderingContext = canvas.getContext("webgl2");
  const postProcess = new ToonPostProcess(webGL2RenderingContext, canvas.width, canvas.height);
  canvas.width = 1280;
  canvas.height = 720;
  postProcess.resize(canvas.width, canvas.height);
  ```

- `setResolutionScale(resolutionScale)` (method, since 0.4.0): 해상도 배율 설정. (씬 판 = 출력 크기 x 배율, 0.05 ~ 4, 기본 1)
  - `resolutionScale` number: 씬 판의 배율. (0.05 ~ 4)

  예제: 폰에서 3D 만 반 해상도로

  ```js
  import { ToonPostProcess } from "./vanilla.js";
  const postProcess = new ToonPostProcess(document.createElement("canvas").getContext("webgl2"), 1080, 1920);
  postProcess.setResolutionScale(0.5);
  const resolutionScale = postProcess.getResolutionScale();
  const sceneWidth = postProcess.getSceneRenderTarget().getWidth();
  ```

- `getResolutionScale()` (method, since 0.4.0): 해상도 배율 반환.
  - returns number: 씬 판의 배율.
- `setSampleCount(sampleCount)` (method, since 0.4.0): 멀티샘플 표본 수 설정. (2 밑이면 없음, 바뀌면 씬 판을 다시 짓는다)
  - `sampleCount` number: 멀티샘플 표본 수. (2 밑이면 멀티샘플 없음)

  예제: 설정에서 계단 줄이기를 켜고 실제 표본 수 읽기

  ```js
  import { ToonPostProcess } from "./vanilla.js";
  const postProcess = new ToonPostProcess(document.createElement("canvas").getContext("webgl2"), 640, 360);
  postProcess.setSampleCount(4);
  const sampleCount = postProcess.getSampleCount();
  const isMultisampled = sampleCount >= 2;
  ```

- `getSampleCount()` (method, since 0.4.0): 실제로 쓰는 멀티샘플 표본 수 반환. (0 이면 없음)
  - returns number: 씬 판이 실제로 쓰는 표본 수. (기기가 받는 수로 줄인 것, 0 이면 없음)
- `getUseFloatColor()` (method, since 0.4.0): 씬 판이 실수인지 반환. (false 면 LDR 길)
  - returns boolean: 씬 판이 실수면 true. (ToonRenderer.setHdrOutput 에 그대로 넘긴다)
- `getColorSpace()` (method, since 0.4.0): 색 공간 반환. (생성 때 정한 값, 톤매핑 뒤 화면 색을 내는 곡선을 가른다)
  - returns string: ColorSpace.gamma 나 ColorSpace.linear.

  예제: 렌더러와 같은 색 공간으로 지은 후처리

  ```js
  import { ToonRenderer, ToonPostProcess, ColorSpace } from "./vanilla.js";
  const webGL2RenderingContext = document.createElement("canvas").getContext("webgl2");
  const renderer = new ToonRenderer(webGL2RenderingContext, { colorSpace: ColorSpace.linear });
  const postProcess = new ToonPostProcess(webGL2RenderingContext, 320, 180, { colorSpace: renderer.getColorSpace() });
  if (postProcess.getColorSpace() !== ColorSpace.linear) {
  	throw new Error("color space is not linear");
  }
  ```

- `begin(clearColor)` (method, since 0.4.0): 씬 그리기 시작. (씬 렌더 타겟을 묶고 바탕 색과 깊이로 비운다, HDR 길은 선형 색, LDR 길은 화면 색)
  - `clearColor` Array<number>: [r, g, b] 바탕 색. (HDR 길은 선형 색, LDR 길은 화면 색)
- `end(outputFramebuffer, viewport)` (method, since 0.4.0): 마무리. (멀티샘플이면 풂 → 블룸 → 톤매핑해 낼 프레임버퍼에, viewport 는 [x, y, 너비, 높이])
  - `outputFramebuffer` WebGLFramebuffer | null: 낼 프레임버퍼. (null 이면 화면)
  - `viewport` Array<number>: [x, y, 너비, 높이] 낼 자리. (드로잉 버퍼 픽셀, 왼쪽 아래가 원점)

  예제: 왼쪽 위 원점의 사각형 안에 내기

  ```js
  import { ToonPostProcess } from "./vanilla.js";
  const webGL2RenderingContext = document.createElement("canvas").getContext("webgl2");
  const screenRect = { x: 40, y: 20, width: 200, height: 120 };
  const postProcess = new ToonPostProcess(webGL2RenderingContext, screenRect.width, screenRect.height);
  postProcess.begin([0.05, 0.05, 0.08]);
  const bottomY = webGL2RenderingContext.drawingBufferHeight - screenRect.y - screenRect.height;
  postProcess.end(null, [screenRect.x, bottomY, screenRect.width, screenRect.height]);
  ```

- `setExposure(exposure)` (method, since 0.4.0): 노출 설정. (톤매핑 전에 곱한다, 1 이 기본)
  - `exposure` number: 노출 배. (0 이상, 1 이 기본)
- `setBloom(isBloomEnabled, bloomStrength, thresholdStart, thresholdEnd)` (method, since 0.4.0): 블룸 설정. (켜기, 세기, 밝은 곳을 뽑는 문턱의 시작과 끝, 문턱은 기본 9 탭 블룸에만 쓴다)
  - `isBloomEnabled` boolean: 블룸을 켤지.
  - `bloomStrength` number: 블룸 세기. (씬 색에 더하는 배, 기본 0.6)
  - `thresholdStart` number: 밝은 곳을 뽑기 시작하는 선형 밝기. (기본 0.9)
  - `thresholdEnd` number: 다 뽑는 선형 밝기. (기본 1.6)

  예제: 빛나는 것만 은은하게 번지게

  ```js
  import { ToonPostProcess } from "./vanilla.js";
  const postProcess = new ToonPostProcess(document.createElement("canvas").getContext("webgl2"), 640, 360);
  postProcess.setExposure(1.1);
  postProcess.setBloom(true, 0.5, 1.2, 2.5);
  postProcess.setBloomFloatColor(true);
  ```

- `setBloomLevels(levelCount, threshold, knee)` (method, since 0.4.0): 블룸 단 수 설정. (0 이면 기본 9 탭 블룸, 1 이상이면 그 단 수의 다단 블룸, 문턱과 무릎은 다단 블룸의 선형 밝기)
  - 다단 블룸 판은 씬 판과 같은 정밀도다. (HDR 길은 RGBA16F)
  - `levelCount` number: 단 수. (0 이면 기본 9 탭 블룸으로 돌린다)
  - `threshold` number: 다단 블룸의 문턱. (선형 밝기)
  - `knee` number: 문턱 둘레를 부드럽게 넘기는 폭. (선형 밝기)

  예제: 넓게 번지는 다단 블룸으로 바꿨다 되돌리기

  ```js
  import { ToonPostProcess } from "./vanilla.js";
  const postProcess = new ToonPostProcess(document.createElement("canvas").getContext("webgl2"), 640, 360);
  postProcess.setBloomLevels(6, 1, 0.3);
  const levelCount = postProcess.getBloomLevelCount();
  postProcess.setBloomLevels(0, 1, 0.3);
  ```

- `getBloomLevelCount()` (method, since 0.4.0): 블룸 단 수 반환. (0 이면 기본 9 탭 블룸)
  - returns number: 다단 블룸의 단 수. (0 이면 기본 9 탭 블룸)
- `setBloomFloatColor(isFloatColor)` (method, since 0.4.0): 기본 9 탭 블룸의 주고받는 판을 실수로. (true 면 RGBA16F, 기본 false 는 RGBA8, 씬 판이 실수가 아니면 무시)
  - `isFloatColor` boolean: true 면 RGBA16F, false 면 RGBA8.
- `setBrightness(brightness)` (method, since 0.4.0): 밝기 설정. (색 보정 맨 앞에서 곱한다, 1 이 그대로)
  - `brightness` number: 밝기 배. (0 이상, 1 이 그대로)
- `setLitArea(center, innerRadius, outerRadius, inverseViewProjectionMatrix)` (method, since 0.4.0): 밝힌 자리 설정. (그 자리에서 수평 거리 innerRadius 안은 밝기 1, outerRadius 밖은 setBrightness 의 밝기, 사이는 부드럽게)
  - 씬 깊이 텍스처(옵션 useDepthTexture)와 그 프레임의 보기와 투영의 역행렬로 화소마다 월드 자리를 되짚는다. 깊이 텍스처가 없으면 무시한다.
  - 카메라가 움직이면 프레임마다 다시 준다. 아무것도 그리지 않은 바탕은 먼 면의 자리로 셈한다.
  - `center` Array<number>: [x, y, z]
  - `innerRadius` number: 밝기 1 인 수평 반지름. (월드 길이)
  - `outerRadius` number: 이 밖은 setBrightness 의 밝기인 수평 반지름. (월드 길이)
  - `inverseViewProjectionMatrix` Matrix4: 이번 프레임 보기와 투영의 역행렬.

  예제: 어두운 장면에서 손전등 둘레만 밝히기

  ```js
  import { ToonPostProcess, Camera3D, Vector3 } from "./vanilla.js";
  const webGL2RenderingContext = document.createElement("canvas").getContext("webgl2");
  const postProcess = new ToonPostProcess(webGL2RenderingContext, 640, 360, { useDepthTexture: true });
  const camera = new Camera3D();
  camera.setPerspective(0.8, 0.1, 100);
  camera.lookAt(Vector3.create(0, 6, 8), Vector3.create(0, 0, 0), Vector3.create(0, 1, 0));
  postProcess.setBrightness(0.35);
  postProcess.setLitArea([0, 0, 0], 2, 4, camera.getInverseViewProjectionMatrix());
  ```

- `clearLitArea()` (method, since 0.4.0): 밝힌 자리 풀기.
- `setColorGrade(saturation, contrast, toneColor, toneAmount, hazeColor, hazeAmount)` (method, since 0.4.0): 색 보정 설정. (채도와 대비는 1 이 그대로, 색조와 안개빛은 sRGB [r, g, b] 0 ~ 1 과 섞는 양 0 ~ 1)
  - 색조 색은 밝기(Rec. 709)를 1 로 맞춰 곱하므로 밝기는 그대로 두고 빛깔만 물든다.
  - 안개빛은 어두운 곳일수록 그 색 쪽으로 끌어올린다. (양 x (1 - 밝기))
  - `saturation` number: 채도. (1 이 그대로, 0 이면 흑백)
  - `contrast` number: 대비. (1 이 그대로)
  - `toneColor` Array<number>: [r, g, b] 색조 색. (sRGB 0 ~ 1, 밝기를 1 로 맞춰 곱한다)
  - `toneAmount` number: 색조를 섞는 양. (0 ~ 1)
  - `hazeColor` Array<number>: [r, g, b] 안개빛 색. (sRGB 0 ~ 1)
  - `hazeAmount` number: 안개빛을 섞는 양. (0 ~ 1, 어두운 곳일수록 세다)

  예제: 해 질 녘처럼 따뜻하고 뿌연 색

  ```js
  import { ToonPostProcess } from "./vanilla.js";
  const postProcess = new ToonPostProcess(document.createElement("canvas").getContext("webgl2"), 640, 360);
  postProcess.setBrightness(0.95);
  postProcess.setColorGrade(0.9, 1.1, [1, 0.75, 0.55], 0.35, [0.35, 0.25, 0.4], 0.2);
  postProcess.setVignette(0.25);
  ```

- `setVignette(vignetteStrength)` (method, since 0.4.0): 가장자리 어둡게 설정. (0 이 없음, 1 이면 구석이 까맣게)
  - `vignetteStrength` number: 가장자리를 어둡게 하는 세기. (0 이 없음, 1 이면 구석이 까맣게)
- `setAmbientOcclusion(isEnabled, intensity = 0.5, radius = 0.5, resolutionScale = 0.5, directLightingStrength = 0)` (method, since 0.4.0): 모서리 어둠(화면 공간 AO) 설정. (기본 꺼짐, 켜면 drawAmbientOcclusion 이 셈하고 몸 셰이더가 바탕빛에 곱한다)
  - 벽과 바닥이 만나는 곳, 물건 밑, 발밑이 엷게 어두워진다. 세기 1 이면 가린 만큼 다 어둡고 0.5 면 그 반이다.
  - 직접 빛 몫은 해가 비추는 곳에서 얼마나 보일지다. (유니티 URP SSAO 의 Direct Lighting Strength, HDRP 의 directLightingStrength)
    0 이면 바탕빛에만 곱하고, 1 이면 해, 채움빛, 점광과 스포트라이트의 확산과 반사광에도 보임을 다 곱한다. 칸(밝기 단계)을 고른 뒤에 곱해 칸 경계 자리는 그대로다.
  - `isEnabled` boolean: 켤지.
  - `intensity` number: 세기 0 ~ 1. (기본 0.5)
  - `radius` number: 가림을 찾는 반지름. (월드 길이, 기본 0.5)
  - `resolutionScale` number: 셈하는 해상도 배율 0.25 ~ 1. (기본 0.5, 흐림과 키우기는 선의 판 해상도)
  - `directLightingStrength` number: 직접 빛에 미치는 몫 0 ~ 1. (기본 0, 바탕빛에만 곱함)

  예제: 바깥선 없는 장면에 모서리 어둠 켜기

  ```js
  import { ToonRenderer, ToonPostProcess, ToonDrawQueue, MeshBuilder, createBoxGeometry, Camera3D, Matrix4, Vector3 } from "./vanilla.js";
  const canvas = Object.assign(document.createElement("canvas"), { width: 320, height: 180 });
  const webGL2RenderingContext = canvas.getContext("webgl2");
  const postProcess = new ToonPostProcess(webGL2RenderingContext, canvas.width, canvas.height, { depthBits: 24 });
  postProcess.setAmbientOcclusion(true, 0.5, 0.5, 0.5, 0.5);
  const renderer = new ToonRenderer(webGL2RenderingContext);
  renderer.setHdrOutput(postProcess.getUseFloatColor());
  const builder = new MeshBuilder();
  builder.addPart(createBoxGeometry(4, 0.2, 4), Matrix4.createTranslation(0, -0.1, 0), "#a0a8b0", { hasOutline: false });
  builder.addPart(createBoxGeometry(0.6, 0.6, 0.6), Matrix4.createTranslation(0, 0.3, 0), "#d08060", { hasOutline: false });
  const mesh = renderer.createMesh(builder.readArrays());
  const camera = new Camera3D();
  camera.setPerspective(0.8, 0.1, 50);
  camera.setAspectRatio(canvas.width / canvas.height);
  camera.lookAt(Vector3.create(2, 2.5, 3), Vector3.create(0, 0, 0), Vector3.create(0, 1, 0));
  const queue = new ToonDrawQueue();
  queue.setPostProcess(postProcess);
  queue.addMesh(mesh, Matrix4.createIdentity());
  postProcess.begin([0.05, 0.05, 0.08]);
  queue.draw(renderer, camera);
  postProcess.end(null, [0, 0, canvas.width, canvas.height]);
  if (postProcess.getAmbientOcclusionTexture() === null || postProcess.getAmbientOcclusionDirectLightingStrength() !== 0.5) {
  	throw new Error("ambient occlusion texture is missing");
  }
  ```

- `getAmbientOcclusion()` (method, since 0.4.0): 모서리 어둠 설정 반환.
  - returns object: { isEnabled, intensity, radius, resolutionScale, directLightingStrength } (새 객체)
- `getAmbientOcclusionDirectLightingStrength()` (method, since 0.4.0): 모서리 어둠이 직접 빛에 미치는 몫 반환. (setAmbientOcclusion 의 다섯째 인자, 그리기 줄이 렌더러에 건다)
  - returns number: 0 ~ 1. (기본 0)
- `isAmbientOcclusionEnabled()` (method, since 0.4.0): 모서리 어둠이 켜졌는지.
  - returns boolean: setAmbientOcclusion 으로 켰으면 true.
- `getAmbientOcclusionPrepass()` (method, since 0.4.0): 바깥선이 없는 장면의 노멀과 깊이 미리 그리기 반환. (선은 긋지 않는 ToonScreenOutline, 처음 부를 때 짓는다)
  - returns ToonScreenOutline: 선의 판만 그리는 화면 바깥선. (beginLineIds, drawMesh, endLineIds 로 그리고 getLineTarget 을 drawAmbientOcclusion 에 준다)
- `drawAmbientOcclusion(lineTarget, viewMatrix, projectionMatrix)` (method, since 0.4.0): 모서리 어둠 셈하기. (선의 판의 노멀과 깊이로 반 해상도 GTAO → 가로 흐림 → 세로 흐림과 키우기, 꺼졌으면 null)
  - 선의 판을 그린 뒤, 몸을 그리기 전에 부른다. 프레임버퍼, 뷰포트, 프로그램, 버텍스 어레이, 고른 유닛은 부르기 전으로 돌린다.
  - 결과 텍스처는 선의 판 크기의 RGBA8 이다. (r 세기를 건 보임, gba 깊이 24 비트) ToonRenderer.setAmbientOcclusionTexture 에 준다.
  - `lineTarget` object: ToonScreenOutline.getLineTarget() 의 결과. ({ lineTexture, depthTexture, width, height })
  - `viewMatrix` Matrix4: 선의 판을 그린 보기 행렬.
  - `projectionMatrix` Matrix4: 선의 판을 그린 투영 행렬. (원근이나 직교)
  - returns WebGLTexture | null: 결과 텍스처. (꺼졌거나 판을 짓지 못했으면 null)

  예제: 렌더러로 바로 그릴 때 선의 판, 모서리 어둠, 몸 차례로

  ```js
  import { ToonRenderer, ToonPostProcess, MeshBuilder, createBoxGeometry, Matrix4, Vector3 } from "./vanilla.js";
  const webGL2RenderingContext = document.createElement("canvas").getContext("webgl2");
  const postProcess = new ToonPostProcess(webGL2RenderingContext, 300, 150, { depthBits: 24 });
  postProcess.setAmbientOcclusion(true);
  const renderer = new ToonRenderer(webGL2RenderingContext);
  const builder = new MeshBuilder();
  builder.addPart(createBoxGeometry(3, 0.2, 3), Matrix4.createIdentity(), "#909090", { hasOutline: false });
  const mesh = renderer.createMesh(builder.readArrays());
  const viewMatrix = Matrix4.createLookAt(Vector3.create(2, 3, 3), Vector3.create(0, 0, 0), Vector3.create(0, 1, 0));
  const projectionMatrix = Matrix4.createOrthographic(-2, 2, -1, 1, 0.1, 20);
  postProcess.begin([0, 0, 0]);
  const prepass = postProcess.getAmbientOcclusionPrepass();
  if (prepass.beginLineIds(viewMatrix, projectionMatrix)) {
  	prepass.drawMesh(mesh, Matrix4.createIdentity(), 1);
  	prepass.endLineIds();
  }
  renderer.setAmbientOcclusionTexture(postProcess.drawAmbientOcclusion(prepass.getLineTarget(), viewMatrix, projectionMatrix));
  renderer.beginFrameWithMatrices(viewMatrix, projectionMatrix);
  renderer.drawMesh(mesh, Matrix4.createIdentity());
  renderer.endFrame();
  renderer.setAmbientOcclusionTexture(null);
  postProcess.end(null, [0, 0, 300, 150]);
  ```

- `getAmbientOcclusionTexture()` (method, since 0.4.0): 모서리 어둠 결과 텍스처 반환. (아직 셈하지 않았거나 꺼졌으면 null)
  - returns WebGLTexture | null: 선의 판 크기의 RGBA8. (r 세기를 건 보임, gba 깊이 24 비트)
- `getSceneRenderTarget()` (method, since 0.4.0): 씬 렌더 타겟 반환. (다른 후처리를 끼울 때)
  - returns RenderTarget: 씬을 그리는 렌더 타겟. (해상도 배율이나 표본 수를 바꾸면 다시 지어질 수 있다)

  예제: 씬 색 텍스처를 다른 후처리에 넘기기

  ```js
  import { ToonPostProcess } from "./vanilla.js";
  const postProcess = new ToonPostProcess(document.createElement("canvas").getContext("webgl2"), 640, 360);
  postProcess.begin([0, 0, 0]);
  const sceneRenderTarget = postProcess.getSceneRenderTarget();
  sceneRenderTarget.resolve();
  const sceneTexture = sceneRenderTarget.getColorTexture(0);
  ```

- `destroy()` (method, since 0.4.0): 지우기.
