vanilladocs
vanillapunch.com
API / graphics3d/shadowmap

graphics3d/shadowmap

섀도우 맵. (방향광 실시간 그림자, 깊이 텍스처 + 직교 광원 행렬)

Shadow map. (directional light real-time shadows, depth texture + orthographic light matrix)

ShadowMapextends Object

짝Counterpart: vanilla-engine ShadowMap

섀도우 맵. (방향광 실시간 그림자, 깊이 텍스처 + 직교 광원 행렬)

  • beginRender() 로 깊이 패스를 시작하고, 결과 텍스처를 본 패스에서 샘플링한다.
  • 광원 행렬은 텍셀 단위로 스냅해 이동 시 그림자 가장자리 떨림을 줄인다.
  • 지을 때 앞의 텍스처와 프레임버퍼 묶음을 돌린다. (모형을 지은 뒤에 지어도 깊이 텍스처가 텍스처 유닛에 남아 그리기가 INVALID_OPERATION 이 되지 않게)

Shadow map. (Real-time directional light shadow, depth texture + orthographic light matrix)

  • beginRender() starts the depth pass, and the resulting texture is sampled in the main pass.
  • The light matrix is snapped to texels to reduce shadow edge shimmering when moving.
  • Restores the previous texture and framebuffer bindings when built. (So that building it after models does not leave the depth texture on a texture unit and turn drawing into INVALID_OPERATION)
예제Example깊이 패스로 그림자를 굽고 본 패스에서 받기Bake shadows in a depth pass and receive them in the main pass
import { ShadowMap, SkinnedModel, SkinnedModelRenderer, Camera3D, Matrix4, Vector3 } from "./build/vanilla.js";

const width = 640;
const height = 360;
const canvas = document.createElement("canvas");
canvas.width = width;
canvas.height = height;
document.body.appendChild(canvas);
const webGL2RenderingContext = canvas.getContext("webgl2");
const shadowMap = new ShadowMap(webGL2RenderingContext, 1024);
const skinnedModelRenderer = new SkinnedModelRenderer(webGL2RenderingContext);
const skinnedModel = await SkinnedModel.loadFromUrl(webGL2RenderingContext, "examples/ancientmountain/assets/fox.glb", skinnedModelRenderer);
skinnedModel.update(0);
const modelMatrix = Matrix4.createIdentity();
const modelMatrixElements = modelMatrix.getElements();

const focusPosition = Vector3.create(0, 40, 0);
const lightDirection = Vector3.create(-0.45, -0.76, -0.47);
shadowMap.updateLightMatrix(focusPosition, lightDirection, 150, 1, 600);
const lightViewProjectionMatrix = shadowMap.getLightViewProjectionMatrix();
const lightViewProjectionElements = lightViewProjectionMatrix.getElements();
shadowMap.beginRender();
skinnedModelRenderer.drawDepth(skinnedModel, lightViewProjectionElements, modelMatrixElements);

const depthTexture = shadowMap.getDepthTexture();
const resolution = shadowMap.getResolution();
skinnedModelRenderer.setShadowMap(depthTexture, lightViewProjectionElements, 1 / resolution);
skinnedModelRenderer.setShadowStrength(0.8);
skinnedModelRenderer.setSunDirection(0.45, 0.76, 0.47);
const cameraX = 0;
const cameraY = 80;
const cameraZ = 220;
const camera = new Camera3D();
camera.setPerspective(Math.PI / 3, 1, 2000);
camera.setAspectRatio(width / height);
const eyePosition = Vector3.create(cameraX, cameraY, cameraZ);
const targetPosition = Vector3.create(0, 45, 0);
camera.lookAt(eyePosition, targetPosition);
const viewProjectionMatrix = camera.getViewProjectionMatrix();
const viewProjectionElements = viewProjectionMatrix.getElements();
webGL2RenderingContext.bindFramebuffer(webGL2RenderingContext.FRAMEBUFFER, null);
webGL2RenderingContext.viewport(0, 0, width, height);
webGL2RenderingContext.clearColor(0.16, 0.2, 0.26, 1);
webGL2RenderingContext.clear(webGL2RenderingContext.COLOR_BUFFER_BIT | webGL2RenderingContext.DEPTH_BUFFER_BIT);
skinnedModelRenderer.draw(skinnedModel, viewProjectionElements, modelMatrixElements, cameraX, cameraY, cameraZ);
생성자constructorconstructor(webGL2RenderingContext, resolution = 2048)#0.3.0 부터since 0.3.0소스source

