vanilladocs
vanillapunch.com
API / graphics3d/toon/toonscreenoutline

graphics3d/toon/toonscreenoutline

툰 화면 공간 바깥선. (노멀, 선 번호, 깊이를 선의 판에 그리고, 바로 이웃 사이의 경계에서 선을 잡아 가는 선은 둘레 칸을 바로 보고, 굵은 선은 점프 플러딩으로 넓힌 뒤 거리로 덮는 몫을 셈해 섞는다)

Toon screen-space outline. (Draws normals, line IDs and depth into the line target, picks lines at the boundaries between direct neighbors, looks at the surrounding cells directly for thin lines and widens thick lines with jump flooding, then computes coverage from distance and blends)

예제Example툰 화면 공간 바깥선을 한 프레임에 긋기Draw the toon screen-space outline in one frame
import { ToonRenderer, ToonScreenOutline, ToonOutlineWidthUnit, MeshBuilder, createBoxGeometry, Matrix4, Vector3 } from "./vanilla.js";
const webGL2RenderingContext = document.createElement("canvas").getContext("webgl2");
const renderer = new ToonRenderer(webGL2RenderingContext);
const outline = new ToonScreenOutline(webGL2RenderingContext);
outline.setWidth(2, ToonOutlineWidthUnit.pixel);
outline.setCrease(50, 1, 0.8);
const builder = new MeshBuilder();
builder.addPart(createBoxGeometry(1, 1, 1), Matrix4.createIdentity(), "#e0c8a8", { hasOutline: false });
const mesh = renderer.createMesh(builder.readArrays());
const viewMatrix = Matrix4.createLookAt(Vector3.create(2, 2, 3), Vector3.create(0, 0, 0), Vector3.create(0, 1, 0));
const projectionMatrix = Matrix4.createPerspective(Math.PI / 4, 1, 0.1, 100);
const modelMatrix = Matrix4.createIdentity();
if (outline.beginLineIds(viewMatrix, projectionMatrix)) {
	outline.drawMesh(mesh, modelMatrix, 1);
	outline.endLineIds();
}
renderer.beginFrameWithMatrices(viewMatrix, projectionMatrix);
renderer.drawMesh(mesh, modelMatrix);
renderer.endFrame();
outline.drawOutline();
Draw the toon screen-space outline in one frame

ToonScreenOutline

짝Counterpart: vanilla-engine ToonScreenOutline

툰 화면 공간 바깥선. (노멀, 선 번호, 깊이를 선의 판에 그리고, 바로 이웃 사이의 경계에서 선을 잡아 가는 선은 둘레 칸을 바로 보고, 굵은 선은 점프 플러딩으로 넓힌 뒤 거리로 덮는 몫을 셈해 섞는다)

  • 선의 판: ToonRenderer 의 createMesh 결과를 같은 행렬로 한 번 더 그려 노멀(팔면체 접기), 선 번호(14 비트), 꼴(바깥 선, 꺾임 선을 켤지)과 깊이를 쓴다.
  • 잡기: 화소와 바로 이웃 넷 사이의 경계마다 한 번 본다. 선은 화소가 아니라 화소 사이의 경계 가운데에 선다. (같은 경계를 두 번 긋지 않는다) 바깥 선은 빈 곳과 맞닿은 실루엣, 다른 번호와 맞닿은 곳, 같은 번호라도 가린 화소가 가려진 화소의 접평면에서 깊이 문턱과 오차 여유보다 떨어진 곳(가려진 실루엣)이다. 꺾임 선은 같은 번호 안에서 이웃한 두 노멀이 꺾임 각보다 더 벌어진 곳이다. 화소 하나 사이의 노멀만 보므로 둥근 면의 실루엣 둘레나 비스듬한 면에 띠가 서지 않는다. 깊이를 접평면 거리로 견주므로 비스듬히 보는 바닥에 가짜 선이 서지 않는다. 문턱에 잰 오차(노멀 8 비트 각 오차 x 두 자리 사이 거리, 꺾임의 화소 한 칸 x 사인, 깊이 24 비트 한 칸) x 배율을 더해 먼 것도 같은 뜻이 되고, 나란한 낮은 턱은 화소 한 칸보다 낮아도 잡힌다.
  • 가는 선(굵기 약 3.24 픽셀까지): 씨앗 고르기와 같은 차례로 화소마다 첫 경계 쪽(R8UI 한 바이트)을 고르고, 섞기가 둘레 3 x 3 화소의 씨앗을 점프 플러딩 마지막 걸음과 같은 차례로 보아 가장 가까운 것까지의 거리를 잰다. 화면 전체 패스가 씨앗 쪽 판 하나와 섞기 하나다. (모바일 타일 GPU 에서 패스 수와 판 대역폭이 굵은 선 길의 몇 분의 1)
  • 넓히기(굵은 선): 경계 토막까지의 거리를 점프 플러딩으로 퍼뜨린다. 굵기에 상관없이 걸음 수는 log2 이고, 바깥 선과 꺾임 선은 따로 퍼뜨려 굵기를 따로 준다.
  • 섞기: 그리는 영역의 화소마다 가장 가까운 경계까지의 거리로 clamp(굵기 / 2 - 거리 + 0.5, 0, 1) 만큼 덮는다. (가장자리가 부드럽고, 넓히기 판을 줄여도 계단과 점선이 없다)
  • 모형마다: drawMesh 의 hasScreenOutline 이 false 면 그 모형은 선을 내지 않고 뒤의 선만 가린다. hasCreaseLine 이 false 면 꺾임 선만 끈다.
  • 번호마다 색: setLineColor 로 번호마다 선 색을 준다. (언리얼 Custom Stencil 꼴, 맞닿은 선은 앞쪽 번호의 색, 표에 없는 번호와 표가 빈 때는 setColor 의 색 그대로)
  • 굵기: setWidth 와 setCrease 의 굵기는 선 하나의 굵기다. (경계를 가운데로 양쪽에 반씩) 단위는 ToonOutlineWidthUnit, 한 픽셀 밑으로 내리지 않는다.
  • 깊이: 투영 행렬로 직교와 원근을 가리고, 깊이를 보기 공간 자리로 풀어 견준다. (화면 사각형처럼 클립 x, y 를 옮긴 투영도 된다)
  • 값: setResolutionScale 로 섞기 앞의 모든 판(선의 판, 가면, 씨앗, 넓히기 판)을 줄인다. (기본 1 은 그리는 영역 그대로, 줄이면 가는 선은 선의 판 해상도에서 덮는 몫 판 하나를 셈해 쌍선형으로 한 번 읽어 섞는다)
  • 인스턴스: drawMeshInstanced 는 인스턴스 배열을 걸러 그때 올린다. drawMeshInstanceBuffer 는 ToonRenderer.createInstanceBuffer 의 버퍼를 몸과 같이 쓰고 다시 올리지 않는다. 버퍼의 인스턴스마다 번호는 꼴의 instanceLineId 칸에서 읽는다. (없으면 공통 번호)
  • 사용: 매 프레임 beginLineIds(보기, 투영) → drawMesh / drawMeshInstanced / drawMeshInstanceBuffer → endLineIds() (씨앗과 넓히기까지 셈) → 툰 몸 그리기 → drawOutline(). beginLineIds 는 그때의 뷰포트를 그리는 영역으로 적어 두고, 선의 판을 그 크기에 맞춰 짓는다. endLineIds 와 drawOutline 이 프레임버퍼, 뷰포트, 상태를 돌린다. ToonDrawQueue.setScreenOutline 으로 맡기면 그리기 줄이 이 차례를 스스로 한다. (엔진 2D 그리기 사이에 끼울 때, 그 전에 Graphic.flushBatch)

