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

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

Toon HDR finishing. (outputs linear color drawn to a float render target to the screen with bloom, exposure, tone mapping and gamma)

Example: Draw a toon scene into a float target and output it with bloom and tone mapping

```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

Toon HDR finishing. (outputs linear color drawn to a float render target to the screen with bloom, exposure, tone mapping and gamma)
- Combines RenderTarget (half-float color, depth), BloomEffect (or MultiLevelBloomEffect) and FullscreenPass.
- Usage: after ToonRenderer.setHdrOutput(true), begin(background linear color) → draw with ToonRenderer → end(output framebuffer, viewport)
  end (resolves first if multisampled) computes bloom and draws the tone-mapped color into the output framebuffer (screen if null).
- Constructor options: new ToonPostProcess(gl, width, height, { sampleCount, useFloatColor, depthBits, useDepthTexture }) (without options, same as now: RGBA16F, depth 16, no multisampling)
  If sampleCount is 2 or more, the scene is drawn to a multisampled (MSAA) renderbuffer and resolved to a texture before end. Reduced to a count the device supports. (getSampleCount, setSampleCount)
  depthBits 24 means 24-bit depth. (scenes with a distant far plane) useDepthTexture keeps the scene depth as a texture. (used by setLitArea)
- Color space: linear color is written to the scene render target. (ToonRenderer.setHdrOutput(true), ToonScreenOutline.setHdrOutput(true), ToonVfx colors are also treated as linear)
  Games that wrote gamma-encoded color g to the float target and converted back with g^2.2 in compositing should convert those values to linear beforehand. Colors become c^2.2, and a brightness multiplier k applied on the gamma side becomes linear k^2.2.
  (e.g. 1.37 is linear 2, 1.6 is 2.81, 2.08 is 5, brightness 1.6 with multiplier 1.6 gives (1.6 x 1.6)^2.2 = 7.9) Bloom threshold and knee are linear brightness.
  These examples hold only for a multiplier that was applied on the gamma side (to the gamma-encoded color g). A multiplier that was applied to linear colors, and values that are linear from the start such as the bloom threshold and knee, are passed as they are without conversion.
- Devices that cannot use float targets: even with useFloatColor (default true), if ToonPostProcess.isFloatColorSupported is false, RGBA8 targets are built. (getUseFloatColor is false)
  That case and useFloatColor: false take the LDR path. The scene is drawn in screen color (gamma-encoded color, ToonRenderer.setHdrOutput(false)), and compositing adds bloom without tone mapping and gamma and applies only color grading.
- Canvas antialias: this post process draws into its own MSAA target (sampleCount), so a game that uses it builds with EngineConfiguration.antialias set to false.
  With true, the canvas itself is MSAA, so the pass that copies to the screen and the UI blend per sample and cost more. (Mac mini, 2560x1440 toon post process scene, GPU throughput 6.89 → 6.49 ms, with it off 6.81 → 5.22 ms)
  Example: engineConfiguration.antialias = false;
- Bloom: default is a half-resolution 9-tap Gaussian (BloomEffect, threshold 0.9 ~ 1.6, ping-pong targets RGBA8, RGBA16F with setBloomFloatColor).
  Giving setBloomLevels(level count, threshold, knee) a level count of 1 or more switches to MultiLevelBloomEffect (halves down then scales up with a tent filter while adding, targets at the same precision as the scene). 0 restores the default. Strength is applied to both by setBloom.
- Tone mapping is the ACES approximation (Krzysztof Narkowicz 2016, whose post lets it be used under CC0 or MIT). Exposure (setExposure) is multiplied in before mapping, then sRGB gamma is applied.
  The gamma color space (default) uses pow(1 / 2.2), the linear color space (options.colorSpace or the engine's ColorSpace.linear) uses the sRGB standard curve (IEC 61966-2-1). (The same curve as ToonRenderer's LDR output)
- Color grading: after gamma, applies in order brightness (setBrightness, toward 1 inside the lit area setLitArea), saturation, color tone (multiplies a color normalized to brightness 1), fog light (pulls dark areas toward that color), contrast, edge darkening. (setColorGrade, setVignette)
  Defaults are brightness 1, saturation 1, contrast 1, color tone 0, fog light 0, edge 0, so there is no grading.
- Resolution scale: with setResolutionScale(scale), the scene target is built at output size x scale and scaled up to end's viewport (linear filtering) for output. (to render only 3D at a lower resolution while leaving UI at device pixels, default 1)
- Outputting inside a node rectangle: resize(rectangle width, height) → begin → draw (leave ToonRenderer's screen rectangle cleared) → end(null, [x, drawing buffer height - y - height, width, height]).
- Ambient occlusion (screen-space AO): turn on with setAmbientOcclusion(on, intensity, radius, resolution scale, direct lighting strength). (off by default, intensity 0.5, radius 0.5 world length, half resolution, direct lighting strength 0)
  Computes GTAO (Jimenez 2016) at half resolution, blurs horizontally while preserving edges by tangent plane distance and normals, then blurs vertically while upsampling to full resolution. (the noise is a fixed pattern so a still screen does not shimmer)
  Normals and depth reuse the line target of the screen outline (ToonScreenOutline). Scenes without outlines use getAmbientOcclusionPrepass(), which draws only the line target and no lines.
  With ToonDrawQueue.setPostProcess(this), the queue calls drawAmbientOcclusion after the line target and before bodies and sets the result on the renderer. The body shader multiplies the ambient light (sky and ground light), and by the direct lighting strength also the diffuse and specular of the sun, fill light and point lights. (applied after the band is chosen so band edges stay, with strength 0 only the ambient light)
  The engine's existing AmbientOcclusionEffect resolves depth only from a perspective field of view and near and far planes and takes RGB world normals with coverage alpha in a hemisphere-sample form, so it does not fit orthographic cameras and the line target (octahedral normals) and is built separately.

Example: Draw only the 3D at lower resolution and apply color grading

```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): Constructor. (screen pixel size, options { sampleCount = 0, useFloatColor = true, depthBits = 16, useDepthTexture = false })
  - `webGL2RenderingContext` WebGL2RenderingContext: The same context as the toon renderer.
  - `width` number: Output width. (Pixels)
  - `height` number: Output height. (Pixels)
  - `options` object | null: { sampleCount (default 0), useFloatColor (default true), depthBits (16 or 24), useDepthTexture (default false), colorSpace (ColorSpace, default is the engine's color space, the same value as ToonRenderer) }
- `static isFloatColorSupported(webGL2RenderingContext)` (static, since 0.4.0): Whether a float color buffer can be rendered to. (EXT_color_buffer_float or EXT_color_buffer_half_float is present, and a framebuffer with a 1 x 1 RGBA16F attached is complete)
  - `webGL2RenderingContext` WebGL2RenderingContext: Context to check.
  - returns boolean: true if it can draw into an RGBA16F target.

  Example: Choose the HDR path or LDR path to suit the device

  ```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): Builds the scene render target. (output size x resolution scale, with the current options)
  - returns RenderTarget: The newly built scene render target.
- `readSceneWidth()` (method, since 0.4.0): Width of the scene buffer. (output width x resolution scale, 1 or more)
  - returns number: Width of the scene target. (Pixels)
- `readSceneHeight()` (method, since 0.4.0): Height of the scene buffer. (output height x resolution scale, 1 or more)
  - returns number: Height of the scene target. (Pixels)
- `resize(width, height)` (method, since 0.4.0): Resizes. (output size, the scene buffer is multiplied by the resolution scale, unchanged if the same)
  - `width` number: Output width. (Pixels)
  - `height` number: Output height. (Pixels)

  Example: Follow when the canvas size changes

  ```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): Sets the resolution scale. (scene buffer = output size x scale, 0.05 ~ 4, default 1)
  - `resolutionScale` number: Scale of the scene target. (0.05 ~ 4)

  Example: Only the 3D at half resolution on phones

  ```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 the resolution scale.
  - returns number: Scale of the scene target.
- `setSampleCount(sampleCount)` (method, since 0.4.0): Sets the multisample sample count. (none if below 2, rebuilds the scene buffer when changed)
  - `sampleCount` number: Multisample count. (No multisampling below 2)

  Example: Turn on anti-aliasing in the settings and read the actual sample count

  ```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): Returns the multisample sample count actually in use. (0 means none)
  - returns number: Sample count the scene target actually uses. (Reduced to what the device accepts, 0 means none)