생성.

Constructor.

webGL2RenderingContextWebGL2RenderingContext
WebGL2 렌더링 컨텍스트.WebGL2 rendering context.
resolutionnumber
깊이 텍스처 한 변의 크기. (픽셀, 기본 2048)Side length of the depth texture. (pixels, default 2048)

짝Counterpart: vanilla-engine ShadowMap.new

메서드methodupdateLightMatrix(focusPosition, lightDirection, extent, nearDistance, farDistance)#0.3.0 부터since 0.3.0소스source

광원 행렬 갱신. (초점 주변을 덮는 직교 투영, 텍셀 스냅, 빛이 거의 바로 위나 아래로 나아가면 위쪽을 z 축으로 잡아 행렬이 깨지지 않게)

Update the light matrix. (Orthographic projection covering the area around the focus, texel snap, the up direction becomes the z axis when the light travels almost straight up or down so the matrix does not break)

focusPositionVector3
그림자를 덮을 가운데 월드 자리.World position at the center of the shadow coverage.
lightDirectionVector3
빛이 나아가는 방향.Direction the light travels.
extentnumber
초점 기준 절반 커버 범위.Half coverage extent around the focus.
nearDistancenumber
광원 직교 투영의 가까운 거리. (월드 단위)Near distance of the light's orthographic projection. (world units)
farDistancenumber
광원 직교 투영의 먼 거리. (월드 단위, 광원 눈은 초점에서 빛 반대쪽으로 (가까운 거리 + 먼 거리) / 2 만큼 떨어진다)Far distance of the light's orthographic projection. (world units, the light eye sits (near distance + far distance) / 2 away from the focus, against the light direction)

짝Counterpart: vanilla-engine ShadowMap.update_light_matrix

예제Example움직이는 초점을 따라가는 광원 행렬Light matrix that follows a moving focus
import { ShadowMap, Vector3 } from "./build/vanilla.js";

const canvas = document.createElement("canvas");
const webGL2RenderingContext = canvas.getContext("webgl2");
const shadowMap = new ShadowMap(webGL2RenderingContext, 2048);
const playerPosition = Vector3.create(12, 0, -4);
const sunTravelDirection = Vector3.create(-0.4, -1.0, -0.3);
shadowMap.updateLightMatrix(playerPosition, sunTravelDirection, 30, 0.5, 200);
const lightViewProjectionMatrix = shadowMap.getLightViewProjectionMatrix();
const clipPoint = lightViewProjectionMatrix.transformPoint(12, 0, -4);
console.log(clipPoint.x, clipPoint.y, clipPoint.z);
shadowMap.destroy();
메서드methodbeginRender()#0.3.0 부터since 0.3.0소스source

깊이 패스 시작. (프레임버퍼 바인드 + 뷰포트 + 깊이 클리어, ToonDrawQueue 가 캐시를 쓸 때는 구운 판에 그리거나 구운 판을 옮겨 그 위에 덧그린다)

Start the depth pass. (Binds the framebuffer, sets the viewport and clears depth, when ToonDrawQueue uses the cache it draws into the baked target or copies the baked target and draws on top)

짝Counterpart: vanilla-engine ShadowMap.begin_render

메서드methodsetUpdateMode(updateMode, updateInterval = 1)#0.4.0 부터since 0.4.0소스source

그림자를 다시 그리는 방식 정하기. (ToonDrawQueue 가 따른다, 기본 ShadowUpdateMode.onChange, 정하면 다음 그리기에서 전부 다시 그린다)

Set how the shadow is redrawn. (ToonDrawQueue follows it, default ShadowUpdateMode.onChange, setting it redraws everything on the next draw)

updateModestring
ShadowUpdateMode.
updateIntervalnumber
interval 일 때 몇 프레임마다 그릴지. (기본 1, 1 보다 작으면 1)With interval, every how many frames to draw. (Default 1, 1 if less than 1)

짝Counterpart: vanilla-engine ShadowMap.set_update_mode

예제Example해 그림자를 세 프레임마다 그리기Draw the sun shadow every three frames
import { ShadowMap, ShadowUpdateMode } from "./vanilla.js";
const webGL2RenderingContext = document.createElement("canvas").getContext("webgl2");
const shadowTarget = new ShadowMap(webGL2RenderingContext, 1024);
shadowTarget.setUpdateMode(ShadowUpdateMode.interval, 3);
console.log(shadowTarget.getUpdateMode(), shadowTarget.getUpdateInterval());
shadowTarget.setUpdateMode(ShadowUpdateMode.everyFrame);
shadowTarget.destroy();
메서드methodgetUpdateMode()#0.4.0 부터since 0.4.0소스source