Toon screen-space outline. (Draws normals, line IDs and depth into the line target, picks lines at the boundaries between direct neighbors, looks at the surrounding cells directly for thin lines and widens thick lines with jump flooding, then computes coverage from distance and blends)

  • Line target: draws the result of ToonRenderer's createMesh once more with the same matrices and writes the normal (octahedral encoding), line ID (14 bits), flags (whether the silhouette line and crease line are on) and depth.
  • Picking: each boundary between a pixel and its four direct neighbors is looked at once. A line stands not on a pixel but in the middle of the boundary between pixels. (The same boundary is not drawn twice) A silhouette line is where it touches empty space (the silhouette), where it touches a different ID, or where, even with the same ID, the occluding pixel is farther than the depth threshold plus the error margin from the occluded pixel's tangent plane (occluded silhouette). A crease line is where two neighboring normals within the same ID open wider than the crease angle. Since only normals one pixel apart are compared, no band appears around the silhouette of round surfaces or on slanted surfaces. Depth is compared as tangent plane distance, so no false lines appear on a floor seen at a grazing angle. The measured error (8-bit normal angular error x the distance between the two positions, one pixel x the sine at a crease, one 24-bit depth step) x the factor is added to the threshold, so distant things mean the same, and a low parallel step is caught even when it is lower than one pixel.
  • Thin lines (up to a width of about 3.24 pixels): in the same order as the seed pick, picks each pixel's first boundary side (one R8UI byte), and the blend looks at the seeds of the 3 x 3 surrounding pixels in the same order as the last jump flooding step to measure the distance to the nearest one. The full-screen passes are one side target and one blend. (A fraction of the passes and target bandwidth of the thick-line path on mobile tile GPUs)
  • Widening (thick lines): the distance to the boundary segments is spread with jump flooding. The step count is log2 regardless of thickness, and silhouette and crease lines are spread separately to give separate thicknesses.
  • Blending: each pixel of the drawing area is covered by clamp(thickness / 2 - distance + 0.5, 0, 1) from the distance to the nearest boundary. (Soft edges, and no stairs or dotted lines)
  • Per model: if hasScreenOutline of drawMesh is false, that model produces no line and only hides lines behind it. If hasCreaseLine is false, only crease lines are turned off.
  • Per-ID color: setLineColor gives a line color per ID. (The Unreal Custom Stencil form; a line where two IDs touch takes the color of the nearer ID, and IDs not in the table, or an empty table, keep the setColor color)
  • Thickness: the thickness of setWidth and setCrease is the thickness of one line. (Half on each side of the boundary) The unit is ToonOutlineWidthUnit, and it does not go below one pixel.
  • Depth: orthographic and perspective are told apart by the projection matrix, and depth is unpacked into view-space position for comparison. (Projections whose clip x and y were moved, like a screen rectangle, also work)
  • Value: setResolutionScale shrinks every target before the blend (the line target, the mask, the seeds, the widening targets). (At the default 1 it is the drawing area as is; below 1 a thin line computes one coverage target at the line-target resolution and blends it with one bilinear read)
  • Instances: drawMeshInstanced culls the instance array and uploads it then. drawMeshInstanceBuffer shares the ToonRenderer.createInstanceBuffer buffer with the body and does not upload it again. The ID of each instance in the buffer is read from the layout's instanceLineId slot. (The common ID if there is none)
  • Use: every frame beginLineIds(view, projection) → drawMesh / drawMeshInstanced / drawMeshInstanceBuffer → endLineIds() (computes seeds and widening) → draw the toon bodies → drawOutline(). beginLineIds notes the current viewport as the drawing area and builds the line target to fit its size. endLineIds and drawOutline restore the framebuffer, viewport and state. If handed over with ToonDrawQueue.setScreenOutline, the draw queue does this sequence by itself. (When inserted between engine 2D drawing, call Graphic.flushBatch before it)
예제Example꺾임 선 없이 실루엣만 굵게Only a thick silhouette without crease lines
import { ToonScreenOutline, ToonOutlineWidthUnit } from "./vanilla.js";
const outline = new ToonScreenOutline(document.createElement("canvas").getContext("webgl2"));
outline.setColor([0.1, 0.08, 0.12, 1]);
outline.setWidth(3, ToonOutlineWidthUnit.pixel);
outline.setCrease(180);
outline.setResolutionScale(0.5);
생성자constructorconstructor(webGL2RenderingContext, options = null)#0.4.0 부터since 0.4.0소스source

생성. (아홉 프로그램과 빈 버텍스 어레이를 짓는다, 선의 판은 첫 beginLineIds 에서)

Constructor. (Builds the nine programs and an empty vertex array; the line target is built at the first beginLineIds)