- `getUseFloatColor()` (method, since 0.4.0): Returns whether the scene buffer is float. (false means the LDR path)
  - returns boolean: true if the scene target is float. (Passed as is to ToonRenderer.setHdrOutput)
- `getColorSpace()` (method, since 0.4.0): Returns the color space. (Set at construction, chooses the curve that outputs screen color after tone mapping)
  - returns string: ColorSpace.gamma or ColorSpace.linear.

  Example: Post process built with the same color space as the renderer

  ```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): Begins drawing the scene. (binds the scene render target and clears it with the background color and depth, linear color on the HDR path, screen color on the LDR path)
  - `clearColor` Array<number>: [r, g, b] background color. (Linear color on the HDR path, screen color on the LDR path)
- `end(outputFramebuffer, viewport)` (method, since 0.4.0): Finishes. (resolve if multisampled → bloom → tone map into the output framebuffer, viewport is [x, y, width, height])
  - `outputFramebuffer` WebGLFramebuffer | null: Framebuffer to output to. (Screen if null)
  - `viewport` Array<number>: [x, y, width, height] output area. (Drawing buffer pixels, bottom left is the origin)

  Example: Output inside a rectangle with a top left origin

  ```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): Sets the exposure. (multiplied before tone mapping, 1 is the default)
  - `exposure` number: Exposure multiplier. (0 or more, 1 is the default)