그림자를 다시 그리는 방식 반환.

Return how the shadow is redrawn.

반환Returnsstring ShadowUpdateMode.

짝Counterpart: vanilla-engine ShadowMap.get_update_mode

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

interval 의 프레임 수 반환.

Return the frame count of interval.

반환Returnsnumber 몇 프레임마다 그리는지. (1 이상)Every how many frames it draws. (1 or more)

짝Counterpart: vanilla-engine ShadowMap.get_update_interval

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

다음 그리기에서 전부 다시 그리게 하기. (드리우개 기록이 못 보는 바뀜, 예를 들어 모형의 꼭짓점을 고쳤을 때)

Make the next draw redraw everything. (For changes the caster record cannot see, for example when the vertices of a mesh were changed)

짝Counterpart: vanilla-engine ShadowMap.request_update

메서드methodgetWebGL2RenderingContext()#0.3.0 부터since 0.3.0소스source

렌더링 컨텍스트 반환.

Returns the rendering context.

반환ReturnsWebGL2RenderingContext 렌더링 컨텍스트.Rendering context.

메서드methodgetFramebuffer()#0.3.0 부터since 0.3.0소스source

프레임버퍼 반환.

Returns the framebuffer.

반환ReturnsWebGLFramebuffer 깊이 전용 프레임버퍼.Depth-only framebuffer.

짝Counterpart: vanilla-engine ShadowMap.get_framebuffer

메서드methodgetDepthTexture()#0.3.0 부터since 0.3.0소스source

깊이 텍스처 반환.

Returns the depth texture.

반환ReturnsWebGLTexture 비교 샘플링(sampler2DShadow)용 깊이 텍스처. (DEPTH_COMPONENT24)Depth texture for comparison sampling (sampler2DShadow). (DEPTH_COMPONENT24)

짝Counterpart: vanilla-engine ShadowMap.get_depth_texture

메서드methodgetResolution()#0.3.0 부터since 0.3.0소스source

해상도 반환.

Returns the resolution.

반환Returnsnumber 깊이 텍스처 한 변의 크기. (픽셀)Side length of the depth texture. (pixels)

짝Counterpart: vanilla-engine ShadowMap.get_resolution

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

초점을 끊어 옮기는 월드 칸 정하기. (해 그림자 캐시용, 기본 0 은 끊지 않고 텍셀 맞춤만)

  • 카메라를 따라 초점이 움직이면 텍셀 하나만 넘어도 빛 행렬이 바뀌어 ShadowUpdateMode.onChange 캐시가 프레임마다 다시 그린다.
  • 칸을 주면 초점을 월드 칸(x, y, z 각각)의 배수에 맞춰 옮겨, 한 칸 안에서는 행렬이 같아 구운 판을 다시 쓴다. 덮는 너비와 깊이에 칸만큼 여유를 더해 초점 둘레가 판 밖으로 나가지 않는다.
  • 유니티와 언리얼의 캐시드 섀도, 가상 섀도 맵의 고정 칸에 초점을 붙이는 꼴과 같은 생각이다. (원문은 읽지 못해 짐작)
  • 텍셀 맞춤은 그 위에 그대로 걸린다. 여유가 늘어 텍셀 하나의 월드 크기는 조금 커진다.

Set the world step the focus moves in. (for the sun shadow cache, the default 0 does not snap and only snaps to texels)

  • When the focus follows a camera, passing a single texel changes the light matrix, so the ShadowUpdateMode.onChange cache redraws every frame.
  • With a step, the focus is moved to multiples of the world step on each of x, y and z, so the matrix stays the same inside one cell and the baked map is reused. The covered width and depth get the step as margin so the area around the focus never leaves the map.
  • This is the same idea as pinning the focus to a fixed cell in the cached shadows of Unity and Unreal and in virtual shadow maps. (the originals were not read, so this is a guess)
  • Texel snapping still applies on top. With the extra margin, one texel covers slightly more world space.
worldStepnumber
월드 칸. (월드 단위, 0 이하면 끔)World step. (in world units, 0 or less turns it off)

짝Counterpart: vanilla-engine ShadowMap.set_focus_step