webGL2RenderingContextWebGL2RenderingContext
툰 렌더러와 같은 컨텍스트.The same context as the toon renderer.
optionsobject | null
{ colorSpace (ColorSpace, 기본은 엔진의 색 공간, ToonRenderer 와 같은 값) }{ colorSpace (ColorSpace, default is the engine's color space, the same value as ToonRenderer) }

짝Counterpart: vanilla-engine ToonScreenOutline.new

정적staticstatic readProgramSources(colorSpace = readEngineColorSpace())#0.4.0 부터since 0.4.0소스source

셰이더 소스 반환. (ShaderWarmer 로 미리 링크할 때)

Returns the shader sources. (For prelinking with ShaderWarmer)

colorSpacestring
색 공간. (ColorSpace, 기본은 엔진의 색 공간, 지을 ToonScreenOutline 과 같은 값을 준다)Color space. (ColorSpace, default is the engine's color space, give the same value the ToonScreenOutline is built with)

반환ReturnsArray<object> { vertexShader, fragmentShader, attributeLocationTable } 아홉. (번호, 씨앗, 모으기, 넓히기, 섞기, 가는 선의 씨앗 쪽 판, 가는 선 섞기, 줄인 판의 가는 선 덮는 몫, 덮는 몫 판 섞기)Nine { vertexShader, fragmentShader, attributeLocationTable }. (ID, seed, gather, widening, blending, thin-line seed side target, thin-line blending, thin-line coverage on a reduced target, coverage target blending)

짝Counterpart: vanilla-engine ToonScreenOutline.read_program_sources

예제Example셰이더를 미리 링크할 목록에 넣기Add the shaders to the list to link in advance
import { ToonScreenOutline } from "./vanilla.js";
const sources = ToonScreenOutline.readProgramSources();
const vertexShaders = sources.map((source) => source.vertexShader);
메서드methodsetColor(color)#0.4.0 부터since 0.4.0소스source

선 색 설정. (sRGB 0 ~ 1 과 알파, 바깥 선과 꺾임 선이 같이 쓴다)

Set the line color. (sRGB 0 ~ 1 and alpha, shared by silhouette and crease lines)

colorArray<number>
[r, g, b, a] 의 sRGB. (a 를 빼면 1)sRGB of [r, g, b, a]. (1 if a is omitted)

짝Counterpart: vanilla-engine ToonScreenOutline.set_color

메서드methodsetLineColor(lineId, color)#0.4.0 부터since 0.4.0소스source

번호마다 선 색 설정. (그 번호의 모형이 앞에 선 바깥 선과 꺾임 선을 이 색으로, 표에 없는 번호는 setColor 의 색 그대로)

  • 언리얼 Custom Stencil 의 후처리 바깥선처럼 선의 판에 이미 있는 번호로 색을 고른다. 고른 모형을 강조하거나 편마다 색을 달리할 때.
  • 표는 선 번호 전부(1 ~ TOON_SCREEN_OUTLINE_MAXIMUM_LINE_ID)를 덮는 128 x 128 찾기 텍스처다. 넣는 번호 수에 상한이 없고, 화소마다 한 번 읽는다.
  • 두 번호가 맞닿은 선은 앞(카메라에 가까운) 쪽 번호의 색이다. 색은 sRGB 8 비트로 담고, 알파 0 은 1/255 로 담는다. (표에 없음과 가르려고, 보이지 않는 것은 같다)

Set the line color per ID. (Silhouette and crease lines where a model with that ID is in front get this color; IDs not in the table keep the setColor color)

  • Like Unreal's Custom Stencil post-process outline, the color is picked by the ID already in the line target. For highlighting a chosen model or giving each team a different color.
  • The table is a 128 x 128 lookup texture covering every line ID (1 ~ TOON_SCREEN_OUTLINE_MAXIMUM_LINE_ID). There is no limit on how many IDs are set, and it is read once per pixel.
  • A line where two IDs touch takes the color of the front ID (closer to the camera). Colors are stored as 8-bit sRGB, and alpha 0 is stored as 1/255. (To tell it apart from not being in the table; it is just as invisible)
lineIdnumber
1 ~ TOON_SCREEN_OUTLINE_MAXIMUM_LINE_ID. (drawMesh 와 drawMeshInstanced 에 준 번호, 범위 밖이면 하지 않는다)1 ~ TOON_SCREEN_OUTLINE_MAXIMUM_LINE_ID. (The ID given to drawMesh and drawMeshInstanced; does nothing when out of range)
colorArray<number>
[r, g, b, a] 의 sRGB 0 ~ 1. (a 를 빼면 1)[r, g, b, a] in sRGB 0 ~ 1. (1 if a is omitted)

짝Counterpart: vanilla-engine ToonScreenOutline.set_line_color

예제Example가리킨 바위 하나의 선만 노랗게Make only the line of the pointed rock yellow
import { ToonRenderer, ToonScreenOutline, MeshBuilder, createOctahedronGeometry, Matrix4, Vector3 } from "./vanilla.js";
const webGL2RenderingContext = document.createElement("canvas").getContext("webgl2");
const renderer = new ToonRenderer(webGL2RenderingContext);
const outline = new ToonScreenOutline(webGL2RenderingContext);
const builder = new MeshBuilder();
builder.addPart(createOctahedronGeometry(0.3), Matrix4.createIdentity(), "#a89880", { hasOutline: false });
const rockMesh = renderer.createMesh(builder.readArrays());
const instances = [0, 1, 2].map((index) => ({ modelMatrix: Matrix4.createTranslation(index * 0.7, 0, 0), lineId: 10 + index }));
outline.setLineColor(11, [1, 0.85, 0.2, 1]);
const viewMatrix = Matrix4.createLookAt(Vector3.create(0.7, 2, 3), Vector3.create(0.7, 0, 0), Vector3.create(0, 1, 0));
const projectionMatrix = Matrix4.createPerspective(Math.PI / 4, 1, 0.1, 100);
if (outline.beginLineIds(viewMatrix, projectionMatrix)) {
	outline.drawMeshInstanced(rockMesh, instances, 10);
	outline.endLineIds();
}
renderer.beginFrameWithMatrices(viewMatrix, projectionMatrix);
renderer.drawMeshInstanced(rockMesh, instances);
renderer.endFrame();
outline.drawOutline();
메서드methodremoveLineColor(lineId)#0.4.0 부터since 0.4.0소스source

번호 하나를 색 표에서 빼기. (그 번호의 선은 setColor 의 색으로 돌아간다)

Remove one ID from the color table. (Lines of that ID go back to the setColor color)

lineIdnumber
setLineColor 에 준 번호.The ID given to setLineColor.

짝Counterpart: vanilla-engine ToonScreenOutline.remove_line_color

메서드methodclearLineColors()#0.4.0 부터since 0.4.0소스source

색 표 비우기. (모든 선이 setColor 의 색으로 돌아간다)

Clear the color table. (All lines go back to the setColor color)

짝Counterpart: vanilla-engine ToonScreenOutline.clear_line_colors

예제Example프레임마다 강조할 번호를 다시 넣기Set the IDs to highlight again every frame
import { ToonScreenOutline } from "./vanilla.js";
const outline = new ToonScreenOutline(document.createElement("canvas").getContext("webgl2"));
outline.clearLineColors();
outline.setLineColor(3, [1, 1, 1, 1]);
outline.setLineColor(7, [1, 0.3, 0.2, 1]);
const count = outline.getLineColorCount();
메서드methodgetLineColorCount()#0.4.0 부터since 0.4.0소스source

색 표에 든 번호 수 반환.

Return the number of IDs in the color table.

반환Returnsnumber setLineColor 로 넣고 빼지 않은 번호 수.The number of IDs set with setLineColor and not removed.

짝Counterpart: vanilla-engine ToonScreenOutline.get_line_color_count

메서드methodsetWidth(width, unit = ToonOutlineWidthUnit.pixel)#0.4.0 부터since 0.4.0소스source

바깥 선 굵기 설정. (실루엣과 다른 번호와 맞닿은 곳의 선, 반지름이 아니라 선 하나의 굵기, 0 이면 긋지 않음)

  • 꺾임 선 굵기도 이 단위로 센다.

Set the silhouette line thickness. (Lines at the silhouette and where a different ID touches, the thickness of one line rather than a radius, 0 draws none)

  • The crease line thickness is counted in this unit too.
widthnumber
선 하나의 굵기. (경계를 가운데로 양쪽에 반씩)Thickness of one line. (Half on each side of the boundary)
unitstring
ToonOutlineWidthUnit. (기본 pixel)ToonOutlineWidthUnit. (Default pixel)

짝Counterpart: vanilla-engine ToonScreenOutline.set_width

메서드methodsetCrease(angleDegrees, width = 1, opacity = 1)#0.4.0 부터since 0.4.0소스source

꺾임 선 설정. (같은 번호 안에서 이웃한 면이 이 각(도)보다 더 꺾이면 선, 굵기는 setWidth 의 단위, 진하기 0 ~ 1)

Set crease lines. (A line where neighboring faces within the same ID bend more than this angle (degrees), thickness in the unit of setWidth, opacity 0 ~ 1)

angleDegreesnumber
꺾임 각. (180 이면 꺾임 선을 긋지 않는다)Crease angle. (180 draws no crease lines)
widthnumber
꺾임 선 하나의 굵기. (기본 1, 0 이면 긋지 않는다)Thickness of one crease line. (Default 1, 0 draws none)
opacitynumber
꺾임 선의 진하기. (기본 1, 선 색의 알파에 곱한다)Opacity of crease lines. (Default 1, multiplied into the alpha of the line color)

짝Counterpart: vanilla-engine ToonScreenOutline.set_crease

예제Example잔 면은 두고 큰 모서리만 엷게Leave small faces and make only big edges faint
import { ToonScreenOutline } from "./vanilla.js";
const outline = new ToonScreenOutline(document.createElement("canvas").getContext("webgl2"));
outline.setCrease(75, 1.5, 0.6);
메서드methodsetFocusDistance(focusDistance)#0.4.0 부터since 0.4.0소스source

초점 거리 설정. (원근 카메라에서 월드 굵기를 픽셀로 셀 거리, 보통 카메라에서 보는 점까지, 0 이면 그린 모형들의 평균 거리)

Sets the focal distance. (Distance at which world width is converted to pixels for a perspective camera, usually from the camera to the look-at point, 0 uses the average distance of the drawn models)

focusDistancenumber
카메라에서의 거리. (월드 길이)Distance from the camera. (World length)

짝Counterpart: vanilla-engine ToonScreenOutline.set_focus_distance

메서드methodsetDepthThreshold(depthThreshold)#0.4.0 부터since 0.4.0소스source

깊이 문턱 설정. (같은 번호의 이웃 화소 가운데 가린 쪽이 가려진 쪽의 접평면에서 이만큼 넘게 떨어지면 가려진 실루엣으로 긋는다, 월드 길이)

  • depthThreshold 는 면에 수직인 거리이고, 화소 여유가 더해진다. (setDepthMargin 의 배율 x 잰 오차, 오차는 화소 크기와 면의 기울기를 따른다)
  • 장면의 크기에 맞춘다. (사람 크기 장면이면 0.02 ~ 0.1, 0 이면 오차 여유만으로 가른다)

Set the depth threshold. (If, of two neighboring pixels with the same ID, the occluding one is farther than this from the occluded one's tangent plane, an occluded silhouette is drawn, world length)

  • depthThreshold is a distance perpendicular to the face, and a pixel margin is added to it. (The setDepthMargin factor x the measured error, the error follows the pixel size and the slant of the face)
  • Match it to the scale of the scene. (0.02 ~ 0.1 for a human-sized scene, 0 separates by the error margin alone)
depthThresholdnumber
접평면 거리 문턱. (월드 길이, 면에 수직, 0 이상)Tangent plane distance threshold. (World length, perpendicular to the face, 0 or more)

짝Counterpart: vanilla-engine ToonScreenOutline.set_depth_threshold

예제Example낮은 턱까지 실루엣으로 긋기Drawing even low steps as silhouettes
import { ToonScreenOutline } from "./vanilla.js";
const outline = new ToonScreenOutline(document.createElement("canvas").getContext("webgl2"));
outline.setDepthThreshold(0.01);
console.log(outline.getDepthThreshold());
메서드methodgetDepthThreshold()#0.4.0 부터since 0.4.0소스source

깊이 문턱 반환. (월드 길이, 면에 수직)

Returns the depth threshold. (World length, perpendicular to the face)

반환Returnsnumber 접평면 거리 문턱. (월드 길이)Tangent plane distance threshold. (World length)

예제Example기본 깊이 문턱 읽기Reading the default depth threshold
import { ToonScreenOutline } from "./vanilla.js";
const outline = new ToonScreenOutline(document.createElement("canvas").getContext("webgl2"));
console.log(outline.getDepthThreshold()); // 0.05
메서드methodsetDepthMargin(depthMargin)#0.4.0 부터since 0.4.0소스source

깊이 여유 배율 설정. (깊이 문턱에 더하는 화소 여유가 잰 오차의 몇 배인지, 기본 2)

  • 이어진 면에서도 생기는 접평면 거리의 오차를 화소마다 잰다. 노멀 8 비트 팔면체의 각 오차(0.0165 rad) x 두 화소 자리 사이 거리(면이 비스듬할수록 길다), 꺾인 줄을 사이에 둔 두 화소의 화소 한 칸 x 두 노멀이 벌어진 사인, 깊이 24 비트 한 칸.
  • 두 면이 나란한 낮은 턱은 꺾임 몫이 0 이라 화소 한 칸보다 낮아도 잡힌다. 둥근 면을 굵은 다각형으로 지어 보간 노멀이 면에서 크게 벗어나는 모형에서 깊이 문턱을 아주 낮추면 잔선이 생기니, 그때 배율을 올린다.
  • 0 이면 깊이 문턱만으로 가른다.

Set the depth margin factor. (How many times the measured error the pixel margin added to the depth threshold is, default 2)

  • The error of the tangent-plane distance that appears even on connected surfaces is measured per pixel: the angular error of the 8-bit octahedral normal (0.0165 rad) x the distance between the two pixel positions (longer the more slanted the face), one pixel x the sine of the angle between the two normals for two pixels on either side of a crease, and one step of the 24-bit depth.
  • A low step between two parallel faces has no crease term, so it is caught even when it is lower than one pixel. On models that build round surfaces from coarse polygons, where the interpolated normal strays far from the face, lowering the depth threshold a lot produces stray lines, so raise the factor then.
  • 0 separates by the depth threshold alone.
depthMarginnumber
잰 오차에 곱할 배율. (0 이상)Factor to multiply the measured error by. (0 or more)

짝Counterpart: vanilla-engine ToonScreenOutline.set_depth_margin

예제Example여유를 줄여 낮은 턱을 더 잡기Reducing the margin to catch more low steps
import { ToonScreenOutline } from "./vanilla.js";
const outline = new ToonScreenOutline(document.createElement("canvas").getContext("webgl2"));
outline.setDepthThreshold(0.02);
outline.setDepthMargin(1);
console.log(outline.getDepthMargin()); // 1
메서드methodgetDepthMargin()#0.4.0 부터since 0.4.0소스source

깊이 여유 배율 반환.

Returns the depth margin factor.

반환Returnsnumber 잰 오차에 곱할 배율.Factor to multiply the measured error by.

예제Example기본 깊이 여유 배율 읽기Reading the default depth margin factor
import { ToonScreenOutline } from "./vanilla.js";
const outline = new ToonScreenOutline(document.createElement("canvas").getContext("webgl2"));
console.log(outline.getDepthMargin()); // 2
메서드methodsetResolutionScale(resolutionScale)#0.4.0 부터since 0.4.0소스source

선의 판 해상도 몫 설정. (그리는 영역에 대한 몫 0.25 ~ 1, 기본 1, 폰과 태블릿의 가벼운 길은 낮춘다)

  • 이름대로 섞기 앞의 모든 판(선의 판 = 노멀과 번호와 깊이, 가면, 씨앗, 넓히기 판)을 그리는 영역 x 몫 크기로 잡는다. 선의 판은 몫만큼 작은 해상도로 한 번 더 그려지므로 값이 몫의 제곱으로 준다. 기본 1 은 그리는 영역과 같은 크기라 화면이 바이트까지 그대로다.
  • 몫이 1 보다 작을 때 가는 선(굵기 x 몫이 약 3.24 선의 판 픽셀 이하)은 선의 판 해상도에서 덮는 몫(진하기와 번호 색을 곱한 RGBA8)을 한 번 셈하고, 마지막 섞기가 그것을 쌍선형으로 한 번 읽는다. (읽기 9 에서 1) 굵은 선은 선의 판 해상도에서 점프 플러딩을 하고 섞을 때 거리를 그리는 영역 픽셀로 곱해 잰다. 어느 길이든 선 굵기는 그리는 영역 픽셀(setWidth)이고 선 자리는 몫이 작을수록 가장자리가 부드러워진다.
  • getLineTarget() 의 lineTexture, depthTexture 해상도는 그리는 영역 x 몫이다. (광부의 lineTexture 약속 RGBA8, b 와 a 아래 6 비트 번호, a 위 2 비트 깃발, 굵기 0 이면 선의 판만은 그대로, 해상도만 그리는 영역과 다를 수 있다)
  • CSS 화소당 1.5 화소로 맞추려면 몫 = 1.5 / (그리는 버퍼 화소 / CSS 화소) 로 준다. 엔진 해상도 설정이 그리는 버퍼를 묶어 devicePixelRatio 와 다를 수 있어 캔버스의 width / clientWidth 로 센다.

Set the resolution fraction of the line target. (Fraction of the drawing area 0.25 ~ 1, default 1, lowered on the light path for phones and tablets)

  • As the name says, every target before the blend (the line target = normals, IDs and depth, the mask, the seeds, the widening targets) is built at drawing area x fraction. The line target is drawn once more at that smaller resolution, so the cost falls by the square of the fraction. The default 1 is the same size as the drawing area, so the screen is byte for byte the same.
  • Below 1, a thin line (width x fraction up to about 3.24 line-target pixels) computes its coverage (strength times the ID color, RGBA8) once at the line-target resolution, and the final blend reads it once with bilinear filtering. (Nine reads become one) A thick line floods at the line-target resolution and measures the distance in drawing area pixels when blending. At any scale the line width (setWidth) is in drawing area pixels, and the smaller the fraction the softer the edges.
  • The lineTexture and depthTexture of getLineTarget() are drawing area x fraction in size. (The lineTexture contract of the miner stays: RGBA8, the ID in b and the low 6 bits of a, flags in the top 2 bits of a, and width 0 draws only the line target; only the resolution may differ from the drawing area)
  • To match 1.5 pixels per CSS pixel, pass 1.5 / (buffer pixels per CSS pixel). Since the engine resolution setting may bundle the buffer and differ from devicePixelRatio, count it as the canvas width / clientWidth.
resolutionScalenumber
0.25 ~ 1. (1 이면 그리는 영역 해상도 그대로)0.25 ~ 1. (1 keeps the drawing area resolution)

짝Counterpart: vanilla-engine ToonScreenOutline.set_resolution_scale

예제ExampleCSS 화소당 선의 판 1.5 화소로 맞추기Match 1.5 line-target pixels per CSS pixel
import { ToonScreenOutline } from "./vanilla.js";
const canvas = document.createElement("canvas");
canvas.width = 750;
canvas.height = 990;
canvas.style.width = "375px";
const outline = new ToonScreenOutline(canvas.getContext("webgl2"));
const bufferPixelPerCssPixel = canvas.width / 375;
outline.setResolutionScale(1.5 / bufferPixelPerCssPixel);
메서드methodsetHdrOutput(isHdrOutput)#0.4.0 부터since 0.4.0소스source

HDR 출력 설정. (true 면 선 색을 선형으로 바꿔 섞는다, ToonRenderer.setHdrOutput 과 맞춘다)

Sets HDR output. (true converts the line color to linear before blending, match with ToonRenderer.setHdrOutput)

isHdrOutputboolean
true 면 선 색을 선형으로 바꿔 섞는다.If true, the line color is converted to linear before blending.

짝Counterpart: vanilla-engine ToonScreenOutline.set_hdr_output

메서드methodgetColorSpace()#0.4.0 부터since 0.4.0소스source

색 공간 반환. (생성 때 정한 값, HDR 출력에서 선 색을 선형으로 바꾸는 곡선, gamma 는 pow 2.2, linear 는 sRGB 표준 곡선)

Returns the color space. (Set at construction, the curve that converts line color to linear for HDR output, pow 2.2 for gamma, the sRGB standard curve for linear)

반환Returnsstring ColorSpace.gamma 나 ColorSpace.linear.ColorSpace.gamma or ColorSpace.linear.

짝Counterpart: vanilla-engine ToonScreenOutline.get_color_space

예제Example렌더러와 같은 색 공간으로 지은 화면 바깥선Screen outline built with the same color space as the renderer
import { ToonRenderer, ToonScreenOutline, ColorSpace } from "./vanilla.js";
const webGL2RenderingContext = document.createElement("canvas").getContext("webgl2");
const renderer = new ToonRenderer(webGL2RenderingContext);
const screenOutline = new ToonScreenOutline(webGL2RenderingContext, { colorSpace: renderer.getColorSpace() });
if (screenOutline.getColorSpace() !== ColorSpace.gamma) {
	throw new Error("default color space is not gamma");
}
메서드methodgetLineWidths()#0.4.0 부터since 0.4.0소스source

이번 프레임의 선 굵기 반환. ([바깥 선, 꺾임 선] 의 그리는 영역 픽셀, endLineIds 뒤에 정해짐)

Return this frame's line thickness. (Drawing area pixels of [silhouette line, crease line], decided after endLineIds)

반환ReturnsArray<number> [바깥 선 굵기, 꺾임 선 굵기]. (긋지 않으면 0)[silhouette line thickness, crease line thickness]. (0 if not drawn)

짝Counterpart: vanilla-engine ToonScreenOutline.get_line_widths

메서드methodgetLineTarget()#0.4.0 부터since 0.4.0소스source

선의 판 반환. (없으면 null)

Return the line target. (null if none)

반환Returnsobject | null { lineTexture (노멀과 번호 RGBA8), depthTexture (깊이 24), edgeMaskTexture (가는 선의 씨앗 쪽 판 R8UI, 아래 3 비트 바깥 선, 위 3 비트 꺾임 선의 첫 경계 쪽 0 없음, 1 오른쪽, 2 왼쪽, 3 위, 4 아래), seedTexture (온 해상도 씨앗 RGBA16UI, 굵은 선을 긋기 전에는 null), jumpFloodTextures (넓히기 판 RGBA16UI 둘, 굵은 선을 긋기 전에는 빔), jumpFloodIndex (넓히기를 마친 쪽, 점프 플러딩을 안 했으면 -1), coverageTexture (선의 판을 줄였을 때 가는 선의 덮는 몫 RGBA8 곱한 색, 줄여 가는 선을 그을 때 짓기 전에는 null), outlinePath (이번 프레임의 길 "none", "thin", "thinScaled", "jumpFlood"), width, height (선의 판 해상도, 그리는 영역 x setResolutionScale 의 몫), jumpFloodWidth, jumpFloodHeight (선의 판과 같다) }{ lineTexture (normal and ID RGBA8), depthTexture (depth 24), edgeMaskTexture (thin-line seed side target R8UI, low 3 bits contour and next 3 bits crease first edge side, 0 none, 1 right, 2 left, 3 up, 4 down), seedTexture (seeds at the line-target resolution RGBA16UI, null until a thick line is drawn), jumpFloodTextures (two widening targets RGBA16UI, empty until a thick line is drawn), jumpFloodIndex (the side that finished widening, -1 when jump flooding did not run), coverageTexture (coverage of a thin line when the line target is reduced, RGBA8 premultiplied color, null until a reduced thin line is drawn), outlinePath (this frame's path "none", "thin", "thinScaled", "jumpFlood"), width, height (line-target resolution, drawing area x the fraction of setResolutionScale), jumpFloodWidth, jumpFloodHeight (same as the line target) }

짝Counterpart: vanilla-engine ToonScreenOutline.get_line_target

메서드methodbeginLineIds(viewMatrix, projectionMatrix)#0.4.0 부터since 0.4.0소스source

번호 그리기 시작. (지금 뷰포트를 그리는 영역으로 적고, 선의 판을 묶어 비운다)

Begins drawing IDs. (Records the current viewport as the drawing area, binds and clears the line target)

viewMatrixMatrix4
보기 행렬.View matrix.
projectionMatrixMatrix4
투영 행렬. (원근이나 직교)Projection matrix. (Perspective or orthographic)

반환Returnsboolean 선의 판을 짓지 못했으면 false. (그때 drawMesh 는 아무것도 하지 않는다)false if the line target could not be built. (drawMesh then does nothing)

짝Counterpart: vanilla-engine ToonScreenOutline.begin_line_ids

메서드methoddrawMesh(mesh, modelMatrix, lineId, options = {})#0.4.0 부터since 0.4.0소스source

모형 하나의 번호 그리기. (ToonRenderer.drawMesh 와 같은 행렬과 자세, 화면 밖이면 건너뛴다)

Draws IDs for one model. (Same matrices and pose as ToonRenderer.drawMesh, skipped if off-screen)

meshobject | null
ToonRenderer.createMesh 의 결과.Result of ToonRenderer.createMesh.
modelMatrixMatrix4
모형 행렬.Model matrix.
lineIdnumber
1 ~ TOON_SCREEN_OUTLINE_MAXIMUM_LINE_ID. (0 은 빈 곳이라 쓰지 않는다, 같은 번호끼리 맞닿은 곳은 긋지 않는다)1 ~ TOON_SCREEN_OUTLINE_MAXIMUM_LINE_ID. (0 is empty space and not used, no line where the same IDs touch)
optionsobject
{ jointMatrices Float32Array, isCulled (기본 true), indexStart, indexCount (몸 번호 버퍼의 일부만), isMirrored (주지 않으면 행렬식으로), hasScreenOutline (기본 true, false 면 선은 내지 않고 가리기만), hasCreaseLine (기본 true) }{ jointMatrices Float32Array, isCulled (default true), indexStart, indexCount (only part of the body index buffer), isMirrored (from the determinant if not given), hasScreenOutline (default true, false only hides without producing lines), hasCreaseLine (default true) }

짝Counterpart: vanilla-engine ToonScreenOutline.draw_mesh

예제Example바닥은 선 없이 가리기만, 결정은 꺾임 선 없이The floor only hides without lines, the crystals without crease lines
import { ToonRenderer, ToonScreenOutline, MeshBuilder, createBoxGeometry, createOctahedronGeometry, Matrix4, Vector3 } from "./vanilla.js";
const webGL2RenderingContext = document.createElement("canvas").getContext("webgl2");
const renderer = new ToonRenderer(webGL2RenderingContext);
const outline = new ToonScreenOutline(webGL2RenderingContext);
const floorBuilder = new MeshBuilder();
floorBuilder.addPart(createBoxGeometry(6, 0.2, 6), Matrix4.createTranslation(0, -0.1, 0), "#506070", { hasOutline: false });
const floorMesh = renderer.createMesh(floorBuilder.readArrays());
const crystalBuilder = new MeshBuilder();
crystalBuilder.addPart(createOctahedronGeometry(0.5), Matrix4.createTranslation(0, 0.5, 0), "#90d0ff", { hasOutline: false });
const crystalMesh = renderer.createMesh(crystalBuilder.readArrays());
const viewMatrix = Matrix4.createLookAt(Vector3.create(3, 3, 4), Vector3.create(0, 0, 0), Vector3.create(0, 1, 0));
const projectionMatrix = Matrix4.createPerspective(Math.PI / 4, 1, 0.1, 100);
if (outline.beginLineIds(viewMatrix, projectionMatrix)) {
	outline.drawMesh(floorMesh, Matrix4.createIdentity(), 1, { hasScreenOutline: false });
	outline.drawMesh(crystalMesh, Matrix4.createIdentity(), 2, { hasCreaseLine: false });
	outline.endLineIds();
}
메서드methoddrawMeshInstanced(mesh, instances, lineId, options = {})#0.4.0 부터since 0.4.0소스source

같은 모형 여럿의 번호를 한 번에 그리기. (인스턴스에 lineId 가 있으면 그 번호, 없으면 공통 번호)

Draws IDs for multiple instances of the same model at once. (Uses the instance's lineId if present, otherwise the common ID)

meshobject | null
ToonRenderer.createMesh 의 결과.Result of ToonRenderer.createMesh.
instancesArray<object>
{ modelMatrix: Matrix4, lineId: number (선택) } 의 배열.Array of { modelMatrix: Matrix4, lineId: number (optional) }.
lineIdnumber
공통 번호.Common ID.
optionsobject
drawMesh 와 같다. (꼴은 모든 인스턴스에 같다)Same as drawMesh. (The options are the same for all instances)

짝Counterpart: vanilla-engine ToonScreenOutline.draw_mesh_instanced

예제Example돌마다 다른 번호로 맞닿은 곳에도 선A different ID per stone so lines appear where they touch too
import { ToonRenderer, ToonScreenOutline, MeshBuilder, createOctahedronGeometry, Matrix4, Vector3 } from "./vanilla.js";
const webGL2RenderingContext = document.createElement("canvas").getContext("webgl2");
const renderer = new ToonRenderer(webGL2RenderingContext);
const outline = new ToonScreenOutline(webGL2RenderingContext);
const builder = new MeshBuilder();
builder.addPart(createOctahedronGeometry(0.3), Matrix4.createIdentity(), "#a89880", { hasOutline: false });
const rockMesh = renderer.createMesh(builder.readArrays());
const instances = [0, 1, 2].map((index) => ({ modelMatrix: Matrix4.createTranslation(index * 0.5, 0, 0), lineId: 10 + index }));
const viewMatrix = Matrix4.createLookAt(Vector3.create(0.5, 2, 3), Vector3.create(0.5, 0, 0), Vector3.create(0, 1, 0));
const projectionMatrix = Matrix4.createPerspective(Math.PI / 4, 1, 0.1, 100);
if (outline.beginLineIds(viewMatrix, projectionMatrix)) {
	outline.drawMeshInstanced(rockMesh, instances, 10);
	outline.endLineIds();
}
메서드methoddrawMeshInstanceBuffer(mesh, instanceBuffer, instanceCount, lineId, options = {})#0.4.0 부터since 0.4.0소스source

영구 인스턴스 버퍼로 번호 그리기. (몸과 같은 GPU 버퍼를 쓰고 다시 올리지 않는다, 버퍼 전체의 경계로 통째 거른다)

  • 인스턴스마다 번호는 꼴의 instanceLineId 칸, 없으면 공통 번호. 꼴에 행렬이 없으면 자리를 몰라 그리지 않는다. (정점 조각은 선의 판에서 돌지 않는다)

Draws IDs with a persistent instance buffer. (Uses the same GPU buffer as the body and does not upload it again, culled as a whole by the bounds of the entire buffer)

  • The ID of each instance is the layout's instanceLineId slot, otherwise the common ID. If the layout has no matrix the position is unknown and it is not drawn. (Vertex chunks do not run in the line target)
meshobject | null
ToonRenderer.createMesh 의 결과.Result of ToonRenderer.createMesh.
instanceBufferobject
ToonRenderer.createInstanceBuffer 의 결과. (지은 렌더러의 버텍스 어레이를 같이 쓴다)The result of ToonRenderer.createInstanceBuffer. (Shares the vertex arrays of the renderer that built it)
instanceCountnumber
그릴 인스턴스 수. (버퍼에 든 수를 넘으면 자른다)Number of instances to draw. (Clamped if more than the buffer holds)
lineIdnumber
공통 번호. (꼴에 instanceLineId 가 없을 때)Common ID. (When the layout has no instanceLineId)
optionsobject
drawMesh 와 같다. (꼴은 모든 인스턴스에 같다)Same as drawMesh. (The options are the same for all instances)

짝Counterpart: vanilla-engine ToonScreenOutline.draw_mesh_instance_buffer

예제Example돌 버퍼 하나로 몸과 선의 판을 같이 그리기Draw the body and line target together with one rock buffer
import { ToonRenderer, ToonScreenOutline, MeshBuilder, createOctahedronGeometry, Matrix4, Vector3 } from "./vanilla.js";
const webGL2RenderingContext = document.createElement("canvas").getContext("webgl2");
const renderer = new ToonRenderer(webGL2RenderingContext);
const outline = new ToonScreenOutline(webGL2RenderingContext);
const builder = new MeshBuilder();
builder.addPart(createOctahedronGeometry(0.3), Matrix4.createIdentity(), "#a89880", { hasOutline: false });
const rockMesh = renderer.createMesh(builder.readArrays());
const instanceLayout = renderer.createInstanceLayout([{ name: "instanceMatrix", size: 16 }, { name: "instanceTint", size: 4 }, { name: "instanceLineId", size: 1 }]);
const data = new Float32Array(21 * 3);
for (let index = 0; index < 3; ++index) {
	data.set(Matrix4.createTranslation(index * 0.5, 0, 0).getElements(), index * 21);
	data.set([1, 1, 1, 1, 10 + index], index * 21 + 16);
}
const instanceBuffer = renderer.createInstanceBuffer(instanceLayout, data);
const viewMatrix = Matrix4.createLookAt(Vector3.create(0.5, 2, 3), Vector3.create(0.5, 0, 0), Vector3.create(0, 1, 0));
const projectionMatrix = Matrix4.createPerspective(Math.PI / 4, 1, 0.1, 100);
if (outline.beginLineIds(viewMatrix, projectionMatrix)) {
	outline.drawMeshInstanceBuffer(rockMesh, instanceBuffer, 3, 10);
	outline.endLineIds();
}
renderer.beginFrameWithMatrices(viewMatrix, projectionMatrix);
renderer.drawMeshInstanceBuffer(rockMesh, instanceBuffer, 3);
renderer.endFrame();
outline.drawOutline();
메서드methoddrawWithCount(mesh, modelElements, instanceCount, lineId, lineIdSource, isMirrored, options, vertexArray)#0.4.0 부터since 0.4.0소스source

번호 그리기 본체.

Core of ID drawing.

meshobject
ToonRenderer.createMesh 의 결과.Result of ToonRenderer.createMesh.
modelElementsFloat32Array
모형 행렬의 수 16.The 16 numbers of the model matrix.
instanceCountnumber
0 이면 보통 그리기.0 means normal drawing.
lineIdnumber
공통 번호.Common ID.
lineIdSourcenumber
번호를 읽을 곳. (0 공통 번호, 1 틴트 칸의 x, 2 인스턴스 버퍼의 instanceLineId)Where to read the ID. (0 common ID, 1 the x of the tint slot, 2 the instance buffer's instanceLineId)
isMirroredboolean
감기를 뒤집어 그릴지.Whether to draw with the winding flipped.
optionsobject
drawMesh 의 꼴.Options of drawMesh.
vertexArrayWebGLVertexArrayObject
그릴 버텍스 어레이. (모형의 몸이나 모형과 인스턴스 버퍼를 묶은 것)Vertex array to draw. (The model's body, or the model bound with an instance buffer)
메서드methodendLineIds()#0.4.0 부터since 0.4.0소스source

번호 그리기 끝. (가는 선은 씨앗 쪽 판 하나를 고르고, 굵은 선은 씨앗을 고르고 점프 플러딩으로 넓힌 뒤, 프레임버퍼와 뷰포트와 상태를 돌린다)

  • 가는 선(굵기가 THIN_LINE_MAXIMUM_WIDTH 이하, 약 3.24 픽셀까지): 화면 전체 패스가 씨앗 쪽 판 하나다. 섞기가 둘레 3 x 3 화소의 씨앗을 본다. (씨앗, 모으기, 넓히기 없음)
  • 굵은 선: 씨앗, 모으기, 넓히기 걸음마다 한 패스. (씨앗 판과 넓히기 판은 처음 굵은 선을 그을 때 짓는다)
  • 판을 통째로 덮어쓰는 패스는 앞에 판 비우기(clearBufferuiv, clearBufferfv)를 불러 옛 내용을 읽어 들이지 않게 한다. (타일 GPU 의 판 불러오기를 없앰, invalidateFramebuffer 는 아이패드와 아이폰 사파리에서 프레임마다 약 10 ~ 25 ms 가 붙어 쓰지 않는다)

End ID drawing. (Thin lines pick one seed side target, thick lines pick seeds and widen them with jump flooding, then restores the framebuffer, viewport and state)

  • Thin lines (width at most THIN_LINE_MAXIMUM_WIDTH, about 3.24 pixels): one full-screen pass for the seed side target. The composite looks at the seeds of the surrounding 3 x 3 pixels. (No seed, gather or widening)
  • Thick lines: one pass each for seed, gather and every widening step. (The seed and widening targets are built the first time a thick line is drawn)
  • Passes that overwrite a whole target clear it first (clearBufferuiv, clearBufferfv) so the old contents are not loaded. (Removes target loads on tile GPUs; invalidateFramebuffer is not used because it added about 10 to 25 ms per frame in iPad and iPhone Safari)

짝Counterpart: vanilla-engine ToonScreenOutline.end_line_ids

메서드methoddrawOutline()#0.4.0 부터since 0.4.0소스source

바깥선 긋기. (가는 선은 씨앗 쪽 판, 굵은 선은 넓힌 씨앗 판으로 beginLineIds 때의 그리는 영역에 섞는다, 깊이는 보지도 쓰지도 않는다, 스텐실은 그대로)

Draw the outline. (Blends into the drawing area of beginLineIds with the seed side target for thin lines and the widened seed target for thick lines, neither reads nor writes depth, stencil untouched)

짝Counterpart: vanilla-engine ToonScreenOutline.draw_outline

메서드methodreadLineWidths()#0.4.0 부터since 0.4.0소스source

이번 프레임의 선 굵기 셈. ([바깥 선, 꺾임 선] 의 그리는 영역 픽셀, 0 이 아니면 한 픽셀 밑으로 내리지 않음)

Compute this frame's line thickness. (Drawing area pixels of [silhouette line, crease line], not below one pixel unless 0)

반환ReturnsArray<number> [바깥 선 굵기, 꺾임 선 굵기].[silhouette line thickness, crease line thickness].

짝Counterpart: vanilla-engine ToonScreenOutline.read_line_widths

메서드methodaddDrawnDistance(mesh, modelElements)#0.4.0 부터since 0.4.0소스source

그린 모형의 거리 더하기. (초점 거리를 주지 않은 원근에서 쓴다, 보기 공간의 앞쪽 거리)

Adds a drawn model's distance. (Used in perspective when no focal distance is given, forward distance in view space)

meshobject
ToonRenderer.createMesh 의 결과.Result of ToonRenderer.createMesh.
modelElementsFloat32Array
모형 행렬의 수 16.The 16 numbers of the model matrix.
메서드methodisVisible(mesh, modelElements)#0.4.0 부터since 0.4.0소스source

경계 구가 이번 프레임의 절두체 안에 드는지.

Whether the bounding sphere is inside this frame's frustum.

meshobject
ToonRenderer.createMesh 의 결과.Result of ToonRenderer.createMesh.
modelElementsFloat32Array
모형 행렬의 수 16.The 16 numbers of the model matrix.

반환Returnsboolean 절두체 안에 들면 true.true if inside the frustum.

메서드methodreadLineTarget(width, height, jumpFloodWidth, jumpFloodHeight)#0.4.0 부터since 0.4.0소스source

선의 판 읽기. (크기가 바뀌면 다시 지음, 그리는 영역 해상도의 노멀과 번호 RGBA8, 깊이 24, 씨앗 RGBA16UI 와 넓히기 판 RGBA16UI 둘, 짓지 못하면 null)

Read the line target. (Rebuilt if the size changes, normal and ID RGBA8 at drawing area resolution, depth 24, seeds RGBA16UI and two widening targets RGBA16UI, null if it could not be built)

widthnumber
선의 판 너비. (그리는 영역 픽셀)Width of the line target. (Drawing area pixels)
heightnumber
선의 판 높이.Height of the line target.
jumpFloodWidthnumber
넓히기 판 너비.Width of the widening target.
jumpFloodHeightnumber
넓히기 판 높이.Height of the widening target.

반환Returnsobject | null 선의 판. (짓지 못하면 null)The line target. (null if it could not be built)

메서드methoddeleteLineTarget()#0.4.0 부터since 0.4.0소스source

선의 판 지우기.

Deletes the line target.

메서드methodsaveState()#0.4.0 부터since 0.4.0소스source

그리기 상태 적어 두기.

Records the draw state.

메서드methodrestoreState()#0.4.0 부터since 0.4.0소스source

적어 둔 상태로 돌리기.

Restores the recorded state.

메서드methoddestroy()#0.4.0 부터since 0.4.0소스source

다 쓴 뒤 지우기. (선의 판, 버텍스 어레이, 프로그램 일곱)

Delete after use. (Line target, vertex array, seven programs)

짝Counterpart: vanilla-engine ToonScreenOutline.destroy

함수Functions

함수functionreadJumpFloodSteps(reach)#0.4.0 부터since 0.4.0소스source

점프 플러딩의 걸음 목록. (씨앗을 reach 화소까지 넓히는 데 드는 걸음, 큰 것부터 반씩 줄여 1 까지)

  • 걸음 k, k/2, ..., 1 은 씨앗을 2k - 1 화소까지 옮긴다. (Rong, Tan 2006)

Step list of jump flooding. (Steps needed to widen seeds up to reach pixels, halving from the largest down to 1)

  • Steps k, k/2, ..., 1 carry a seed up to 2k - 1 pixels. (Rong, Tan 2006)
reachnumber
씨앗을 옮길 거리. (선의 판 픽셀)Distance to carry the seeds. (Line target pixels)

반환ReturnsArray<number> 큰 것부터 1 까지의 걸음.Steps from the largest down to 1.

짝Counterpart: vanilla-engine read_jump_flood_steps

예제Example4 화소까지 넓히는 걸음Steps to widen up to 4 pixels
import { readJumpFloodSteps } from "./vanilla.js";
const steps = readJumpFloodSteps(4);

상수Constants

상수constantTOON_SCREEN_OUTLINE_MAXIMUM_LINE_ID = 16383#0.4.0 부터since 0.4.0소스source

선 번호의 상한. (선의 판에 14 비트로 쓴다, 0 은 빈 곳)

Upper limit of line IDs. (Written into the line target in 14 bits, 0 is empty space)

반환Returnsnumber

짝Counterpart: vanilla-engine TOON_SCREEN_OUTLINE_MAXIMUM_LINE_ID

ToonOutlineWidthUnitenum

짝Counterpart: vanilla-engine ToonOutlineWidthUnit

굵기의 단위.

  • world: 월드 길이. (직교는 투영의 세로 배율로, 원근은 초점 거리에서 화면 픽셀로 셈해 멀수록 가늘어진다)
  • pixel: 그리는 영역의 픽셀. (거리와 상관없이 같은 굵기)

Unit of thickness.

  • world: world length. (Orthographic uses the vertical scale of the projection, perspective converts to screen pixels at the focal distance so it gets thinner farther away)
  • pixel: pixels of the drawing area. (Same thickness regardless of distance)
예제Example월드 길이로 굵기 주기Give the thickness in world length
import { ToonScreenOutline, ToonOutlineWidthUnit } from "./vanilla.js";
const outline = new ToonScreenOutline(document.createElement("canvas").getContext("webgl2"));
outline.setWidth(0.02, ToonOutlineWidthUnit.world);
outline.setFocusDistance(6);
이름Name값Value설명Description
worldworld월드 길이. (멀수록 가늘어진다)World length. (Thinner farther away)
pixelpixel그리는 영역의 픽셀. (거리와 상관없이 같은 굵기)Pixels of the drawing area. (Same thickness regardless of distance)