graphics3d/toon/toondrawqueue
툰 그리기 줄. (한 프레임에 그릴 모형을 담아 두었다가 ToonRenderer 로 차례를 맞춰 그린다)
Toon draw queue. (holds the models to draw in a frame, then draws them in order with ToonRenderer)
import { ToonRenderer, ToonDrawQueue, ToonScreenOutline, MeshBuilder, createSphereGeometry, ShadowMap, Camera3D, Matrix4, Vector3 } from "./vanilla.js";
const webGL2RenderingContext = document.createElement("canvas").getContext("webgl2");
const renderer = new ToonRenderer(webGL2RenderingContext);
const builder = new MeshBuilder();
builder.addPart(createSphereGeometry(0.5, 32, 20), Matrix4.createIdentity(), "#f0e8e0", { hasOutline: false });
const ballMesh = renderer.createMesh(builder.readArrays());
const shadowMap = new ShadowMap(webGL2RenderingContext, 1024);
shadowMap.updateLightMatrix(Vector3.create(0, 0, 0), Vector3.create(-0.4, -1, -0.3), 5, 0.5, 30);
renderer.setShadow(shadowMap, 1);
const camera = new Camera3D();
camera.setPerspective(0.8, 0.1, 100);
camera.lookAt(Vector3.create(0, 2, 5), Vector3.create(0, 0.5, 0), Vector3.create(0, 1, 0));
const queue = new ToonDrawQueue();
queue.setScreenOutline(new ToonScreenOutline(webGL2RenderingContext));
queue.addMesh(ballMesh, Matrix4.createTranslation(0, 0.5, 0), { lineId: 1 });
queue.addMesh(ballMesh, Matrix4.createTranslation(1.2, 0.5, 0), { lineId: 2, alpha: 0.5 });
queue.drawShadows(renderer, shadowMap);
queue.draw(renderer, camera);ToonDrawItem
남겨 두는 그리기 항목. (모형, 모형 행렬, 꼴을 쥐고 꼴을 푼 것을 기억한다, 프레임마다 ToonDrawQueue.addItem 으로 담는다)
- 유니티 MeshRenderer, 언리얼 프리미티브 컴포넌트 꼴이다. 한 번 짓고 쥐어 두면 그리기 줄이 꼴 객체를 프레임마다 견주거나 풀지 않는다. 부품이 많은 모형은 부품마다 하나씩 짓는다. (재질 범위의 indexStart, indexCount 를 꼴에)
- 꼴은 넘긴 객체를 그대로 쥔다. (복사하지 않는다) 꼴을 고치면 바뀜 표시가 있어야 다시 푼다: setOption(이름, 값) 이나 setOptions(새 꼴) 은 스스로 표시한다. 꼴 객체의 값(틴트 배열의 수까지)을 그 자리에서 고쳤으면 markDirty() 를 부른다.
- 모형 행렬은 복사해 쥔다. 바꾸면 setModelMatrix 로 넘긴다. (그 자리에서 고친 행렬도 다시 넘긴다, 쥔 행렬을 고치지 않는다) 바뀐 것(모형, 행렬, 꼴)이 없는 항목은 그림자 캐시(ShadowUpdateMode.onChange)도 견주지 않는다. (뼈대 행렬이 있으면 견준다)
- addMesh 와 화면이 같다. 꼴은 addMesh 의 꼴과 같다. (ToonRenderer.drawMesh 의 꼴과 castsShadow, group, isDepthPrepassed, lineId, hasScreenOutline, hasCreaseLine)
A retained draw item. (Holds the mesh, model matrix and options and remembers the resolved options; add it with ToonDrawQueue.addItem every frame)
- Same shape as Unity's MeshRenderer and Unreal's primitive component. Once built and held, the draw queue does not compare or resolve the options object every frame. Build one per part for models with many parts. (indexStart, indexCount of the material range in the options)
- The options object is held as given. (Not copied) After changing options, the item needs a dirty mark to resolve again: setOption(name, value) and setOptions(newOptions) mark it themselves. Call markDirty() after changing values of the options object in place (including numbers of a tint array).
- The model matrix is copied. Pass changes with setModelMatrix. (Pass a matrix changed in place again, do not change the held matrix) Items with no change (mesh, matrix, options) are not compared by the shadow cache (ShadowUpdateMode.onChange) either. (Compared when there are joint matrices)
- Draws the same image as addMesh. The options are the same as addMesh's. (ToonRenderer.drawMesh options plus castsShadow, group, isDepthPrepassed, lineId, hasScreenOutline, hasCreaseLine)
import { ToonDrawItem, Matrix4 } from "./vanilla.js";
const options = { tintColor: [1, 1, 1, 1], lineId: 7 };
const drawItem = new ToonDrawItem(null, Matrix4.createIdentity(), options);
drawItem.setOption("emissiveIntensity", 0.5);
options.tintColor[0] = 0.5;
drawItem.markDirty();생성.
Constructor.
- meshobject | null
- ToonRenderer.createMesh 의 결과.Result of ToonRenderer.createMesh.
- modelMatrixMatrix4
- 모형 행렬. (복사한다)Model matrix. (Copied)
- optionsobject
- ToonDrawQueue.addMesh 와 같은 꼴.Options, same as ToonDrawQueue.addMesh.
모형 바꾸기. (꼴은 그대로)
Changes the mesh. (Options unchanged)
- meshobject | null
- ToonRenderer.createMesh 의 결과.Result of ToonRenderer.createMesh.
import { ToonDrawItem, Matrix4 } from "./vanilla.js";
const drawItem = new ToonDrawItem(null, Matrix4.createIdentity(), {});
drawItem.setMesh(null);모형 행렬 반환. (쥔 것, 읽기만 한다, 바꾸려면 setModelMatrix)
Returns the model matrix. (The held one, read only, use setModelMatrix to change it)
반환ReturnsMatrix4 모형 행렬.Model matrix.
모형 행렬 바꾸기. (값을 복사해 쥔다, 같은 값이면 바뀐 것으로 치지 않는다)
Changes the model matrix. (Copies the values, the same values do not count as a change)
- modelMatrixMatrix4
- 모형 행렬. (복사한다)Model matrix. (Copied)
import { ToonDrawItem, Matrix4 } from "./vanilla.js";
const drawItem = new ToonDrawItem(null, Matrix4.createIdentity(), {});
drawItem.setModelMatrix(Matrix4.createTranslation(1, 0, 0));꼴 반환. (쥔 객체, 그 자리에서 고쳤으면 markDirty)
Returns the options. (The held object, call markDirty after changing it in place)
반환Returnsobject 그리기 꼴.Draw options.
꼴 바꾸기. (새 꼴 객체를 쥐고 바뀜 표시)
Changes the options. (Holds the new options object and marks dirty)
- optionsobject
- ToonDrawQueue.addMesh 와 같은 꼴.Options, same as ToonDrawQueue.addMesh.
import { ToonDrawItem, Matrix4 } from "./vanilla.js";
const drawItem = new ToonDrawItem(null, Matrix4.createIdentity(), { lineId: 1 });
drawItem.setOptions({ lineId: 1, alpha: 0.5 });꼴의 칸 하나 바꾸기. (쥔 꼴 객체의 칸을 고치고 바뀜 표시, undefined 면 칸을 지운다)
Changes one option. (Sets the option on the held options object and marks dirty, undefined removes it)
- namestring
- 꼴의 칸 이름. (tintColor, emissiveIntensity, alpha 같은 것)Name of the option. (tintColor, emissiveIntensity, alpha and the like)
- valueany
- 값. (undefined 면 칸을 지워 기본값으로)Value. (undefined removes the option to use the default)
import { ToonDrawItem, Matrix4 } from "./vanilla.js";
const drawItem = new ToonDrawItem(null, Matrix4.createIdentity(), { lineId: 1 });
drawItem.setOption("tintColor", [1, 0.6, 0.6, 1]);바뀜 표시. (꼴 객체의 값을 그 자리에서 고친 뒤 부른다, 다음에 담을 때 다시 푼다)
Marks dirty. (Call after changing values of the options object in place, the options are resolved again the next time it is added)
import { ToonDrawItem, Matrix4 } from "./vanilla.js";
const options = { tintColor: [1, 1, 1, 1] };
const drawItem = new ToonDrawItem(null, Matrix4.createIdentity(), options);
options.tintColor[1] = 0.5;
drawItem.markDirty();바뀜 표시가 있는지.
Whether it is marked dirty.
반환Returnsboolean 다음에 담을 때 꼴을 다시 풀면 true.true when the options will be resolved again the next time it is added.
ToonDrawQueue
툰 그리기 줄. (한 프레임에 그릴 모형을 담아 두었다가 ToonRenderer 로 차례를 맞춰 그린다)
- 차례: (화면 공간 바깥선의 선의 판) → 단계 beforeOpaque → 불투명한 몸 → afterOpaque → 불투명한 것의 바깥선 껍데기 → 화면 공간 바깥선 → afterOutline → 비치는 것(카메라에서 먼 것부터, 깊이는 쓰지 않음) → afterTransparent. 몸을 다 그린 뒤 바깥선을 몰아 그려 프로그램을 덜 바꾸고, 비치는 것은 뒤의 것이 비쳐 보이게 맨 끝에 먼 것부터 섞는다.
- 불투명한 것(몸, 바깥선 껍데기, 그림자 깊이)은 재질, 모형, 바탕색 텍스처로 정렬해 그린다. (같은 것끼리는 담은 차례, 유니티 SRP Batcher 처럼 상태를 덜 바꾼다) 깊이 시험(LEQUAL)으로 가장 가까운 것이 남으므로 화면은 담은 차례와 같다. 깊이가 꼭 같은 면(겹친 평면)만 나중에 그린 것이 이겨 차례가 드러난다. 그런 것은 한 모형으로 합치거나 깊이를 띄운다. 비치는 것은 지금처럼 먼 것부터 담은 차례로 그린다.
- 비치는 것: 그릴 때의 alpha 나 tintColor 의 알파가 1 보다 작거나 blendMode 가 alpha 가 아닌 것. 바깥선 껍데기도 함께(hasOutline) 그린다.
- 묶음: options.group 이 같은 비치는 것은 한 덩어리로 가운데 깊이(담긴 것의 평균)로 정렬하고 담은 차례로 그린다. options.isDepthPrepassed 가 묶음 안에 하나라도 있으면 그 덩어리는 깊이만 먼저 그린 뒤 같은 깊이(LEQUAL)인 화소에만 색을 칠한다. 여러 부품이 겹친 홀로그램이 두 겹으로 밝지 않고 한 덩어리로 비친다. 덩어리끼리는 먼 것부터라 서로 비친다.
- 화면 공간 바깥선: setScreenOutline(ToonScreenOutline) 을 주면 draw 가 몸 앞에 불투명한 것을 선의 판에 그리고, 바깥선 껍데기 뒤에 섞는다. 번호는 options.lineId (주지 않으면 담은 차례 + 1, 인스턴스는 instances[i].lineId, 인스턴스 버퍼는 꼴의 instanceLineId 칸이 먼저), 모형마다 options.hasScreenOutline, options.hasCreaseLine 으로 끄고 켠다. 비치는 것은 선의 판에 그리지 않는다. 화면 사각형(ToonRenderer.setScreenRect)이 있으면 그 사각형을 선의 판의 그리는 영역으로 쓴다.
- 모서리 어둠: setPostProcess(ToonPostProcess) 를 주고 후처리에서 setAmbientOcclusion 을 켜면 선의 판 뒤, 몸 앞에 셈해 렌더러에 걸고 endFrame 뒤에 푼다. (바깥선이 없으면 선 없이 선의 판만 그린다)
- 단계 콜백: addPass(stage, callback) 의 callback(renderer, webGL2RenderingContext) 를 그 자리에서 부른다. 부른 뒤 렌더러가 프레임의 그리기 상태를 다시 건다.
- 인스턴스 묶음(addMeshInstanced)은 불투명이면 몸과 바깥선 껍데기를 한 번에 그리고, 비치면 인스턴스 자리의 가운데로 한 덩어리로 정렬한다. 인스턴스마다 걸러 그릴 때마다 올린다. (몸, 그림자, 선의 판이 같은 배열을 따로 올림) 오래 두는 것은 addMeshInstanceBuffer 로 한 번 올린 버퍼를 같이 쓴다.
- 인스턴스 버퍼(addMeshInstanceBuffer)는 유니티 Graphics.RenderMeshInstanced 와 GraphicsBuffer, 고도 MultiMesh 꼴이다. 버퍼 전체의 경계로 통째 거르고 다시 올리지 않는다.
- 그림자: drawShadows(renderer, shadowMap) 가 castsShadow 가 false 가 아닌 불투명한 것만 해의 그림자 깊이로 그린다. draw 보다 먼저 부른다. 그림자 판의 setUpdateMode(ShadowUpdateMode) 를 따른다. 기본 onChange 는 빛과 드리우개가 그대로면 다시 그리지 않고, 오래 그대로인 것은 구워 두고 움직이는 것만 덧그린다. (화면은 매 프레임 그린 것과 같다) 점광과 스포트라이트 그림자는 drawLocalShadows(renderer, shadowAtlas) 가 아틀라스의 칸마다 같은 것을 그린다. (렌더러에 setLocalShadows 로 건다)
- 사용: 매 프레임 clear() → addMesh / addMeshInstanced / addMeshInstanceBuffer / addPass → (drawShadows) → draw(renderer, camera) 나 drawWithMatrices(renderer, 보기 행렬, 투영 행렬) draw 는 renderer.beginFrameWithCamera(camera) 와 endFrame 을 스스로 부른다. drawWithMatrices 는 beginFrameWithMatrices 를 부른다. (직교 원 행렬 카메라) 화면 사각형(ToonRenderer.setScreenRect)은 그 전에 건다. clear 는 담은 모형과 단계 콜백을 모두 비운다. (화면 공간 바깥선은 그대로 둔다)
- 담는 것은 행렬과 꼴의 참조다. draw 를 부를 때까지 고치지 않는다.
Toon draw queue. (Holds the models to draw in a frame, then draws them in order with ToonRenderer)
- Order: (line target of the screen-space outline) → stage beforeOpaque → opaque bodies → afterOpaque → outline shells of opaque things → screen-space outline → afterOutline → transparent things (farthest from the camera first, depth not written) → afterTransparent. Outlines are drawn together after all bodies to switch programs less, and transparent things are blended last from the farthest so what is behind shows through.
- Opaque things (bodies, outline shells, shadow depth) are drawn sorted by material, model and base color texture. (Ties keep the order they were added, so state changes less, like the Unity SRP Batcher) The depth test (LEQUAL) keeps the nearest one, so the screen is the same as in the added order. Only faces at exactly the same depth (overlapping planes) show the order, because the one drawn later wins. Merge such things into one model or offset their depth. Transparent things are drawn as before, farthest first in the added order.
- Transparent things: those whose alpha or tintColor alpha at draw time is below 1, or whose blendMode is not alpha. Their outline shells are drawn with them too (hasOutline).
- Groups: transparent things with the same options.group are sorted as one lump by the middle depth (average of the members) and drawn in the order they were added. If even one member of a group has options.isDepthPrepassed, that lump draws depth first and then paints color only on pixels with the same depth (LEQUAL). A hologram made of several overlapping parts shows through as one lump instead of being doubly bright. Lumps are drawn farthest first so they show through each other.
- Screen-space outline: if setScreenOutline(ToonScreenOutline) is given, draw draws opaque things into the line target before the bodies and blends it after the outline shells. The ID is options.lineId (the order added + 1 if not given, for instances instances[i].lineId and for instance buffers the layout's instanceLineId slot comes first), and per model options.hasScreenOutline and options.hasCreaseLine turn it off and on. Transparent things are not drawn into the line target. If there is a screen rectangle (ToonRenderer.setScreenRect), that rectangle is used as the drawing area of the line target.
- Ambient occlusion: with setPostProcess(ToonPostProcess) and setAmbientOcclusion turned on in the post process, it is computed after the line target and before bodies, set on the renderer and cleared after endFrame. (without outlines, only the line target is drawn, without lines)
- Stage callbacks: callback(renderer, webGL2RenderingContext) of addPass(stage, callback) is called at that point. After the call, the renderer sets the frame's draw state again.
- Instance batches (addMeshInstanced) draw body and outline shell at once if opaque, and if transparent are sorted as one lump by the center of the instance positions. They are culled per instance and uploaded each time they are drawn. (The body, shadows and line target each upload the same array) Long-lived ones share a buffer uploaded once with addMeshInstanceBuffer.
- Instance buffers (addMeshInstanceBuffer) follow the form of Unity's Graphics.RenderMeshInstanced with GraphicsBuffer and Godot's MultiMesh. They are culled as a whole by the bounds of the entire buffer and not uploaded again.
- Shadows: drawShadows(renderer, shadowMap) draws only opaque things whose castsShadow is not false into the sun's shadow depth. Call it before draw. It follows setUpdateMode(ShadowUpdateMode) of the shadow target. The default onChange does not redraw when the lights and casters are unchanged, bakes the ones that stay still and draws only the moving ones on top. (The screen is the same as drawing every frame) For point light and spotlight shadows, drawLocalShadows(renderer, shadowAtlas) draws the same things per atlas tile. (Set on the renderer with setLocalShadows)
- Use: every frame clear() → addMesh / addMeshInstanced / addMeshInstanceBuffer / addPass → (drawShadows) → draw(renderer, camera) or drawWithMatrices(renderer, view matrix, projection matrix) draw calls renderer.beginFrameWithCamera(camera) and endFrame by itself. drawWithMatrices calls beginFrameWithMatrices. (Orthographic or raw matrix camera) The screen rectangle (ToonRenderer.setScreenRect) is set before that. clear empties all added models and stage callbacks. (The screen-space outline is kept)
- What is added are references to matrices and options. Do not change them until draw is called.
import { ToonRenderer, ToonDrawQueue, ToonScreenOutline, MeshBuilder, createBoxGeometry, createFacetedChunkGeometry, Camera3D, Matrix4, Vector3 } from "./vanilla.js";
const webGL2RenderingContext = document.createElement("canvas").getContext("webgl2");
const renderer = new ToonRenderer(webGL2RenderingContext);
const floorBuilder = new MeshBuilder();
floorBuilder.addPart(createBoxGeometry(8, 0.2, 8), Matrix4.createTranslation(0, -0.1, 0), "#708090", { hasOutline: false });
const floorMesh = renderer.createMesh(floorBuilder.readArrays());
const gemBuilder = new MeshBuilder();
gemBuilder.addPart(createFacetedChunkGeometry(0.5, [1, 0.9, 1.1], [1, 1, 1]), Matrix4.createTranslation(0, 0.5, 0), "#a0c0ff", { hasOutline: false });
const gemMesh = renderer.createMesh(gemBuilder.readArrays());
const camera = new Camera3D();
camera.setPerspective(0.8, 0.1, 100);
camera.lookAt(Vector3.create(0, 2, 4), Vector3.create(0, 0.4, 0), Vector3.create(0, 1, 0));
const queue = new ToonDrawQueue();
queue.setScreenOutline(new ToonScreenOutline(webGL2RenderingContext));
queue.addMesh(floorMesh, Matrix4.createIdentity(), { lineId: 1, hasScreenOutline: false });
queue.addMesh(gemMesh, Matrix4.createIdentity(), { lineId: 2, hasCreaseLine: false });
queue.draw(renderer, camera);비우기. (프레임마다 담기 전에, 단계 콜백도 비운다, 화면 공간 바깥선은 그대로)
Clear. (Before adding each frame, also clears stage callbacks, the screen-space outline is kept)
짝Counterpart: vanilla-engine ToonDrawQueue.clear
담은 수 반환.
Returns the queued count.
반환Returnsnumber 담은 모형과 인스턴스 묶음 수.Number of added models and instance batches.
짝Counterpart: vanilla-engine ToonDrawQueue.get_item_count
화면 공간 바깥선 맡기기. (draw 가 선의 판을 그리고 바깥선 껍데기 뒤에 섞는다, null 이면 맡기지 않음)
Hand over the screen-space outline. (draw draws the line target and blends it after the outline shells, null hands over nothing)
- screenOutlineobject | null
- ToonScreenOutline 이나 null.ToonScreenOutline or null.
짝Counterpart: vanilla-engine ToonDrawQueue.set_screen_outline
import { ToonDrawQueue, ToonScreenOutline } from "./vanilla.js";
const webGL2RenderingContext = document.createElement("canvas").getContext("webgl2");
const queue = new ToonDrawQueue();
const outline = new ToonScreenOutline(webGL2RenderingContext);
outline.setWidth(2.5);
queue.setScreenOutline(outline);맡긴 화면 공간 바깥선 반환. (없으면 null)
Return the handed-over screen-space outline. (null if none)
반환Returnsobject | null ToonScreenOutline 이나 null.ToonScreenOutline or null.
툰 후처리 맡기기. (모서리 어둠을 켰으면 draw 가 선의 판 뒤, 몸 앞에 셈해 렌더러에 걸고 endFrame 뒤에 푼다, null 이면 맡기지 않음)
- 화면 공간 바깥선이 있으면 그 선의 판을, 없으면 후처리의 미리 그리기(getAmbientOcclusionPrepass)로 노멀과 깊이만 그린다.
Hands over the toon post process. (if ambient occlusion is on, draw computes it after the line target and before bodies, sets it on the renderer and clears it after endFrame, null hands over nothing)
- Uses the screen outline's line target if there is one, otherwise draws only normals and depth with the post process prepass (getAmbientOcclusionPrepass).
- postProcessobject | null
- ToonPostProcess 나 null.ToonPostProcess or null.
짝Counterpart: vanilla-engine ToonDrawQueue.set_post_process
import { ToonDrawQueue, ToonScreenOutline, ToonPostProcess } from "./vanilla.js";
const webGL2RenderingContext = document.createElement("canvas").getContext("webgl2");
const postProcess = new ToonPostProcess(webGL2RenderingContext, 640, 360, { depthBits: 24 });
postProcess.setAmbientOcclusion(true, 0.5, 0.5, 0.5);
const queue = new ToonDrawQueue();
queue.setScreenOutline(new ToonScreenOutline(webGL2RenderingContext));
queue.setPostProcess(postProcess);맡긴 툰 후처리 반환. (없으면 null)
Returns the handed-over toon post process. (null if none)
반환Returnsobject | null ToonPostProcess 나 null.ToonPostProcess or null.
단계 콜백 담기. (ToonDrawStage 의 자리에서 callback(renderer, webGL2RenderingContext) 를 부른다, 담은 차례로)
Adds a stage callback. (Calls callback(renderer, webGL2RenderingContext) at the ToonDrawStage position, in the order added)
- stagestring
- ToonDrawStage.
- callbackFunction
- (renderer, webGL2RenderingContext) 를 받는다. 부른 뒤 렌더러가 프레임의 그리기 상태를 다시 건다.Receives (renderer, webGL2RenderingContext). After the call, the renderer sets the frame's draw state again.
짝Counterpart: vanilla-engine ToonDrawQueue.add_pass
모형 하나 담기. (null 이면 담지 않는다)
Queues a single model. (Not queued if null)
- meshobject | null
- ToonRenderer.createMesh 의 결과.Result of ToonRenderer.createMesh.
- modelMatrixMatrix4
- 모형 행렬. (draw 때까지 고치지 않는다)Model matrix. (Do not change it until draw)
- optionsobject
- ToonRenderer.drawMesh 의 꼴과 castsShadow (기본 true), group, isDepthPrepassed, lineId, hasScreenOutline (기본 true), hasCreaseLine (기본 true).Form of ToonRenderer.drawMesh plus castsShadow (default true), group, isDepthPrepassed, lineId, hasScreenOutline (default true), hasCreaseLine (default true).
짝Counterpart: vanilla-engine ToonDrawQueue.add_mesh
남겨 두는 그리기 항목 짓기. (한 번 짓고 쥐어 두었다가 프레임마다 addItem 으로 담는다, new ToonDrawItem 과 같다)
Builds a retained draw item. (Build once, hold it and add it with addItem every frame, same as new ToonDrawItem)
- meshobject | null
- ToonRenderer.createMesh 의 결과.Result of ToonRenderer.createMesh.
- modelMatrixMatrix4
- 모형 행렬. (복사해 쥔다, 바꾸면 그 항목의 setModelMatrix)Model matrix. (Copied and held, change it with the item's setModelMatrix)
- optionsobject
- addMesh 와 같은 꼴. (쥐어 둔다, 고치면 markDirty 나 setOption)Options, same as addMesh. (Held, call markDirty or setOption after changing)
반환ReturnsToonDrawItem 그리기 항목.Draw item.
import { ToonRenderer, ToonDrawQueue, MeshBuilder, createBoxGeometry, Camera3D, Matrix4, Vector3 } from "./vanilla.js";
const webGL2RenderingContext = document.createElement("canvas").getContext("webgl2");
const renderer = new ToonRenderer(webGL2RenderingContext);
const builder = new MeshBuilder();
builder.addPart(createBoxGeometry(1, 1, 1), Matrix4.createIdentity(), "#c08060");
const boxMesh = renderer.createMesh(builder.readArrays());
const camera = new Camera3D();
camera.setPerspective(0.8, 0.1, 100);
camera.lookAt(Vector3.create(0, 2, 4), Vector3.create(0, 0, 0), Vector3.create(0, 1, 0));
const queue = new ToonDrawQueue();
const boxItem = queue.createItem(boxMesh, Matrix4.createTranslation(0, 0.5, 0), { tintColor: [1, 0.8, 0.8, 1], lineId: 1 });
queue.clear();
queue.addItem(boxItem);
queue.draw(renderer, camera);
boxItem.setOption("tintColor", [0.8, 1, 0.8, 1]);남겨 두는 그리기 항목 담기. (addMesh 와 같은 자리, 바뀜 표시가 없으면 앞서 푼 꼴을 그대로 쓴다)
- 꼴 객체를 프레임마다 견주거나 풀지 않는다. 꼴을 고쳤으면 그 항목의 markDirty 나 setOption, setOptions 를 부른다. (유니티 MeshRenderer, 언리얼 프리미티브 컴포넌트 꼴)
- 바뀐 것이 없는 항목은 그림자 캐시(onChange)도 견주지 않는다. 행렬을 바꾸면 setModelMatrix 로 넘긴다.
Adds a retained draw item. (Same place as addMesh, uses the options resolved before when not marked dirty)
- Does not compare or resolve the options object every frame. After changing options call the item's markDirty, setOption or setOptions. (Unity MeshRenderer, Unreal primitive component shape)
- Items with no change are not compared by the shadow cache (onChange) either. Pass a changed matrix with setModelMatrix.
- drawItemToonDrawItem
- createItem 이나 new ToonDrawItem 의 결과.Result of createItem or new ToonDrawItem.
import { ToonDrawQueue, ToonDrawItem, Matrix4 } from "./vanilla.js";
const queue = new ToonDrawQueue();
const drawItem = new ToonDrawItem(null, Matrix4.createIdentity(), { lineId: 3 });
queue.clear();
queue.addItem(drawItem);같은 모형 여럿 담기. (GPU 인스턴싱, 비어 있거나 null 이면 담지 않는다)
Queues multiple instances of the same model. (GPU instancing, not queued if empty or null)
- meshobject | null
- ToonRenderer.createMesh 의 결과.Result of ToonRenderer.createMesh.
- instancesArray<object>
- { modelMatrix, tintColor, lineId (선택) } 의 배열.Array of { modelMatrix, tintColor, lineId (optional) }.
- optionsobject
- addMesh 와 같다.Same as addMesh.
짝Counterpart: vanilla-engine ToonDrawQueue.add_mesh_instanced
영구 인스턴스 버퍼로 같은 모형 여럿 담기. (몸, 바깥선 껍데기, 그림자, 선의 판이 한 GPU 버퍼를 같이 쓰고 다시 올리지 않는다)
- 버퍼는 ToonRenderer.createInstanceBuffer 로 짓고 updateInstanceBuffer, updateInstanceBufferRange 로 고친다. 버퍼 전체의 경계로 통째 거른다.
- 인스턴스마다 선 번호는 꼴의 instanceLineId 칸, 없으면 options.lineId (주지 않으면 담은 차례 + 1).
- 그림자 캐시(ShadowUpdateMode.onChange)는 버퍼의 generation 으로 고친 것을 안다.
Adds many of the same model with a persistent instance buffer. (The body, outline shell, shadows and line target share one GPU buffer and do not upload it again)
- Build the buffer with ToonRenderer.createInstanceBuffer and change it with updateInstanceBuffer or updateInstanceBufferRange. Culled as a whole by the bounds of the entire buffer.
- The line ID of each instance is the layout's instanceLineId slot, otherwise options.lineId (the order added + 1 if not given).
- The shadow cache (ShadowUpdateMode.onChange) learns of changes through the buffer's generation.
- meshobject | null
- ToonRenderer.createMesh 의 결과.Result of ToonRenderer.createMesh.
- instanceBufferobject | null
- ToonRenderer.createInstanceBuffer 의 결과.The result of ToonRenderer.createInstanceBuffer.
- instanceCountnumber
- 그릴 인스턴스 수. (버퍼에 든 수를 넘으면 자른다, 0 이하면 담지 않는다)Number of instances to draw. (Clipped if it exceeds the number in the buffer, not added if 0 or less)
- optionsobject
- addMesh 와 같다.Same as addMesh.
짝Counterpart: vanilla-engine ToonDrawQueue.add_mesh_instance_buffer
import { ToonRenderer, ToonDrawQueue, ToonScreenOutline, MeshBuilder, createOctahedronGeometry, Camera3D, Matrix4, Vector3 } from "./vanilla.js";
const webGL2RenderingContext = document.createElement("canvas").getContext("webgl2");
const renderer = new ToonRenderer(webGL2RenderingContext);
const builder = new MeshBuilder();
builder.addPart(createOctahedronGeometry(0.3), Matrix4.createIdentity(), "#a89880");
const rockMesh = renderer.createMesh(builder.readArrays());
const instanceLayout = renderer.createInstanceLayout([{ name: "instanceMatrix", size: 16 }, { name: "instanceTint", size: 4 }, { name: "instanceLineId", size: 1 }]);
const floatCount = instanceLayout.getFloatCount();
const data = new Float32Array(floatCount * 25);
for (let index = 0; index < 25; ++index) {
data.set(Matrix4.createTranslation(index % 5 - 2, 0, Math.floor(index / 5) - 2).getElements(), index * floatCount);
data.set([1, 1, 1, 1, 1 + index], index * floatCount + 16);
}
const instanceBuffer = renderer.createInstanceBuffer(instanceLayout, data, "dynamic");
const camera = new Camera3D();
camera.setPerspective(0.8, 0.1, 50);
camera.lookAt(Vector3.create(0, 5, 6), Vector3.create(0, 0, 0), Vector3.create(0, 1, 0));
const queue = new ToonDrawQueue();
queue.setScreenOutline(new ToonScreenOutline(webGL2RenderingContext));
queue.addMeshInstanceBuffer(rockMesh, instanceBuffer, 25);
queue.draw(renderer, camera);
const brokenRock = data.slice(12 * floatCount, 13 * floatCount);
brokenRock.set([0.5, 0.5, 0.5, 1], 16);
renderer.updateInstanceBufferRange(instanceBuffer, 12, brokenRock);
queue.draw(renderer, camera);그릴 꼴이 비치는지. (alpha 나 틴트의 알파가 1 보다 작거나 섞는 방식이 곧은 알파가 아님)
Whether the shape to draw is translucent. (alpha or the tint's alpha is less than 1, or the blend mode is not straight alpha)
- optionsobject
- 그리기 꼴.Draw options.
반환Returnsboolean 비치면 true.true if transparent.
그림자 깊이 그리기. (불투명하고 castsShadow 가 false 가 아닌 것만, 앞의 프레임버퍼와 뷰포트는 되돌린다)
Draws shadow depth. (Only opaque ones whose castsShadow is not false, restores the previous framebuffer and viewport)
- rendererobject
- ToonRenderer.
- shadowMapobject
- ShadowMap.
짝Counterpart: vanilla-engine ToonDrawQueue.draw_shadows
점광과 스포트라이트 그림자 깊이 그리기. (불투명하고 castsShadow 가 false 가 아닌 것을 아틀라스의 칸마다, 앞의 프레임버퍼와 뷰포트는 되돌린다)
Draw point light and spotlight shadow depth. (Opaque things whose castsShadow is not false, per atlas tile, the previous framebuffer and viewport are restored)
- rendererobject
- ToonRenderer.
- shadowAtlasobject
- ShadowAtlas. (updateLights 를 부른 것)ShadowAtlas. (One on which updateLights was called)
짝Counterpart: vanilla-engine ToonDrawQueue.draw_local_shadows
import { ToonRenderer, ToonDrawQueue, MeshBuilder, createBoxGeometry, createSphereGeometry, ShadowAtlas, Camera3D, Matrix4, Vector3 } from "./vanilla.js";
const webGL2RenderingContext = document.createElement("canvas").getContext("webgl2");
const renderer = new ToonRenderer(webGL2RenderingContext);
const builder = new MeshBuilder();
builder.addPart(createBoxGeometry(4, 0.2, 4), Matrix4.createTranslation(0, -0.1, 0), "#8090a0", { hasOutline: false });
builder.addPart(createSphereGeometry(0.5, 24, 16), Matrix4.createTranslation(0, 0.5, 0), "#f0e0d0", { hasOutline: false });
const mesh = renderer.createMesh(builder.readArrays());
renderer.setPointLights([{ position: [1, 2, 1], color: [1, 0.85, 0.6], intensity: 4, range: 8, castsShadow: true }]);
const shadowAtlas = new ShadowAtlas(webGL2RenderingContext, 1024);
shadowAtlas.updateLights(renderer.getLightSet().getPointLights());
renderer.setLocalShadows(shadowAtlas, 1);
const camera = new Camera3D();
camera.setPerspective(0.8, 0.1, 50);
camera.lookAt(Vector3.create(0, 3, 5), Vector3.create(0, 0, 0), Vector3.create(0, 1, 0));
const queue = new ToonDrawQueue();
queue.addMesh(mesh, Matrix4.createIdentity());
queue.drawLocalShadows(renderer, shadowAtlas);
queue.draw(renderer, camera);담은 것 그리기. (화면 공간 바깥선이 있으면 선의 판부터, beginFrameWithCamera 와 endFrame 을 스스로 부른다)
Draw what was added. (Starts with the line target if there is a screen-space outline, calls beginFrameWithCamera and endFrame by itself)
- rendererobject
- ToonRenderer.
- cameraobject
- Camera3D.
짝Counterpart: vanilla-engine ToonDrawQueue.draw
보기와 투영 행렬로 담은 것 그리기. (Camera3D 없이, beginFrameWithMatrices 와 endFrame 을 스스로 부른다)
Draws the queued items with view and projection matrices. (Without Camera3D, calls beginFrameWithMatrices and endFrame itself)
- rendererobject
- ToonRenderer.
- viewMatrixMatrix4
- 보기 행렬.View matrix.
- projectionMatrixMatrix4
- 투영 행렬.Projection matrix.
짝Counterpart: vanilla-engine ToonDrawQueue.draw_with_matrices
화면 공간 바깥선의 선의 판 그리기. (맡긴 것이 없으면 아무것도 하지 않음, 불투명한 것만, 화면 사각형이 있으면 그 사각형을 그리는 영역으로)
Draw the line target of the screen-space outline. (Does nothing if none was handed over, opaque things only, uses the screen rectangle as the drawing area if there is one)
- rendererobject
- ToonRenderer.
- viewMatrixMatrix4
- 보기 행렬.View matrix.
- projectionMatrixMatrix4
- 투영 행렬.Projection matrix.
한 단계의 콜백 부르기. (부른 뒤 프레임의 그리기 상태를 다시 건다)
Calls the callbacks of one stage. (Re-applies the frame's draw state after calling)
- rendererobject
- ToonRenderer.
- stagestring
- ToonDrawStage.
단계마다 그리기. (beginFrame 과 endFrame 사이, readDepth(자리) 는 카메라에서의 보기 깊이)
Draws per stage. (Between beginFrame and endFrame, readDepth(position) is the view depth from the camera)
- rendererobject
- ToonRenderer.
- readDepthFunction
- ({ x, y, z }) 의 보기 깊이를 돌려준다.Returns the view depth of ({ x, y, z }).
하나 그리기. (모형 하나는 drawMesh, 인스턴스 묶음은 drawMeshInstanced, 인스턴스 버퍼는 drawMeshInstanceBuffer)
Draws one item. (A single model uses drawMesh, an instance group uses drawMeshInstanced, an instance buffer uses drawMeshInstanceBuffer)
- rendererobject
- ToonRenderer.
- itemobject
- 담은 것 하나.One added item.
- optionsobject
- 이번에 쓸 그리기 꼴.Draw options to use this time.
ToonDrawStageenum
그리기 줄의 단계. (addPass 의 콜백을 부를 자리)
- beforeOpaque: 불투명한 몸 앞. (평면 거울에 비친 모습, 하늘)
- afterOpaque: 불투명한 몸 뒤, 바깥선 껍데기 앞.
- afterOutline: 바깥선 껍데기와 화면 공간 바깥선 뒤, 비치는 것 앞.
- afterTransparent: 비치는 것 뒤. (효과)
Stages of the draw queue. (Where addPass callbacks are called)
- beforeOpaque: before opaque bodies. (Planar mirror reflection, sky)
- afterOpaque: after opaque bodies, before outline shells.
- afterOutline: after outline shells and the screen-space outline, before transparent things.
- afterTransparent: after transparent things. (Effects)
import { ToonDrawQueue, ToonDrawStage } from "./vanilla.js";
const queue = new ToonDrawQueue();
queue.addPass(ToonDrawStage.afterOpaque, (renderer, webGL2RenderingContext) => {
webGL2RenderingContext.depthMask(false);
});| 이름Name | 값Value | 설명Description |
|---|---|---|
beforeOpaque | beforeOpaque | 불투명한 몸 앞.Before opaque bodies. |
afterOpaque | afterOpaque | 불투명한 몸 뒤, 바깥선 껍데기 앞.After opaque bodies, before outline shells. |
afterOutline | afterOutline | 바깥선 껍데기와 화면 공간 바깥선 뒤, 비치는 것 앞.After outline shells and the screen-space outline, before transparent things. |
afterTransparent | afterTransparent | 비치는 것 뒤.After transparent things. |