예제Example초점을 1 미터 칸으로 끊어 옮기기Moving the focus in one meter steps
import { ShadowMap, Vector3 } from "./vanilla.js";
const webGL2RenderingContext = document.createElement("canvas").getContext("webgl2");
const shadowMap = new ShadowMap(webGL2RenderingContext, 1024);
shadowMap.setFocusStep(1);
shadowMap.updateLightMatrix(Vector3.create(0.2, 0, 0), Vector3.create(-0.4, -1, -0.3), 20, 0.5, 100);
console.log(shadowMap.getFocusStep());
shadowMap.destroy();
메서드methodgetFocusStep()#0.4.0 부터since 0.4.0소스source

초점을 끊어 옮기는 월드 칸 반환.

Return the world step the focus moves in.

반환Returnsnumber 월드 칸. (0 이면 끔)World step. (0 means off)

짝Counterpart: vanilla-engine ShadowMap.get_focus_step

메서드methodgetLightViewProjectionMatrix()#0.3.0 부터since 0.3.0소스source

광원 뷰 투영 행렬 반환.

Returns the light view-projection matrix.

반환ReturnsMatrix4 광원 뷰 투영 행렬. (updateLightMatrix 전에는 단위 행렬)Light view-projection matrix. (identity before updateLightMatrix)

짝Counterpart: vanilla-engine ShadowMap.get_light_view_projection_matrix

메서드methodsetBias(depthBias, normalBias)#0.4.0 부터since 0.4.0소스source

그림자 치우침 정하기. (그림자 텍셀 단위, 기본 깊이 1, 노멀 1, 받는 쪽이 읽을 때 쓴다)

  • 텍셀 하나의 월드 크기(빛 행렬의 가로 폭 / 해상도)를 곱해 월드 거리로 바꾸므로 extent 와 해상도가 바뀌어도 같은 몫으로 걸린다. (유니티 URP 의 Depth Bias, Normal Bias 와 같은 단위)
  • 깊이 치우침은 빛 쪽으로 견줄 깊이를 당긴다. 노멀 치우침은 받는 점을 면의 노멀 쪽으로 밀어 읽는다. 둘 다 3x3 PCF 의 반지름 1.5 텍셀을 곱한다.
  • ToonRenderer 는 여기에 기울기 비례 치우침(빛과 면이 스칠수록 커짐, 텍셀 2.5 x 기울기, 기울기는 10 까지)을 더한다.
  • 줄이면 그림자가 붙고 제 그림자 여드름이 생기기 쉽다. 늘리면 여드름은 없어지고 그림자가 떠 보인다(피터 패닝).

Sets the shadow bias. (in shadow texels, default depth 1, normal 1, applied by the receiver when it reads the shadow)

  • It is multiplied by the world size of one texel (light matrix width / resolution), so the same amount applies when the extent or resolution changes. (the same units as Depth Bias and Normal Bias in Unity URP)
  • Depth bias pulls the compared depth toward the light. Normal bias pushes the receiving point along the surface normal before reading. Both are multiplied by the 1.5 texel radius of the 3x3 PCF.
  • ToonRenderer adds a slope-scaled bias on top (grows as the light grazes the surface, 2.5 texels x slope, slope clamped at 10).
  • Lower values keep shadows attached but invite self-shadow acne. Higher values remove acne but make shadows look detached (peter panning).
depthBiasnumber
깊이 치우침. (텍셀 단위, 0 이상)Depth bias. (in shadow texels, 0 or more)
normalBiasnumber
노멀 치우침. (텍셀 단위, 0 이상)Normal bias. (in shadow texels, 0 or more)

짝Counterpart: vanilla-engine ShadowMap.set_bias

예제Example텍셀 단위로 그림자 치우침 정하기Setting the shadow bias in texels
import { ShadowMap, Vector3 } from "./vanilla.js";
const webGL2RenderingContext = document.createElement("canvas").getContext("webgl2");
const shadowMap = new ShadowMap(webGL2RenderingContext, 1024);
shadowMap.updateLightMatrix(Vector3.create(0, 0, 0), Vector3.create(-0.3, -1, -0.2), 20, 1, 100);
shadowMap.setBias(0.5, 1.5);
console.log(shadowMap.getDepthBias(), shadowMap.getNormalBias());
shadowMap.destroy();
메서드methodgetDepthBias()#0.4.0 부터since 0.4.0소스source

깊이 치우침 반환.

Returns the depth bias.

반환Returnsnumber 깊이 치우침. (그림자 텍셀 단위, 기본 1)Depth bias. (in shadow texels, default 1)

짝Counterpart: vanilla-engine ShadowMap.get_depth_bias

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

노멀 치우침 반환.

Returns the normal bias.