- `setBloom(isBloomEnabled, bloomStrength, thresholdStart, thresholdEnd)` (method, since 0.4.0): Sets the bloom. (enabled, intensity, start and end of the threshold that extracts bright areas, the threshold is used only by the default 9-tap bloom)
  - `isBloomEnabled` boolean: Whether to turn on bloom.
  - `bloomStrength` number: Bloom strength. (Multiplier added to the scene color, default 0.6)
  - `thresholdStart` number: Linear brightness where bright areas start to be extracted. (Default 0.9)
  - `thresholdEnd` number: Linear brightness where they are fully extracted. (Default 1.6)

  Example: Make only glowing things spread softly

  ```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): Sets the number of bloom levels. (0 means the default 9-tap bloom, 1 or more means a multi-level bloom with that many levels, threshold and knee are the linear brightness of the multi-level bloom)
  - The multi-level bloom buffers have the same precision as the scene buffer. (RGBA16F on the HDR path)
  - `levelCount` number: Number of levels. (0 returns to the default 9-tap bloom)
  - `threshold` number: Threshold of the multi-level bloom. (Linear brightness)
  - `knee` number: Width for passing the threshold softly. (Linear brightness)

  Example: Switch to a wide multi-level bloom and switch back

  ```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): Returns the number of bloom levels. (0 means the default 9-tap bloom)
  - returns number: Number of levels of the multi-level bloom. (0 means the default 9-tap bloom)
- `setBloomFloatColor(isFloatColor)` (method, since 0.4.0): Makes the ping-pong buffers of the default 9-tap bloom float. (true means RGBA16F, the default false means RGBA8, ignored if the scene buffer is not float)
  - `isFloatColor` boolean: true means RGBA16F, false means RGBA8.
- `setBrightness(brightness)` (method, since 0.4.0): Sets the brightness. (multiplied at the very start of color grading, 1 leaves it unchanged)
  - `brightness` number: Brightness multiplier. (0 or more, 1 leaves it as is)
- `setLitArea(center, innerRadius, outerRadius, inverseViewProjectionMatrix)` (method, since 0.4.0): Sets the lit spot. (within horizontal distance innerRadius of that spot the brightness is 1, beyond outerRadius it is the setBrightness brightness, smooth in between)
  - Reconstructs the world position of each pixel from the scene depth texture (option useDepthTexture) and the inverse of that frame's view and projection matrices. Ignored if there is no depth texture.
  - Give it again every frame when the camera moves. The background where nothing was drawn is computed as a position on the far plane.
  - `center` Array<number>: [x, y, z]
  - `innerRadius` number: Horizontal radius with brightness 1. (World length)
  - `outerRadius` number: Horizontal radius beyond which the brightness of setBrightness applies. (World length)
  - `inverseViewProjectionMatrix` Matrix4: Inverse of this frame's view and projection.

  Example: Light only the area around a flashlight in a dark scene

  ```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): Clears the lit spot.
- `setColorGrade(saturation, contrast, toneColor, toneAmount, hazeColor, hazeAmount)` (method, since 0.4.0): Sets the color grading. (saturation and contrast leave it unchanged at 1, tint and fog color are sRGB [r, g, b] 0 ~ 1 with a mix amount 0 ~ 1)
  - The tint color is normalized to luminance (Rec. 709) 1 before multiplying, so brightness stays the same and only the hue is tinted.
  - The fog color lifts darker areas more toward that color. (amount x (1 - luminance))
  - `saturation` number: Saturation. (1 leaves it as is, 0 is grayscale)
  - `contrast` number: Contrast. (1 leaves it as is)
  - `toneColor` Array<number>: [r, g, b] tint color. (sRGB 0 ~ 1, multiplied after normalizing its brightness to 1)
  - `toneAmount` number: Amount of tint to mix. (0 ~ 1)
  - `hazeColor` Array<number>: [r, g, b] haze color. (sRGB 0 ~ 1)
  - `hazeAmount` number: Amount of haze to mix. (0 ~ 1, stronger in darker areas)

  Example: Warm, hazy color like dusk

  ```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): Sets the vignette. (0 is none, 1 makes the corners black)
  - `vignetteStrength` number: Strength of darkening the edges. (0 is none, 1 makes the corners black)
