graphics3d/toon/toonpostprocess
툰 HDR 마무리. (실수 렌더 타겟에 그린 선형 색을 블룸, 노출, 톤매핑, 감마로 화면에 낸다)
Toon HDR finishing. (outputs linear color drawn to a float render target to the screen with bloom, exposure, tone mapping and gamma)
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 월드 노멀과 커버리지 알파를 받는 반구 표본 꼴이라 직교 카메라와 선의 판(팔면체 노멀)에 맞지 않아 따로 짓는다.
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.
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());생성. (화면 픽셀 크기, 옵션 { sampleCount = 0, useFloatColor = true, depthBits = 16, useDepthTexture = false })
Constructor. (screen pixel size, options { sampleCount = 0, useFloatColor = true, depthBits = 16, useDepthTexture = false })
- webGL2RenderingContextWebGL2RenderingContext
- 툰 렌더러와 같은 컨텍스트.The same context as the toon renderer.
- widthnumber
- 출력 너비. (픽셀)Output width. (Pixels)
- heightnumber
- 출력 높이. (픽셀)Output height. (Pixels)
- optionsobject | null
- { sampleCount (기본 0), useFloatColor (기본 true), depthBits (16 이나 24), useDepthTexture (기본 false), colorSpace (ColorSpace, 기본은 엔진의 색 공간, ToonRenderer 와 같은 값) }{ 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) }
짝Counterpart: vanilla-engine ToonPostProcess.new
실수 컬러 판을 그릴 수 있는지. (EXT_color_buffer_float 나 EXT_color_buffer_half_float 가 있고, 1 x 1 RGBA16F 를 붙인 프레임버퍼가 완성되는지)
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)
- webGL2RenderingContextWebGL2RenderingContext
- 알아볼 컨텍스트.Context to check.
반환Returnsboolean RGBA16F 판에 그릴 수 있으면 true.true if it can draw into an RGBA16F target.
짝Counterpart: vanilla-engine ToonPostProcess.is_float_color_supported
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);씬 렌더 타겟 짓기. (출력 크기 x 해상도 배율, 지금 옵션으로)
Builds the scene render target. (output size x resolution scale, with the current options)
반환ReturnsRenderTarget 새로 지은 씬 렌더 타겟.The newly built scene render target.
씬 판의 너비. (출력 너비 x 해상도 배율, 1 이상)
Width of the scene buffer. (output width x resolution scale, 1 or more)
반환Returnsnumber 씬 판의 너비. (픽셀)Width of the scene target. (Pixels)
씬 판의 높이. (출력 높이 x 해상도 배율, 1 이상)
Height of the scene buffer. (output height x resolution scale, 1 or more)
반환Returnsnumber 씬 판의 높이. (픽셀)Height of the scene target. (Pixels)
크기 바꾸기. (출력 크기, 씬 판은 해상도 배율을 곱함, 같으면 그대로)
Resizes. (output size, the scene buffer is multiplied by the resolution scale, unchanged if the same)
- widthnumber
- 출력 너비. (픽셀)Output width. (Pixels)
- heightnumber
- 출력 높이. (픽셀)Output height. (Pixels)
짝Counterpart: vanilla-engine ToonPostProcess.resize
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);해상도 배율 설정. (씬 판 = 출력 크기 x 배율, 0.05 ~ 4, 기본 1)
Sets the resolution scale. (scene buffer = output size x scale, 0.05 ~ 4, default 1)
- resolutionScalenumber
- 씬 판의 배율. (0.05 ~ 4)Scale of the scene target. (0.05 ~ 4)
짝Counterpart: vanilla-engine ToonPostProcess.set_resolution_scale
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();해상도 배율 반환.
Returns the resolution scale.
반환Returnsnumber 씬 판의 배율.Scale of the scene target.
짝Counterpart: vanilla-engine ToonPostProcess.get_resolution_scale
멀티샘플 표본 수 설정. (2 밑이면 없음, 바뀌면 씬 판을 다시 짓는다)
Sets the multisample sample count. (none if below 2, rebuilds the scene buffer when changed)
- sampleCountnumber
- 멀티샘플 표본 수. (2 밑이면 멀티샘플 없음)Multisample count. (No multisampling below 2)
짝Counterpart: vanilla-engine ToonPostProcess.set_sample_count
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;실제로 쓰는 멀티샘플 표본 수 반환. (0 이면 없음)
Returns the multisample sample count actually in use. (0 means none)
반환Returnsnumber 씬 판이 실제로 쓰는 표본 수. (기기가 받는 수로 줄인 것, 0 이면 없음)Sample count the scene target actually uses. (Reduced to what the device accepts, 0 means none)
짝Counterpart: vanilla-engine ToonPostProcess.get_sample_count
씬 판이 실수인지 반환. (false 면 LDR 길)
Returns whether the scene buffer is float. (false means the LDR path)
반환Returnsboolean 씬 판이 실수면 true. (ToonRenderer.setHdrOutput 에 그대로 넘긴다)true if the scene target is float. (Passed as is to ToonRenderer.setHdrOutput)
짝Counterpart: vanilla-engine ToonPostProcess.get_use_float_color
색 공간 반환. (생성 때 정한 값, 톤매핑 뒤 화면 색을 내는 곡선을 가른다)
Returns the color space. (Set at construction, chooses the curve that outputs screen color after tone mapping)
반환Returnsstring ColorSpace.gamma 나 ColorSpace.linear.ColorSpace.gamma or ColorSpace.linear.
짝Counterpart: vanilla-engine ToonPostProcess.get_color_space
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");
}씬 그리기 시작. (씬 렌더 타겟을 묶고 바탕 색과 깊이로 비운다, HDR 길은 선형 색, LDR 길은 화면 색)
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)
- clearColorArray<number>
- [r, g, b] 바탕 색. (HDR 길은 선형 색, LDR 길은 화면 색)[r, g, b] background color. (Linear color on the HDR path, screen color on the LDR path)
짝Counterpart: vanilla-engine ToonPostProcess.begin
마무리. (멀티샘플이면 풂 → 블룸 → 톤매핑해 낼 프레임버퍼에, viewport 는 [x, y, 너비, 높이])
Finishes. (resolve if multisampled → bloom → tone map into the output framebuffer, viewport is [x, y, width, height])
- outputFramebufferWebGLFramebuffer | null
- 낼 프레임버퍼. (null 이면 화면)Framebuffer to output to. (Screen if null)
- viewportArray<number>
- [x, y, 너비, 높이] 낼 자리. (드로잉 버퍼 픽셀, 왼쪽 아래가 원점)[x, y, width, height] output area. (Drawing buffer pixels, bottom left is the origin)
짝Counterpart: vanilla-engine ToonPostProcess.end
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]);노출 설정. (톤매핑 전에 곱한다, 1 이 기본)
Sets the exposure. (multiplied before tone mapping, 1 is the default)
- exposurenumber
- 노출 배. (0 이상, 1 이 기본)Exposure multiplier. (0 or more, 1 is the default)
짝Counterpart: vanilla-engine ToonPostProcess.set_exposure
블룸 설정. (켜기, 세기, 밝은 곳을 뽑는 문턱의 시작과 끝, 문턱은 기본 9 탭 블룸에만 쓴다)
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)
- isBloomEnabledboolean
- 블룸을 켤지.Whether to turn on bloom.
- bloomStrengthnumber
- 블룸 세기. (씬 색에 더하는 배, 기본 0.6)Bloom strength. (Multiplier added to the scene color, default 0.6)
- thresholdStartnumber
- 밝은 곳을 뽑기 시작하는 선형 밝기. (기본 0.9)Linear brightness where bright areas start to be extracted. (Default 0.9)
- thresholdEndnumber
- 다 뽑는 선형 밝기. (기본 1.6)Linear brightness where they are fully extracted. (Default 1.6)
짝Counterpart: vanilla-engine ToonPostProcess.set_bloom
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);블룸 단 수 설정. (0 이면 기본 9 탭 블룸, 1 이상이면 그 단 수의 다단 블룸, 문턱과 무릎은 다단 블룸의 선형 밝기)
- 다단 블룸 판은 씬 판과 같은 정밀도다. (HDR 길은 RGBA16F)
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)
- levelCountnumber
- 단 수. (0 이면 기본 9 탭 블룸으로 돌린다)Number of levels. (0 returns to the default 9-tap bloom)
- thresholdnumber
- 다단 블룸의 문턱. (선형 밝기)Threshold of the multi-level bloom. (Linear brightness)
- kneenumber
- 문턱 둘레를 부드럽게 넘기는 폭. (선형 밝기)Width for passing the threshold softly. (Linear brightness)
짝Counterpart: vanilla-engine ToonPostProcess.set_bloom_levels
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);블룸 단 수 반환. (0 이면 기본 9 탭 블룸)
Returns the number of bloom levels. (0 means the default 9-tap bloom)
반환Returnsnumber 다단 블룸의 단 수. (0 이면 기본 9 탭 블룸)Number of levels of the multi-level bloom. (0 means the default 9-tap bloom)
짝Counterpart: vanilla-engine ToonPostProcess.get_bloom_level_count
기본 9 탭 블룸의 주고받는 판을 실수로. (true 면 RGBA16F, 기본 false 는 RGBA8, 씬 판이 실수가 아니면 무시)
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)
- isFloatColorboolean
- true 면 RGBA16F, false 면 RGBA8.true means RGBA16F, false means RGBA8.
짝Counterpart: vanilla-engine ToonPostProcess.set_bloom_float_color
밝기 설정. (색 보정 맨 앞에서 곱한다, 1 이 그대로)
Sets the brightness. (multiplied at the very start of color grading, 1 leaves it unchanged)
- brightnessnumber
- 밝기 배. (0 이상, 1 이 그대로)Brightness multiplier. (0 or more, 1 leaves it as is)
짝Counterpart: vanilla-engine ToonPostProcess.set_brightness
밝힌 자리 설정. (그 자리에서 수평 거리 innerRadius 안은 밝기 1, outerRadius 밖은 setBrightness 의 밝기, 사이는 부드럽게)
- 씬 깊이 텍스처(옵션 useDepthTexture)와 그 프레임의 보기와 투영의 역행렬로 화소마다 월드 자리를 되짚는다. 깊이 텍스처가 없으면 무시한다.
- 카메라가 움직이면 프레임마다 다시 준다. 아무것도 그리지 않은 바탕은 먼 면의 자리로 셈한다.
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.
- centerArray<number>
- [x, y, z]
- innerRadiusnumber
- 밝기 1 인 수평 반지름. (월드 길이)Horizontal radius with brightness 1. (World length)
- outerRadiusnumber
- 이 밖은 setBrightness 의 밝기인 수평 반지름. (월드 길이)Horizontal radius beyond which the brightness of setBrightness applies. (World length)
- inverseViewProjectionMatrixMatrix4
- 이번 프레임 보기와 투영의 역행렬.Inverse of this frame's view and projection.
짝Counterpart: vanilla-engine ToonPostProcess.set_lit_area
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());밝힌 자리 풀기.
Clears the lit spot.
짝Counterpart: vanilla-engine ToonPostProcess.clear_lit_area
색 보정 설정. (채도와 대비는 1 이 그대로, 색조와 안개빛은 sRGB [r, g, b] 0 ~ 1 과 섞는 양 0 ~ 1)
- 색조 색은 밝기(Rec. 709)를 1 로 맞춰 곱하므로 밝기는 그대로 두고 빛깔만 물든다.
- 안개빛은 어두운 곳일수록 그 색 쪽으로 끌어올린다. (양 x (1 - 밝기))
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))
- saturationnumber
- 채도. (1 이 그대로, 0 이면 흑백)Saturation. (1 leaves it as is, 0 is grayscale)
- contrastnumber
- 대비. (1 이 그대로)Contrast. (1 leaves it as is)
- toneColorArray<number>
- [r, g, b] 색조 색. (sRGB 0 ~ 1, 밝기를 1 로 맞춰 곱한다)[r, g, b] tint color. (sRGB 0 ~ 1, multiplied after normalizing its brightness to 1)
- toneAmountnumber
- 색조를 섞는 양. (0 ~ 1)Amount of tint to mix. (0 ~ 1)
- hazeColorArray<number>
- [r, g, b] 안개빛 색. (sRGB 0 ~ 1)[r, g, b] haze color. (sRGB 0 ~ 1)
- hazeAmountnumber
- 안개빛을 섞는 양. (0 ~ 1, 어두운 곳일수록 세다)Amount of haze to mix. (0 ~ 1, stronger in darker areas)
짝Counterpart: vanilla-engine ToonPostProcess.set_color_grade
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);가장자리 어둡게 설정. (0 이 없음, 1 이면 구석이 까맣게)
Sets the vignette. (0 is none, 1 makes the corners black)
- vignetteStrengthnumber
- 가장자리를 어둡게 하는 세기. (0 이 없음, 1 이면 구석이 까맣게)Strength of darkening the edges. (0 is none, 1 makes the corners black)
짝Counterpart: vanilla-engine ToonPostProcess.set_vignette
setAmbientOcclusion(isEnabled, intensity = 0.5, radius = 0.5, resolutionScale = 0.5, directLightingStrength = 0)#모서리 어둠(화면 공간 AO) 설정. (기본 꺼짐, 켜면 drawAmbientOcclusion 이 셈하고 몸 셰이더가 바탕빛에 곱한다)
- 벽과 바닥이 만나는 곳, 물건 밑, 발밑이 엷게 어두워진다. 세기 1 이면 가린 만큼 다 어둡고 0.5 면 그 반이다.
- 직접 빛 몫은 해가 비추는 곳에서 얼마나 보일지다. (유니티 URP SSAO 의 Direct Lighting Strength, HDRP 의 directLightingStrength) 0 이면 바탕빛에만 곱하고, 1 이면 해, 채움빛, 점광과 스포트라이트의 확산과 반사광에도 보임을 다 곱한다. 칸(밝기 단계)을 고른 뒤에 곱해 칸 경계 자리는 그대로다.
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.
- isEnabledboolean
- 켤지.Whether to enable it.
- intensitynumber
- 세기 0 ~ 1. (기본 0.5)Intensity 0 ~ 1. (default 0.5)
- radiusnumber
- 가림을 찾는 반지름. (월드 길이, 기본 0.5)Radius to search for occluders. (world length, default 0.5)
- resolutionScalenumber
- 셈하는 해상도 배율 0.25 ~ 1. (기본 0.5, 흐림과 키우기는 선의 판 해상도)Resolution scale of the computation 0.25 ~ 1. (default 0.5, blur and upsampling are at the line target resolution)
- directLightingStrengthnumber
- 직접 빛에 미치는 몫 0 ~ 1. (기본 0, 바탕빛에만 곱함)How much it affects direct lighting, 0 to 1. (default 0, multiplies only the ambient light)
짝Counterpart: vanilla-engine ToonPostProcess.set_ambient_occlusion
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");
}모서리 어둠 설정 반환.
Returns the ambient occlusion settings.
반환Returnsobject { isEnabled, intensity, radius, resolutionScale, directLightingStrength } (새 객체){ isEnabled, intensity, radius, resolutionScale, directLightingStrength } (a new object)
짝Counterpart: vanilla-engine ToonPostProcess.get_ambient_occlusion
모서리 어둠이 직접 빛에 미치는 몫 반환. (setAmbientOcclusion 의 다섯째 인자, 그리기 줄이 렌더러에 건다)
Returns how much ambient occlusion affects direct lighting. (the fifth argument of setAmbientOcclusion, the draw queue sets it on the renderer)
반환Returnsnumber 0 ~ 1. (기본 0)0 to 1. (default 0)
짝Counterpart: vanilla-engine ToonPostProcess.get_ambient_occlusion_direct_lighting_strength
모서리 어둠이 켜졌는지.
Whether ambient occlusion is on.
반환Returnsboolean setAmbientOcclusion 으로 켰으면 true.true if turned on with setAmbientOcclusion.
짝Counterpart: vanilla-engine ToonPostProcess.is_ambient_occlusion_enabled
바깥선이 없는 장면의 노멀과 깊이 미리 그리기 반환. (선은 긋지 않는 ToonScreenOutline, 처음 부를 때 짓는다)
Returns the normal and depth prepass for scenes without outlines. (a ToonScreenOutline that draws no lines, built on the first call)
반환ReturnsToonScreenOutline 선의 판만 그리는 화면 바깥선. (beginLineIds, drawMesh, endLineIds 로 그리고 getLineTarget 을 drawAmbientOcclusion 에 준다)A screen outline that only draws the line target. (draw with beginLineIds, drawMesh, endLineIds and pass getLineTarget to drawAmbientOcclusion)
짝Counterpart: vanilla-engine ToonPostProcess.get_ambient_occlusion_prepass
모서리 어둠 셈하기. (선의 판의 노멀과 깊이로 반 해상도 GTAO → 가로 흐림 → 세로 흐림과 키우기, 꺼졌으면 null)
- 선의 판을 그린 뒤, 몸을 그리기 전에 부른다. 프레임버퍼, 뷰포트, 프로그램, 버텍스 어레이, 고른 유닛은 부르기 전으로 돌린다.
- 결과 텍스처는 선의 판 크기의 RGBA8 이다. (r 세기를 건 보임, gba 깊이 24 비트) ToonRenderer.setAmbientOcclusionTexture 에 준다.
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.
- lineTargetobject
- ToonScreenOutline.getLineTarget() 의 결과. ({ lineTexture, depthTexture, width, height })The result of ToonScreenOutline.getLineTarget(). ({ lineTexture, depthTexture, width, height })
- viewMatrixMatrix4
- 선의 판을 그린 보기 행렬.The view matrix the line target was drawn with.
- projectionMatrixMatrix4
- 선의 판을 그린 투영 행렬. (원근이나 직교)The projection matrix the line target was drawn with. (perspective or orthographic)
반환ReturnsWebGLTexture | null 결과 텍스처. (꺼졌거나 판을 짓지 못했으면 null)The result texture. (null if off or the targets could not be built)
짝Counterpart: vanilla-engine ToonPostProcess.draw_ambient_occlusion
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]);모서리 어둠 결과 텍스처 반환. (아직 셈하지 않았거나 꺼졌으면 null)
Returns the ambient occlusion result texture. (null if not computed yet or off)
반환ReturnsWebGLTexture | null 선의 판 크기의 RGBA8. (r 세기를 건 보임, gba 깊이 24 비트)RGBA8 the size of the line target. (r visibility with intensity applied, gba 24-bit depth)
짝Counterpart: vanilla-engine ToonPostProcess.get_ambient_occlusion_texture
씬 렌더 타겟 반환. (다른 후처리를 끼울 때)
Returns the scene render target. (for inserting other post-processing)
반환ReturnsRenderTarget 씬을 그리는 렌더 타겟. (해상도 배율이나 표본 수를 바꾸면 다시 지어질 수 있다)Render target the scene is drawn into. (May be rebuilt if the resolution scale or sample count changes)
짝Counterpart: vanilla-engine ToonPostProcess.get_scene_render_target
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);