반환Returnsnumber 노멀 치우침. (그림자 텍셀 단위, 기본 1)Normal bias. (in shadow texels, default 1)

짝Counterpart: vanilla-engine ShadowMap.get_normal_bias

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

파괴. (프레임버퍼와 깊이 텍스처, 구운 판을 지운다)

Destroy. (Deletes the framebuffer, the depth texture and the baked target)

짝Counterpart: vanilla-engine ShadowMap.destroy

ShadowAtlasextends Object

짝Counterpart: vanilla-engine ShadowAtlas

그림자 아틀라스. (점광과 스포트라이트의 실시간 그림자를 깊이 텍스처 한 장에 칸으로 나눠 담는다)

  • 유니티 URP 의 추가 빛 그림자 아틀라스 꼴이다. 스포트라이트는 원근 그림자 맵 한 칸, 점광은 큐브 여섯 면을 칸 여섯에 (면마다 90 도 원근) 그린다.
  • updateLights(빛 목록) 이 castsShadow 가 true 인 빛을 SHADOW_ATLAS_MAXIMUM_LIGHTS 까지 골라 칸을 나누고 칸마다 보기와 투영을 셈한다. 빛은 ToonLightSet.setPointLights 의 꼴이다. { position, direction (있으면 스포트라이트), outerConeAngle, range (먼 거리, 0 이면 30), shadowNear (가까운 거리, 기본 0.05), castsShadow } 목록에서의 차례(lightIndex)를 적어 두어, ToonRenderer 가 그 점광에 이 그림자를 붙인다. (아틀라스는 기본 빛 묶음의 점광 목록으로 짓는다)
  • 칸 크기는 유니티 URP 기본과 같이 정한다. 칸마다 tileResolution(기본 1024, URP 추가 빛 그림자 해상도 단계 High 의 기본값이고 빛의 기본 단계가 High)을 바라고, 아틀라스(기본 2048, URP 기본)에 다 들어가지 않으면 다 들어갈 때까지 칸 한 변을 반씩 줄인다. (URP 의 shadowSlicesScaleFactor 를 두 배씩) 칸은 한 변 gridSize 의 격자에 차례로 놓는다. (gridSize = 내림(해상도 / 칸 한 변)) 점광 하나(여섯 칸)면 512, 스포트라이트 하나면 1024 다.
  • 그리기: beginRender() 로 판을 비우고, 칸마다 beginTile(칸 번호) 로 뷰포트를 그 칸에 건 뒤 getTile(칸 번호).viewProjectionMatrix 로 깊이를 그린다. (ToonRenderer.beginShadowAtlasPass 와 setShadowAtlasTile 이 이 차례를 한다)
  • 받기: 셰이더는 빛의 자리에서 면으로의 쪽으로 점광의 면을 고르고(가장 큰 축), 앞쪽, 위쪽, 오른쪽 바탕과 가까운 거리, 먼 거리로 칸 안 자리와 깊이를 셈해 3x3 PCF 로 견준다. 받는 자리는 노멀 쪽으로 그 거리의 칸 텍셀 (1 + 3 x (1 - dot(N, L))) 개만큼 밀어 견준다. (빛에 비스듬한 면일수록 크게, 빛과 그늘 경계의 톱니 같은 그림자 여드름을 막는다)

Shadow atlas. (Stores real-time shadows of point lights and spotlights as tiles in one depth texture)

  • Same form as the additional light shadow atlas of Unity URP. A spotlight is drawn into one perspective shadow map tile, a point light draws the six cube faces into six tiles (90 degree perspective per face).
  • updateLights(light list) picks lights with castsShadow true up to SHADOW_ATLAS_MAXIMUM_LIGHTS, divides the tiles and computes view and projection per tile. Lights have the form of ToonLightSet.setPointLights. { position, direction (spotlight if present), outerConeAngle, range (far distance, 30 if 0), shadowNear (near distance, default 0.05), castsShadow } The order in the list (lightIndex) is noted so ToonRenderer attaches this shadow to that point light. (The atlas is built from the point light list of the default light set)
  • Tile size is decided the same as the Unity URP defaults. Each tile asks for tileResolution (default 1024, the default of the URP additional light shadow resolution tier High, and High is the default tier of a light), and if they do not all fit in the atlas (default 2048, the URP default), the tile side is halved until they all fit. (Doubling shadowSlicesScaleFactor of URP) Tiles are placed in order on a grid of gridSize per side. (gridSize = floor(resolution / tile side)) One point light (six tiles) gives 512, one spotlight gives 1024.
  • Drawing: beginRender() clears the target, then per tile beginTile(tile number) sets the viewport to that tile and depth is drawn with getTile(tile number).viewProjectionMatrix. (ToonRenderer.beginShadowAtlasPass and setShadowAtlasTile do this sequence)
  • Receiving: the shader picks the point light face from the direction from the light position to the surface (largest axis), computes the position and depth inside the tile from the forward, up and right basis and the near and far distances, and compares with 3x3 PCF. The receiving position is pushed toward the normal by (1 + 3 x (1 - dot(N, L))) tile texels at that distance before comparing. (Larger the more the surface is slanted to the light, prevents saw-toothed shadow acne at the light and shade boundary)