- `setAmbientOcclusion(isEnabled, intensity = 0.5, radius = 0.5, resolutionScale = 0.5, directLightingStrength = 0)` (method, since 0.4.0): Sets ambient occlusion (screen-space AO). (off by default, when on drawAmbientOcclusion computes it and the body shader multiplies the ambient light)
  - Where walls meet the floor, under objects and under feet get faintly darker. Intensity 1 darkens by the full occlusion and 0.5 by half of it.
  - The direct lighting strength is how visible it is where the sun shines. (Direct Lighting Strength in Unity URP SSAO, directLightingStrength in HDRP)
    0 multiplies only the ambient light, 1 multiplies the full visibility into the diffuse and specular of the sun, fill light, point lights and spotlights too. It is applied after the band (brightness step) is chosen, so band edges stay where they are.
  - `isEnabled` boolean: Whether to enable it.
  - `intensity` number: Intensity 0 ~ 1. (default 0.5)
  - `radius` number: Radius to search for occluders. (world length, default 0.5)
  - `resolutionScale` number: Resolution scale of the computation 0.25 ~ 1. (default 0.5, blur and upsampling are at the line target resolution)
  - `directLightingStrength` number: How much it affects direct lighting, 0 to 1. (default 0, multiplies only the ambient light)

  Example: Turning on ambient occlusion in a scene without outlines

  ```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 the ambient occlusion settings.
  - returns object: { isEnabled, intensity, radius, resolutionScale, directLightingStrength } (a new object)
- `getAmbientOcclusionDirectLightingStrength()` (method, since 0.4.0): Returns how much ambient occlusion affects direct lighting. (the fifth argument of setAmbientOcclusion, the draw queue sets it on the renderer)
  - returns number: 0 to 1. (default 0)
- `isAmbientOcclusionEnabled()` (method, since 0.4.0): Whether ambient occlusion is on.
  - returns boolean: true if turned on with setAmbientOcclusion.
- `getAmbientOcclusionPrepass()` (method, since 0.4.0): Returns the normal and depth prepass for scenes without outlines. (a ToonScreenOutline that draws no lines, built on the first call)
  - returns ToonScreenOutline: A screen outline that only draws the line target. (draw with beginLineIds, drawMesh, endLineIds and pass getLineTarget to drawAmbientOcclusion)
- `drawAmbientOcclusion(lineTarget, viewMatrix, projectionMatrix)` (method, since 0.4.0): Computes ambient occlusion. (half-resolution GTAO from the line target normals and depth → horizontal blur → vertical blur and upsampling, null if off)
  - Call after drawing the line target and before drawing bodies. Framebuffer, viewport, program, vertex array and active unit are restored to what they were before the call.
  - The result texture is RGBA8 the size of the line target. (r visibility with intensity applied, gba 24-bit depth) Pass it to ToonRenderer.setAmbientOcclusionTexture.
  - `lineTarget` object: The result of ToonScreenOutline.getLineTarget(). ({ lineTexture, depthTexture, width, height })
  - `viewMatrix` Matrix4: The view matrix the line target was drawn with.
  - `projectionMatrix` Matrix4: The projection matrix the line target was drawn with. (perspective or orthographic)
  - returns WebGLTexture | null: The result texture. (null if off or the targets could not be built)

  Example: Line target, ambient occlusion and bodies in order when drawing directly with the renderer

  ```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): Returns the ambient occlusion result texture. (null if not computed yet or off)
  - returns WebGLTexture | null: RGBA8 the size of the line target. (r visibility with intensity applied, gba 24-bit depth)
- `getSceneRenderTarget()` (method, since 0.4.0): Returns the scene render target. (for inserting other post-processing)
  - returns RenderTarget: Render target the scene is drawn into. (May be rebuilt if the resolution scale or sample count changes)

  Example: Pass the scene color texture to another post process

  ```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): Disposes.