예제Example점광 하나와 스포트라이트 하나의 그림자 칸 짓기Build shadow tiles for one point light and one spotlight
import { ShadowAtlas } from "./vanilla.js";
const webGL2RenderingContext = document.createElement("canvas").getContext("webgl2");
const shadowAtlas = new ShadowAtlas(webGL2RenderingContext, 2048);
shadowAtlas.updateLights([
	{ position: [0, 3, 0], range: 8, castsShadow: true },
	{ position: [2, 4, 1], direction: [0, -1, 0], outerConeAngle: 0.5, range: 10, castsShadow: true },
]);
const tileCount = shadowAtlas.getTileCount();
const firstTile = shadowAtlas.getTile(0);
console.log(tileCount, shadowAtlas.getGridSize(), firstTile.size);
shadowAtlas.destroy();
생성자constructorconstructor(webGL2RenderingContext, resolution = 2048, tileResolution = 1024)#0.4.0 부터since 0.4.0소스source

생성. (깊이 텍스처와 컬러 없는 프레임버퍼, 앞의 묶음은 돌린다)

Constructor. (Depth texture and a framebuffer without color, previous bindings are restored)

webGL2RenderingContextWebGL2RenderingContext
렌더링 컨텍스트.Rendering context.
resolutionnumber
아틀라스 한 변의 크기. (픽셀, 기본 2048)Size of one side of the atlas. (Pixels, default 2048)
tileResolutionnumber
칸마다 바라는 한 변. (픽셀, 기본 1024, 다 들어가지 않으면 반씩 줄인다)Side each tile asks for. (Pixels, default 1024, halved if they do not all fit)

짝Counterpart: vanilla-engine ShadowAtlas.new

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

빛 목록으로 칸 나누기. (castsShadow 가 true 인 것을 SHADOW_ATLAS_MAXIMUM_LIGHTS 까지, 스포트라이트 한 칸, 점광 여섯 칸)

Divide tiles from the light list. (Ones with castsShadow true up to SHADOW_ATLAS_MAXIMUM_LIGHTS, one tile per spotlight, six per point light)

pointLightsArray<object>
ToonLightSet.setPointLights 의 꼴의 배열. (getPointLights 를 그대로 주면 된다)Array in the form of ToonLightSet.setPointLights. (getPointLights can be passed as is)

짝Counterpart: vanilla-engine ShadowAtlas.update_lights

메서드methodcreateTile(position, forward, up, tangent, near, far)#0.4.0 부터since 0.4.0소스source

칸 하나 짓기. (지금까지 지은 칸 수로 격자 자리를 정하고, 바탕 보기 행렬과 원근 투영을 곱한다)

Build one tile. (Decides the grid position from the number of tiles built so far, and multiplies the basis view matrix with the perspective projection)

positionArray<number>
빛의 자리.Light position.
forwardArray<number>
보는 쪽.Looking direction.
upArray<number>
위쪽.Up direction.
tangentnumber
반각의 탄젠트. (점광 면은 1, 90 도)Tangent of the half angle. (1 for a point light face, 90 degrees)
nearnumber
가까운 거리.Near distance.
farnumber
먼 거리.Far distance.

반환Returnsobject { viewProjectionMatrix, x, y, size }

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

깊이 패스 시작. (프레임버퍼를 묶고 판 전체를 비운다, 칸마다 beginTile, ToonDrawQueue 가 캐시를 쓸 때는 구운 판에 그리거나 구운 판을 옮겨 그 위에 덧그린다)

Start the depth pass. (Binds the framebuffer and clears the whole target, beginTile per tile, when ToonDrawQueue uses the cache it draws into the baked target or copies the baked target and draws on top)

짝Counterpart: vanilla-engine ShadowAtlas.begin_render

메서드methodsetUpdateMode(updateMode, updateInterval = 1)#0.4.0 부터since 0.4.0소스source

그림자를 다시 그리는 방식 정하기. (ToonDrawQueue 가 따른다, 기본 ShadowUpdateMode.onChange, 정하면 다음 그리기에서 전부 다시 그린다)

Set how the shadow is redrawn. (ToonDrawQueue follows it, default ShadowUpdateMode.onChange, setting it redraws everything on the next draw)

updateModestring
ShadowUpdateMode.
updateIntervalnumber
interval 일 때 몇 프레임마다 그릴지. (기본 1, 1 보다 작으면 1)With interval, every how many frames to draw. (Default 1, 1 if less than 1)

짝Counterpart: vanilla-engine ShadowAtlas.set_update_mode

예제Example점광 그림자를 세 프레임마다 그리기Draw the point light shadow every three frames
import { ShadowAtlas, ShadowUpdateMode } from "./vanilla.js";
const webGL2RenderingContext = document.createElement("canvas").getContext("webgl2");
const shadowTarget = new ShadowAtlas(webGL2RenderingContext, 1024);
shadowTarget.setUpdateMode(ShadowUpdateMode.interval, 3);
console.log(shadowTarget.getUpdateMode(), shadowTarget.getUpdateInterval());
shadowTarget.setUpdateMode(ShadowUpdateMode.everyFrame);
shadowTarget.destroy();
메서드methodgetUpdateMode()#0.4.0 부터since 0.4.0소스source

그림자를 다시 그리는 방식 반환.

Return how the shadow is redrawn.

반환Returnsstring ShadowUpdateMode.

짝Counterpart: vanilla-engine ShadowAtlas.get_update_mode

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

interval 의 프레임 수 반환.

Return the frame count of interval.

반환Returnsnumber 몇 프레임마다 그리는지. (1 이상)Every how many frames it draws. (1 or more)

짝Counterpart: vanilla-engine ShadowAtlas.get_update_interval

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

다음 그리기에서 전부 다시 그리게 하기. (드리우개 기록이 못 보는 바뀜, 예를 들어 모형의 꼭짓점을 고쳤을 때)

Make the next draw redraw everything. (For changes the caster record cannot see, for example when the vertices of a mesh were changed)

짝Counterpart: vanilla-engine ShadowAtlas.request_update

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

칸 하나에 뷰포트 걸기.

Set the viewport to one tile.

tileIndexnumber
칸 번호. (0 ~ getTileCount() - 1)Tile number. (0 ~ getTileCount() - 1)

짝Counterpart: vanilla-engine ShadowAtlas.begin_tile

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

그림자를 받는 빛 수 반환.

Return the number of lights receiving shadows.

반환Returnsnumber 칸을 받은 빛 수. (0 ~ SHADOW_ATLAS_MAXIMUM_LIGHTS)Number of lights that got tiles. (0 ~ SHADOW_ATLAS_MAXIMUM_LIGHTS)

짝Counterpart: vanilla-engine ShadowAtlas.get_light_count

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

그림자를 받는 빛 반환. (셰이더에 올릴 값)

Return the lights receiving shadows. (Values to upload to the shader)

반환ReturnsArray<object> { lightIndex (빛 목록의 차례), position, forward, up, tangent (0 이면 점광), near, far, firstTile } 의 배열.Array of { lightIndex (order in the light list), position, forward, up, tangent (0 for a point light), near, far, firstTile }.

짝Counterpart: vanilla-engine ShadowAtlas.get_lights

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

칸 수 반환.

Return the tile count.

반환Returnsnumber 지은 칸 수. (스포트라이트 하나, 점광 여섯)Number of tiles built. (One per spotlight, six per point light)

짝Counterpart: vanilla-engine ShadowAtlas.get_tile_count

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

칸 반환.

Return a tile.

tileIndexnumber
칸 번호.Tile number.

반환Returnsobject { viewProjectionMatrix (Matrix4), x, y, size (픽셀) }{ viewProjectionMatrix (Matrix4), x, y, size (pixels) }

짝Counterpart: vanilla-engine ShadowAtlas.get_tile

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

격자 한 변의 칸 수 반환.

Return the number of tiles per side of the grid.

반환Returnsnumber 격자 한 변의 칸 수.Number of tiles per side of the grid.

짝Counterpart: vanilla-engine ShadowAtlas.get_grid_size

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

칸마다 바라는 한 변 반환. (픽셀, 생성 때 준 값)

Return the side each tile asks for. (Pixels, the value given at construction)

반환Returnsnumber 칸마다 바라는 한 변. (픽셀)Side each tile asks for. (Pixels)

짝Counterpart: vanilla-engine ShadowAtlas.get_tile_resolution

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

칸 한 변 반환. (픽셀)

Return the side of a tile. (Pixels)

반환Returnsnumber 칸 한 변. (픽셀)Side of a tile. (Pixels)

짝Counterpart: vanilla-engine ShadowAtlas.get_tile_size

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

해상도 반환.

Returns the resolution.

반환Returnsnumber 아틀라스 한 변. (픽셀)One side of the atlas. (Pixels)

짝Counterpart: vanilla-engine ShadowAtlas.get_resolution

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

깊이 텍스처 반환. (비교 샘플링 sampler2DShadow)

Return the depth texture. (Comparison sampling with sampler2DShadow)

반환ReturnsWebGLTexture 아틀라스의 깊이 텍스처.Depth texture of the atlas.

짝Counterpart: vanilla-engine ShadowAtlas.get_depth_texture

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

프레임버퍼 반환.

Returns the framebuffer.

반환ReturnsWebGLFramebuffer 아틀라스의 깊이 프레임버퍼.Depth framebuffer of the atlas.

짝Counterpart: vanilla-engine ShadowAtlas.get_framebuffer

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

파괴. (프레임버퍼와 깊이 텍스처, 구운 판을 지운다)

Destroy. (Deletes the framebuffer, the depth texture and the baked target)

짝Counterpart: vanilla-engine ShadowAtlas.destroy

상수Constants

상수constantSHADOW_ATLAS_MAXIMUM_LIGHTS = 4#0.4.0 부터since 0.4.0소스source

그림자 아틀라스가 받는 점광과 스포트라이트 수의 상한. (셰이더의 유니폼 배열 크기)

Upper limit of point lights and spotlights the shadow atlas receives. (Size of the uniform arrays in the shader)

반환Returnsnumber

짝Counterpart: vanilla-engine SHADOW_ATLAS_MAXIMUM_LIGHTS

ShadowUpdateModeenum

짝Counterpart: vanilla-engine ShadowUpdateMode

그림자 깊이를 다시 그리는 방식. (ShadowMap 과 ShadowAtlas 의 setUpdateMode, ToonDrawQueue.drawShadows 와 drawLocalShadows 가 따른다)

  • everyFrame: 매 프레임 드리우개 전부를 다시 그린다.
  • onChange: 빛과 드리우개가 그대로면 다시 그리지 않는다. 오래 그대로인 드리우개는 따로 구워 두고, 움직이는 것만 매 프레임 그 위에 덧그린다. (기본, 화면은 매 프레임 그린 것과 같다)
  • interval: N 프레임마다 한 번 전부 다시 그린다. (사이의 프레임은 앞의 그림자를 그대로 써서, 움직이는 것의 그림자가 늦게 따라온다)

How the shadow depth is redrawn. (setUpdateMode of ShadowMap and ShadowAtlas, followed by ToonDrawQueue.drawShadows and drawLocalShadows)

  • everyFrame: redraws all casters every frame.
  • onChange: does not redraw when the lights and casters are unchanged. Casters that stay still are baked separately and only the moving ones are drawn on top every frame. (Default, the screen is the same as drawing every frame)
  • interval: redraws everything once every N frames. (The frames in between keep the previous shadow, so the shadows of moving things follow late)
예제Example해 그림자는 바뀔 때만, 점광 그림자는 네 프레임마다Sun shadow only on change, point light shadow every four frames
import { ShadowMap, ShadowAtlas, ShadowUpdateMode } from "./vanilla.js";
const webGL2RenderingContext = document.createElement("canvas").getContext("webgl2");
const shadowMap = new ShadowMap(webGL2RenderingContext, 1024);
shadowMap.setUpdateMode(ShadowUpdateMode.onChange);
const shadowAtlas = new ShadowAtlas(webGL2RenderingContext, 1024);
shadowAtlas.setUpdateMode(ShadowUpdateMode.interval, 4);
console.log(shadowMap.getUpdateMode(), shadowAtlas.getUpdateMode(), shadowAtlas.getUpdateInterval());
shadowMap.destroy();
shadowAtlas.destroy();
이름Name값Value설명Description
everyFrameeveryFrame매 프레임 전부.Everything every frame.
onChangeonChange바뀔 때만. (기본)Only on change. (Default)
intervalintervalN 프레임마다.Every N frames.