vanilladocs
vanillapunch.com
API / graphics3d/toon/toonlightset

graphics3d/toon/toonlightset

툰 빛 묶음. (ToonRenderer 가 몸을 칠할 빛과 툰 빛 반응을 한 덩어리로 든다)

Toon light set. (Holds as one bundle the lights ToonRenderer uses to shade bodies and the toon light response)

예제Example그늘 색 두 단계와 단단한 하이라이트, 림, 스포트라이트를 건 빛 묶음A light set with two shade color levels, hard highlight, rim and spotlight
import { ToonLightSet } from "./vanilla.js";
const lightSet = new ToonLightSet();
lightSet.setLight([-0.4, -1, -0.3], [0.85, 0.82, 0.78], [0.3, 0.33, 0.42], [0.16, 0.15, 0.14]);
lightSet.setShade({ step: 0.5, feather: 0.02, color: [0.55, 0.52, 0.7], secondStep: 0.25, secondFeather: 0.02, secondColor: [0.36, 0.33, 0.52] });
lightSet.setSpecular(0.6, 64, 0);
lightSet.setRimLight([0.5, 0.55, 0.7], 3, 0.2, 1);
lightSet.setPointLights([{ position: [0, 3, 0], color: [1, 0.8, 0.6], intensity: 3, range: 6, direction: [0, -1, 0], innerConeAngle: 0.3, outerConeAngle: 0.6 }]);

ToonLightSet

짝Counterpart: vanilla-engine ToonLightSet

툰 빛 묶음. (ToonRenderer 가 몸을 칠할 빛과 툰 빛 반응을 한 덩어리로 든다)

  • 렌더러는 기본 묶음 하나를 들고, setLight 같은 렌더러의 빛 설정은 그 묶음을 고친다. 그리기마다 options.lightSet 으로 다른 묶음을 줄 수 있다. (재질마다 그늘 색이 다를 때)
  • 해(주광): 방향(sunDirection)은 빛이 나아가는 쪽이다. 면에서 해 쪽을 가리키는 방향의 반대다. (위에서 내리쬐면 [0, -1, 0]) 그림자를 받는다.
  • 바탕빛: 하늘색과 땅색을 노멀의 위아래(N.y x 0.5 + 0.5)로 섞는다. (반구 빛)
  • 그늘 램프(셀 셰이딩): 빛을 받는 몫 x 를 램프에 대어 색을 고른다. x 는 반 램버트면 dot(N, L) x 0.5 + 0.5, 아니면 max(dot(N, L), 0) 이고, 그리기의 shadeOffset 을 더한 뒤 해는 그림자(받는 몫 0 ~ 1)를 곱한다. (그림자가 검정이 아니라 그늘 색으로 들어간다, 유니티 툰 셰이더의 System Shadows) 램프는 칸(stop)마다 자리, 색(선형 배), 부드러움이다. 칸 i 의 색은 x 가 (자리 - 부드러움) 에서 자리까지 오를 때 앞 칸 색에서 넘어간다. (유니티 툰 셰이더의 Step 과 Feather) 부드러움이 화소 하나 너비(fwidth)보다 작으면 그 너비로 막아 경계가 계단지지 않는다. setShade 는 바탕, 1 차 그늘, 2 차 그늘 셋(유니티 툰 셰이더의 Base, 1st Shade, 2nd Shade)으로, setShadeRamp 는 칸을 바로, setBandCount 는 고른 칸으로, setBandRamp 는 회색 칸으로 램프를 짓는다. setRampTexture 를 주면 칸 대신 그 텍스처의 가로(x 를 u 로, v 는 0.5)를 읽는다. (팀 포트리스 2 의 warp, 원신과 붕괴의 램프 텍스처) 칸이 없으면(clearShadeRamp, setBandCount(0)) 부드러운 램버트다.
  • 빛마다: 해는 램프 색을 통째로 받아 그늘도 해의 색으로 물든다. 채움 빛, 점광, 스포트라이트는 램프의 밝기 단계(바닥 칸이 0, 맨 위 칸이 1)를 받아 등진 면을 밝히지 않는다.
  • 채움 빛(fill): 그림자를 받지 않는 둘째 방향광. 방향의 뜻은 해와 같다. 기본 색 0 이면 없다.
  • 하이라이트(정반사): 블린 퐁 pow(max(dot(N, H), 0), exponent) 를 0.5 에서 가른 단단한 점(부드러움 0)에서 그대로의 부드러운 빛(부드러움 1)까지. 색 x 세기 x 빛 색 x 빛을 받는 단계. 해와 점광, 스포트라이트 모두에 선다. 기본 세기 0 이면 없다.
  • 림 빛(rim): pow(1 - max(dot(N, V), 0), power) 를 0.5 에서 가른 단단한 테(부드러움 0)에서 부드러운 테(1)까지. lightMask 가 1 이면 해를 받는 쪽에만. 바탕색과 상관없이 더한다. 그늘 쪽 림(setShadeRimLight)은 같은 테를 해와 등진 쪽에 (테 - (dot(N, L) x 0.5 + 0.5)) 만큼 더한다. (유니티 툰 셰이더의 Antipodean(Ap) Rim Light)
  • 빛 색 쓰기(setLightColorUsage): 색마다 빛 색을 곱할지 고른다. 끄면 그 색은 빛의 세기(0.299 R + 0.587 G + 0.114 B)만 받고, 림과 매트캡과 천사 고리와 바깥선은 빛을 받지 않는다. (유니티 툰 셰이더의 Is_LightColor_*, 기본 모두 켬)
  • 빛 세기 막기(setLightIntensityLimited): 빛마다 받은 몫을 1 로 막는다. 해와 채움 빛은 채널마다 1 로 자르고, 점광과 스포트라이트는 감쇠까지 곱한 색의 세기가 1 을 넘으면 세기로 나눈다. (유니티 툰 셰이더의 Limit Light Intensity, 기본 켬) HDR 블룸에 센 빛을 쓰려면 끈다. 옛 게임 셰이더(빛 세기를 막지 않던 것)를 옮길 때나 세기 1 을 넘는 점광, HDR 블룸을 쓸 때는 setLightIntensityLimited(false).
  • 점광과 스포트라이트: TOON_MAXIMUM_POINT_LIGHTS 까지. { position, color(선형), intensity, range, decay, rangeExponent, wrap, direction, innerConeAngle, outerConeAngle, castsShadow, shadowNear } castsShadow 가 true 인 빛은 ShadowAtlas.updateLights 가 그림자 칸을 준다. (점광은 큐브 여섯 면, 스포트라이트는 원근 한 칸, 먼 거리는 range, 가까운 거리는 shadowNear 기본 0.05) 감쇠는 창 x 거리 감쇠다. 창은 range 가 0 보다 크면 (1 - (거리 / range)^rangeExponent) 를 0 ~ 1 로 막아 제곱, 0 이면 1. 거리 감쇠는 decay 가 0 보다 크면 1 / max(거리^decay, 0.01), 0 이면 1. 기본(decay 2, rangeExponent 4)은 three.js 와 언리얼, 고도 4 의 점광 꼴이다. direction(빛이 나아가는 쪽)을 주면 스포트라이트다. 각 감쇠는 glTF KHR_lights_punctual 꼴로 clamp(cos 각 x scale + offset, 0, 1) 의 제곱이다. (innerConeAngle 기본 0, outerConeAngle 기본 π/4, 라디안) 받는 몫은 감싸기(wrap) (dot(N, L) + wrap) / (1 + wrap) 이다. (0 이면 램버트, GPU Gems 1 의 wrap lighting)
  • 빛 꼴: setLightModel({ isEnergyNormalized }) 가 true 면 바탕색 x 빛을 π 로 나누고 하이라이트에 (exponent + 8) / 8π 를 곱한다. (물리 빛 세기를 조도로 주는 약속)
  • 색은 모두 선형 색이다. (HDR 이면 1 을 넘어도 된다) 램프 텍스처는 sRGB 로 보고 선형으로 바꿔 읽는다. (감마 색 공간은 셰이더가 pow 2.2 로, 선형 색 공간은 sRGB 텍스처라 GPU 가)
  • 고치면 판 번호(getVersion)가 오른다. 렌더러는 묶음과 판 번호가 같으면 다시 올리지 않는다.

Toon light set. (Holds as one bundle the lights ToonRenderer uses to shade bodies and the toon light response)

  • The renderer holds one default set, and the renderer's light settings such as setLight change that set. Another set can be given per draw with options.lightSet. (When the shade color differs per material)
  • Sun (key light): the direction (sunDirection) is the way the light travels. It is the opposite of the direction from the surface toward the sun. ([0, -1, 0] when shining down from above) It receives shadows.
  • Ambient: mixes the sky color and ground color by the normal's up and down (N.y x 0.5 + 0.5). (hemisphere light)
  • Shade ramp (cel shading): the received light amount x is laid against the ramp to pick the color. x is dot(N, L) x 0.5 + 0.5 for half Lambert, otherwise max(dot(N, L), 0), and after adding the draw's shadeOffset, for the sun it is multiplied by the shadow (received amount 0 ~ 1). (Shadows enter as the shade color rather than black, System Shadows of the Unity Toon Shader) The ramp has a position, color (linear multiplier) and softness per cell (stop). The color of cell i transitions from the previous cell's color as x rises from (position - softness) to the position. (Step and Feather of the Unity Toon Shader) If the softness is smaller than one pixel width (fwidth), it is held at that width so the boundary does not stair-step. setShade builds the ramp from three, base, 1st shade and 2nd shade (Base, 1st Shade, 2nd Shade of the Unity Toon Shader), setShadeRamp from cells directly, setBandCount from even cells, setBandRamp from gray cells. If setRampTexture is given, the horizontal of that texture (x as u, v is 0.5) is read instead of cells. (The warp of Team Fortress 2, the ramp textures of Genshin and Honkai) Without cells (clearShadeRamp, setBandCount(0)) it is smooth Lambert.
  • Per light: the sun receives the whole ramp color so the shade also takes on the sun's color. The fill light, point lights and spotlights receive the ramp's brightness level (bottom cell 0, top cell 1) and do not light faces turned away.
  • Fill light (fill): a second directional light that does not receive shadows. Its direction means the same as the sun's. With the default color 0 it is absent.
  • Highlight (specular): Blinn-Phong pow(max(dot(N, H), 0), exponent), from a hard spot cut at 0.5 (softness 0) to the plain soft light (softness 1). Color x strength x light color x received light level. It appears for the sun, point lights and spotlights alike. With the default strength 0 there is none.
  • Rim light (rim): pow(1 - max(dot(N, V), 0), power), from a hard rim cut at 0.5 (softness 0) to a soft rim (1). If lightMask is 1, only on the side receiving the sun. Added regardless of the base color. The shade-side rim (setShadeRimLight) adds the same rim on the side facing away from the sun by (rim - (dot(N, L) x 0.5 + 0.5)). (Antipodean (Ap) Rim Light of the Unity Toon Shader)
  • Light color usage (setLightColorUsage): chooses per color whether the light color is multiplied. When off, that color receives only the light's intensity (0.299 R + 0.587 G + 0.114 B), and the rim, matcap, angel ring and outline receive no light. (Is_LightColor_* of the Unity Toon Shader, all on by default)
  • Light intensity limit (setLightIntensityLimited): limits what each light gives to 1. The sun and fill light are clamped to 1 per channel, and point lights and spotlights are divided by the intensity of their color with attenuation applied when it exceeds 1. (Limit Light Intensity of the Unity Toon Shader, on by default) Turn it off to use strong lights for HDR bloom. When porting an old game shader (one that did not limit light intensity), or when using point lights above intensity 1 or HDR bloom, use setLightIntensityLimited(false).
  • Point lights and spotlights: up to TOON_MAXIMUM_POINT_LIGHTS. { position, color (linear), intensity, range, decay, rangeExponent, wrap, direction, innerConeAngle, outerConeAngle, castsShadow, shadowNear } Lights with castsShadow true get shadow tiles from ShadowAtlas.updateLights. (Six cube faces for a point light, one perspective tile for a spotlight, the far distance is range, the near distance is shadowNear default 0.05) Attenuation is window x distance attenuation. The window is (1 - (distance / range)^rangeExponent) clamped to 0 ~ 1 and squared if range is greater than 0, and 1 if it is 0. Distance attenuation is 1 / max(distance^decay, 0.01) if decay is greater than 0, and 1 if it is 0. The default (decay 2, rangeExponent 4) is the point light form of three.js, Unreal and Godot 4. Giving direction (the way the light travels) makes a spotlight. Angular attenuation is the square of clamp(cos angle x scale + offset, 0, 1) in the glTF KHR_lights_punctual form. (innerConeAngle default 0, outerConeAngle default π/4, radians) The received amount is the wrap (dot(N, L) + wrap) / (1 + wrap). (0 is Lambert, the wrap lighting of GPU Gems 1)
  • Light model: if setLightModel({ isEnergyNormalized }) is true, base color x light is divided by π and the highlight is multiplied by (exponent + 8) / 8π. (The convention of giving physical light intensity as illuminance)
  • All colors are linear colors. (They may exceed 1 for HDR) Ramp textures are treated as sRGB and read converted to linear. (By the shader with pow 2.2 in the gamma color space, by the GPU as an sRGB texture in the linear color space)
  • Modifying it raises the version number (getVersion). The renderer does not re-upload if the set and version number are the same.
예제Example재질마다 다른 그늘 색을 빛 묶음으로 주기Give a different shade color per material with light sets
import { ToonRenderer, MeshBuilder, createSphereGeometry, Matrix4, Vector3 } from "./vanilla.js";
const webGL2RenderingContext = document.createElement("canvas").getContext("webgl2");
const renderer = new ToonRenderer(webGL2RenderingContext);
const skinLightSet = renderer.createLightSet();
skinLightSet.setShade({ step: 0.55, feather: 0.04, color: [0.86, 0.6, 0.6] });
const builder = new MeshBuilder();
builder.addPart(createSphereGeometry(0.5, 32, 20), Matrix4.createIdentity(), "#f0d0c0", { hasOutline: false });
const mesh = renderer.createMesh(builder.readArrays());
renderer.beginFrameWithMatrices(Matrix4.createLookAt(Vector3.create(0, 0, 3), Vector3.create(0, 0, 0), Vector3.create(0, 1, 0)), Matrix4.createPerspective(0.8, 1, 0.1, 10));
renderer.drawMesh(mesh, Matrix4.createIdentity(), { lightSet: skinLightSet });
renderer.endFrame();
생성자constructorconstructor()#0.4.0 부터since 0.4.0소스source

생성. (기본은 반 램버트 0.5 에서 갈리는 두 단계 그늘, 그늘 색은 서늘한 보라)

Constructor. (The default is a two-level shade split at half Lambert 0.5, with a cool purple shade color)

짝Counterpart: vanilla-engine ToonLightSet.new

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

고친 판 올리기.

Raises the version after a modification.

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

번호 반환. (묶음마다 다르다)

Returns the ID. (different per set)

반환Returnsnumber 묶음 번호.Set number.

짝Counterpart: vanilla-engine ToonLightSet.get_id

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

판 번호 반환. (고칠 때마다 오른다)

Returns the version number. (raised on every modification)

반환Returnsnumber 판 번호.Version number.

짝Counterpart: vanilla-engine ToonLightSet.get_version

메서드methodsetLight(sunDirection, sunColor, skyColor, groundColor)#0.4.0 부터since 0.4.0소스source

해와 바탕빛 설정. (해가 비추는 방향, 해의 색, 하늘색, 땅색, 모두 선형)

Set the sun and ambient light. (Direction the sun shines, sun color, sky color, ground color, all linear)

sunDirectionArray<number>
빛이 나아가는 쪽. [x, y, z]The way the light travels. [x, y, z]
sunColorArray<number>
해의 선형 색과 세기. [r, g, b]Linear color and intensity of the sun. [r, g, b]
skyColorArray<number>
위를 보는 면의 바탕빛. [r, g, b]Ambient light of faces looking up. [r, g, b]
groundColorArray<number>
아래를 보는 면의 바탕빛. [r, g, b]Ambient light of faces looking down. [r, g, b]

짝Counterpart: vanilla-engine ToonLightSet.set_light

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

해가 비추는 방향 설정. (빛이 나아가는 쪽, 면에서 해 쪽 방향이면 부호를 뒤집어 준다)

Sets the sun direction. (the way the light travels, flip the sign if you have the direction from the surface toward the sun)

sunDirectionArray<number>
[x, y, z]

짝Counterpart: vanilla-engine ToonLightSet.set_sun_direction

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

해가 비추는 방향 반환. (ShadowMap.updateLightMatrix 에 그대로 넘긴다)

Returns the sun direction. (pass it as is to ShadowMap.updateLightMatrix)

반환ReturnsArray<number> [x, y, z]

짝Counterpart: vanilla-engine ToonLightSet.get_sun_direction

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

해의 색 반환.

Returns the sun color.

반환ReturnsArray<number> 선형 [r, g, b].Linear [r, g, b].

짝Counterpart: vanilla-engine ToonLightSet.get_sun_color

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

하늘색 반환.

Returns the sky color.

반환ReturnsArray<number> 선형 [r, g, b].Linear [r, g, b].

짝Counterpart: vanilla-engine ToonLightSet.get_sky_color

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

땅색 반환.

Returns the ground color.

반환ReturnsArray<number> 선형 [r, g, b].Linear [r, g, b].

짝Counterpart: vanilla-engine ToonLightSet.get_ground_color

메서드methodsetFillLight(fillDirection, fillColor)#0.4.0 부터since 0.4.0소스source

채움 빛 설정. (빛이 나아가는 방향과 선형 색, 색이 0 이면 없음, 그림자를 받지 않음)

Set the fill light. (Direction the light travels and linear color, none if the color is 0, receives no shadow)

fillDirectionArray<number>
빛이 나아가는 쪽. [x, y, z]The way the light travels. [x, y, z]
fillColorArray<number>
선형 [r, g, b].Linear [r, g, b].

짝Counterpart: vanilla-engine ToonLightSet.set_fill_light

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

채움 빛 반환.

Returns the fill light.

반환Returnsobject { direction, color }

짝Counterpart: vanilla-engine ToonLightSet.get_fill_light

메서드methodsetRimLight(rimColor, rimPower, rimFeather = 1, rimLightMask = 0)#0.4.0 부터since 0.4.0소스source

림 빛 설정. (선형 색, 거듭제곱, 부드러움 0 ~ 1, 해를 받는 쪽에만 둘 몫 0 ~ 1, 거듭제곱이 0 이하면 없음)

Set the rim light. (Linear color, power, softness 0 ~ 1, share kept only on the side receiving the sun 0 ~ 1, none if the power is 0 or less)

rimColorArray<number>
더할 선형 색. [r, g, b]Linear color to add. [r, g, b]
rimPowernumber
거듭제곱. (클수록 테가 가늘다, 0 이면 없음)Power. (The larger, the thinner the rim, 0 means none)
rimFeathernumber
0 이면 단단한 테, 1 이면 부드러운 테. (기본 1)0 is a hard rim, 1 is a soft rim. (Default 1)
rimLightMasknumber
1 이면 해를 받는 쪽에만 테를 둔다. (기본 0)1 puts the rim only on the side receiving the sun. (Default 0)

짝Counterpart: vanilla-engine ToonLightSet.set_rim_light

예제Example해 쪽에만 서는 단단한 테A hard rim that stands only on the sun side
import { ToonLightSet } from "./vanilla.js";
const lightSet = new ToonLightSet();
lightSet.setRimLight([0.6, 0.65, 0.8], 2.5, 0, 1);
메서드methodgetRimLight()#0.4.0 부터since 0.4.0소스source

림 빛 반환.

Returns the rim light.

반환Returnsobject { color, power, feather, lightMask }

짝Counterpart: vanilla-engine ToonLightSet.get_rim_light

메서드methodsetShadeRimLight(shadeRimColor, shadeRimPower)#0.4.0 부터since 0.4.0소스source

그늘 쪽 림 빛 설정. (해와 등진 쪽의 테, 선형 색, 거듭제곱, 부드러움은 setRimLight 의 것을 같이 쓴다, 거듭제곱이 0 이하면 없음)

Set the shade-side rim light. (Rim on the side facing away from the sun, linear color, power, softness is shared with setRimLight, none if the power is 0 or less)

shadeRimColorArray<number>
더할 선형 색. [r, g, b]Linear color to add. [r, g, b]
shadeRimPowernumber
거듭제곱. (0 이면 없음)Power. (0 means none)

짝Counterpart: vanilla-engine ToonLightSet.set_shade_rim_light

예제Example그늘 쪽에 푸른 테A blue rim on the shade side
import { ToonLightSet } from "./vanilla.js";
const lightSet = new ToonLightSet();
lightSet.setRimLight([0.8, 0.75, 0.6], 3, 0.1, 1);
lightSet.setShadeRimLight([0.2, 0.3, 0.6], 2.5);
메서드methodgetShadeRimLight()#0.4.0 부터since 0.4.0소스source

그늘 쪽 림 빛 반환.

Return the shade-side rim light.

반환Returnsobject { color, power }

짝Counterpart: vanilla-engine ToonLightSet.get_shade_rim_light

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

빛 색 쓰기 설정. (색마다 빛 색을 곱할지, 주지 않은 것은 그대로)

  • base 바탕, shade 그늘, highlight 하이라이트, rim 림, shadeRim 그늘 쪽 림, matcap 매트캡, angelRing 천사 고리, outline 껍데기 바깥선.
  • 바탕, 그늘, 하이라이트는 끄면 빛의 휘도(회색)를 받고, 나머지는 끄면 빛을 받지 않는다. (유니티 툰 셰이더 소스의 lightIntensity 와 1)

Set the light color usage. (Whether to multiply the light color per color, ones not given stay as they are)

  • base base, shade shade, highlight highlight, rim rim, shadeRim shade-side rim, matcap matcap, angelRing angel ring, outline shell outline.
  • Base, shade and highlight receive the light's luminance (gray) when off, and the rest receive no light when off. (lightIntensity and 1 in the Unity Toon Shader source)
lightColorUsageobject
{ base, shade, highlight, rim, shadeRim, matcap, angelRing, outline } 의 참 거짓.true or false for { base, shade, highlight, rim, shadeRim, matcap, angelRing, outline }.

짝Counterpart: vanilla-engine ToonLightSet.set_light_color_usage

예제Example그늘과 바깥선은 빛 색에 물들지 않게Keep the shade and outline from taking on the light color
import { ToonLightSet } from "./vanilla.js";
const lightSet = new ToonLightSet();
lightSet.setLightColorUsage({ shade: false, outline: false });
메서드methodgetLightColorUsage()#0.4.0 부터since 0.4.0소스source

빛 색 쓰기 반환.

Return the light color usage.

반환Returnsobject { base, shade, highlight, rim, shadeRim, matcap, angelRing, outline }

짝Counterpart: vanilla-engine ToonLightSet.get_light_color_usage

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

빛 세기 막기 설정. (true 면 빛마다 받은 몫을 1 로 막아 하얗게 날지 않게 한다, 기본 true, 유니티 툰 셰이더의 Limit Light Intensity)

  • 해와 채움 빛은 색의 채널마다 1 로 자른다. (주광의 saturate)
  • 점광과 스포트라이트는 감쇠까지 곱한 색의 세기(0.299 R + 0.587 G + 0.114 B)가 1 을 넘으면 세기로 나눈다. (추가 빛의 min(색, 색 / 세기))
  • 빛 꼴이 isEnergyNormalized 면 π 로 나눈 뒤의 몫을 1 로 막는다.
  • 옛 게임 셰이더(빛 세기를 막지 않던 것)를 옮길 때나 세기 1 을 넘는 점광, HDR 블룸을 쓸 때는 setLightIntensityLimited(false).

Set the light intensity limit. (If true, limits what each light gives to 1 so it does not wash out to white, default true, Limit Light Intensity of the Unity Toon Shader)

  • The sun and fill light are clamped to 1 per color channel. (saturate of the main light)
  • Point lights and spotlights are divided by the intensity (0.299 R + 0.587 G + 0.114 B) of their color with attenuation applied when it exceeds 1. (min(color, color / intensity) of additional lights)
  • If the light model is isEnergyNormalized, the share after dividing by π is limited to 1.
  • When porting an old game shader (one that did not limit light intensity), or when using point lights above intensity 1 or HDR bloom, use setLightIntensityLimited(false).
isLimitedboolean
true 면 막는다.If true, limits.

짝Counterpart: vanilla-engine ToonLightSet.set_light_intensity_limited

예제Example센 해로 HDR 블룸을 내려고 막기를 끄기Turn off the limit to get HDR bloom from a strong sun
import { ToonLightSet } from "./vanilla.js";
const lightSet = new ToonLightSet();
lightSet.setLight([-0.4, -1, -0.3], [4, 3.8, 3.5], [0.4, 0.45, 0.55], [0.2, 0.18, 0.16]);
lightSet.setLightIntensityLimited(false);
if (lightSet.isLightIntensityLimited()) {
	throw new Error("unexpected limit");
}
메서드methodisLightIntensityLimited()#0.4.0 부터since 0.4.0소스source

빛 세기를 막는지 반환.

Return whether the light intensity is limited.

반환Returnsboolean 막으면 true.true if limited.

짝Counterpart: vanilla-engine ToonLightSet.is_light_intensity_limited

메서드methodsetSpecular(specularStrength, specularExponent = 48, specularFeather = 0, specularColor = [1, 1, 1])#0.4.0 부터since 0.4.0소스source

하이라이트(정반사) 설정. (세기 0 이면 없음, 지수가 클수록 작은 점, 부드러움 0 이면 단단한 툰 점, 1 이면 부드러운 블린 퐁)

Set the highlight (specular). (None if the strength is 0, the larger the exponent the smaller the spot, softness 0 is a hard toon spot, 1 is soft Blinn-Phong)

specularStrengthnumber
세기. (0 이면 없음)Strength. (0 means none)
specularExponentnumber
블린 퐁 지수. (기본 48)Blinn-Phong exponent. (Default 48)
specularFeathernumber
0 ~ 1. (기본 0, 단단한 점)0 ~ 1. (Default 0, hard spot)
specularColorArray<number>
선형 [r, g, b]. (기본 흰색)Linear [r, g, b]. (Default white)

짝Counterpart: vanilla-engine ToonLightSet.set_specular

예제Example부드러운 하이라이트Soft highlight
import { ToonLightSet } from "./vanilla.js";
const lightSet = new ToonLightSet();
lightSet.setSpecular(0.4, 32, 1, [1, 0.95, 0.9]);
메서드methodgetSpecular()#0.4.0 부터since 0.4.0소스source

하이라이트 반환.

Return the highlight.

반환Returnsobject { strength, exponent, feather, color }

짝Counterpart: vanilla-engine ToonLightSet.get_specular

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

점광과 스포트라이트 설정. (TOON_MAXIMUM_POINT_LIGHTS 를 넘는 것은 버린다, direction 을 주면 스포트라이트)

Set point lights and spotlights. (Ones beyond TOON_MAXIMUM_POINT_LIGHTS are dropped, giving direction makes a spotlight)

pointLightsArray<object>
{ position [x, y, z], color [r, g, b] 선형, intensity (기본 1), range (기본 0 = 끝없음), decay (기본 2), rangeExponent (기본 4), wrap (기본 0), direction [x, y, z] (빛이 나아가는 쪽, 주면 스포트라이트), innerConeAngle (기본 0), outerConeAngle (기본 π/4), castsShadow (기본 false), shadowNear (기본 0.05) } 의 배열.Array of { position [x, y, z], color [r, g, b] linear, intensity (default 1), range (default 0 = endless), decay (default 2), rangeExponent (default 4), wrap (default 0), direction [x, y, z] (the way the light travels, spotlight if given), innerConeAngle (default 0), outerConeAngle (default π/4), castsShadow (default false), shadowNear (default 0.05) }.

짝Counterpart: vanilla-engine ToonLightSet.set_point_lights

예제Example아래를 비추는 스포트라이트 하나One spotlight shining down
import { ToonLightSet } from "./vanilla.js";
const lightSet = new ToonLightSet();
lightSet.setPointLights([{ position: [0, 4, 0], color: [1, 0.9, 0.7], intensity: 4, range: 8, direction: [0, -1, 0], innerConeAngle: 0.25, outerConeAngle: 0.5 }]);
메서드methodgetPointLights()#0.4.0 부터since 0.4.0소스source

점광 반환. (설정한 것 그대로, 한도로 자르기 전)

Returns the point lights. (as set, before clipping to the limit)

반환ReturnsArray<object> setPointLights 가 채운 꼴의 배열.Array in the form filled by setPointLights.

짝Counterpart: vanilla-engine ToonLightSet.get_point_lights

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

셰이더에 넣을 점광 수의 한도 설정. (0 ~ TOON_MAXIMUM_POINT_LIGHTS, 가벼운 길에서 줄인다)

Sets the limit on the number of point lights put into the shader. (0 ~ TOON_MAXIMUM_POINT_LIGHTS, lowered on lightweight paths)

pointLightLimitnumber
한도.Limit.

짝Counterpart: vanilla-engine ToonLightSet.set_point_light_limit

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

셰이더에 넣을 점광 수. (설정한 수와 한도 가운데 작은 것)

Number of point lights put into the shader. (the smaller of the set count and the limit)

반환Returnsnumber 셰이더에 넣을 점광 수.Number of point lights put into the shader.

짝Counterpart: vanilla-engine ToonLightSet.get_point_light_count

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

그늘 셋 설정. (유니티 툰 셰이더의 바탕, 1 차 그늘, 2 차 그늘과 그 경계의 Step, Feather)

  • step 은 바탕과 1 차 그늘의 경계, secondStep 은 1 차와 2 차 그늘의 경계다. (빛을 받는 몫 x 의 자리, 반 램버트면 0.5 가 해와 직각인 면)
  • 색은 바탕색과 빛에 곱하는 선형 배다. 바탕은 흰색 [1, 1, 1].
  • secondStep 이 0 이하면 2 차 그늘이 없다. (기본 0)

Set the three shades. (Base, 1st shade, 2nd shade of the Unity Toon Shader and Step and Feather of their boundaries)

  • step is the boundary between base and 1st shade, secondStep the boundary between 1st and 2nd shade. (A position of the received light amount x, with half Lambert 0.5 is the face perpendicular to the sun)
  • Colors are linear multipliers on the base color and light. The base is white [1, 1, 1].
  • If secondStep is 0 or less, there is no 2nd shade. (Default 0)
shadeobject
{ step (기본 0.5), feather (기본 0.02), color (기본 [0.5, 0.48, 0.66]), secondStep (기본 0), secondFeather (기본 0.02), secondColor (기본 [0.32, 0.3, 0.48]), isHalfLambert (기본 true) }{ step (default 0.5), feather (default 0.02), color (default [0.5, 0.48, 0.66]), secondStep (default 0), secondFeather (default 0.02), secondColor (default [0.32, 0.3, 0.48]), isHalfLambert (default true) }

짝Counterpart: vanilla-engine ToonLightSet.set_shade

예제Example따뜻한 1 차 그늘과 짙은 2 차 그늘A warm 1st shade and a deep 2nd shade
import { ToonLightSet } from "./vanilla.js";
const lightSet = new ToonLightSet();
lightSet.setShade({ step: 0.5, feather: 0.03, color: [0.8, 0.62, 0.6], secondStep: 0.2, secondFeather: 0.03, secondColor: [0.5, 0.36, 0.42] });
메서드methodsetShadeRamp(positions, colors, feathers, isHalfLambert)#0.4.0 부터since 0.4.0소스source

그늘 램프 설정. (칸마다 자리, 선형 색, 부드러움, 칸은 2 ~ TOON_MAXIMUM_BAND_STEPS, 비우면 부드러운 램버트)

  • 칸은 자리의 오름차순이다. 첫 칸의 자리와 부드러움은 쓰지 않는다. (x 가 둘째 칸 밑이면 첫 칸 색)

Set the shade ramp. (Position, linear color and softness per cell, 2 ~ TOON_MAXIMUM_BAND_STEPS cells, smooth Lambert if emptied)

  • Cells are in ascending order of position. The position and softness of the first cell are not used. (The first cell's color if x is below the second cell)
positionsArray<number>
칸마다의 자리. (빛을 받는 몫 x)Position per cell. (Received light amount x)
colorsArray<Array<number>>
칸마다의 선형 [r, g, b] 배.Linear [r, g, b] multiplier per cell.
feathersArray<number>
칸마다의 부드러움. (그 칸으로 넘어가는 너비)Softness per cell. (Width of the transition into that cell)
isHalfLambertboolean
x 를 dot x 0.5 + 0.5 로 셀지. (아니면 max(dot, 0))Whether to count x as dot x 0.5 + 0.5. (Otherwise max(dot, 0))

짝Counterpart: vanilla-engine ToonLightSet.set_shade_ramp

예제Example세 칸 램프를 바로 주기Give a three-cell ramp directly
import { ToonLightSet } from "./vanilla.js";
const lightSet = new ToonLightSet();
lightSet.setShadeRamp([0, 0.4, 0.62], [[0.3, 0.3, 0.45], [0.62, 0.6, 0.75], [1, 1, 1]], [0, 0.05, 0.02], true);
메서드methodclearShadeRamp()#0.4.0 부터since 0.4.0소스source

그늘 램프 끄기. (부드러운 램버트)

Turn off the shade ramp. (Smooth Lambert)

짝Counterpart: vanilla-engine ToonLightSet.clear_shade_ramp

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

그늘 램프 반환. (칸이 비면 부드러운 램버트)

Return the shade ramp. (Smooth Lambert if the cells are empty)

반환Returnsobject { positions, colors, feathers, isHalfLambert }

짝Counterpart: vanilla-engine ToonLightSet.get_shade_ramp

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

고른 칸 설정. (max(dot(N, L), 0) 을 칸 수로 반올림한 회색 칸, 1 ~ TOON_MAXIMUM_BAND_STEPS - 1, 0 이면 부드러운 램버트)

Set even cells. (Gray cells rounding max(dot(N, L), 0) to the cell count, 1 ~ TOON_MAXIMUM_BAND_STEPS - 1, 0 means smooth Lambert)

bandCountnumber
칸 수. (0 이면 부드럽게)Number of cells. (0 means smooth)

짝Counterpart: vanilla-engine ToonLightSet.set_band_count

메서드methodsetBandRamp(thresholds, values, isHalfLambert)#0.4.0 부터since 0.4.0소스source

회색 칸 램프 설정. (문턱은 값보다 하나 적다, 값은 TOON_MAXIMUM_BAND_STEPS 까지, 첫 문턱 밑이 첫 값, 마지막 문턱 위가 마지막 값)

Set a gray cell ramp. (Thresholds are one fewer than values, values up to TOON_MAXIMUM_BAND_STEPS, below the first threshold is the first value, above the last threshold the last value)

thresholdsArray<number>
오름차순 문턱.Ascending thresholds.
valuesArray<number>
칸마다의 받는 몫.Received amount per cell.
isHalfLambertboolean
dot x 0.5 + 0.5 를 문턱에 댈지.Whether to compare dot x 0.5 + 0.5 to the thresholds.

짝Counterpart: vanilla-engine ToonLightSet.set_band_ramp

메서드methodsetRampTexture(rampTexture, isHalfLambert = true)#0.4.0 부터since 0.4.0소스source

램프 텍스처 설정. (칸 대신 텍스처의 가로를 읽는다, null 이면 칸으로, ToonRenderer.createTexture 로 지은 것)

  • x 를 u 로 v 0.5 를 읽는다. 왼쪽이 그늘, 오른쪽이 빛. sRGB 로 보고 선형으로 바꾼다. 늘이지 않게 isRepeated: false 로 짓는다.

Set the ramp texture. (Reads the horizontal of the texture instead of cells, back to cells if null, one built with ToonRenderer.createTexture)

  • Reads x as u at v 0.5. Left is shade, right is light. Treated as sRGB and converted to linear. Build it with isRepeated: false so it does not wrap.
rampTextureWebGLTexture | null
램프 텍스처나 null.Ramp texture or null.
isHalfLambertboolean
x 를 반 램버트로 셀지. (기본 true)Whether to count x with half Lambert. (Default true)

짝Counterpart: vanilla-engine ToonLightSet.set_ramp_texture

예제Example코드로 그린 네 칸 램프 텍스처A four-cell ramp texture drawn in code
import { ToonRenderer } from "./vanilla.js";
const webGL2RenderingContext = document.createElement("canvas").getContext("webgl2");
const renderer = new ToonRenderer(webGL2RenderingContext);
const data = new Uint8Array([70, 60, 120, 255, 120, 110, 170, 255, 200, 190, 220, 255, 255, 255, 255, 255]);
const rampTexture = renderer.createTexture({ width: 4, height: 1, data: data }, { isMipmapped: false, isRepeated: false, isFiltered: false });
renderer.getLightSet().setRampTexture(rampTexture);
메서드methodgetRampTexture()#0.4.0 부터since 0.4.0소스source

램프 텍스처 반환. (없으면 null)

Return the ramp texture. (null if none)

반환ReturnsWebGLTexture | null 램프 텍스처. (없으면 null)Ramp texture. (null if none)

짝Counterpart: vanilla-engine ToonLightSet.get_ramp_texture

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

빛 꼴 설정. ({ isEnergyNormalized } 바탕색 x 빛을 π 로 나눌지)

Sets the light model. ({ isEnergyNormalized } whether to divide base color x light by π)

lightModelobject
{ isEnergyNormalized }

짝Counterpart: vanilla-engine ToonLightSet.set_light_model

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

빛 꼴 반환.

Returns the light model.

반환Returnsobject { isEnergyNormalized }

짝Counterpart: vanilla-engine ToonLightSet.get_light_model

상수Constants

상수constantTOON_MAXIMUM_POINT_LIGHTS = 8#0.4.0 부터since 0.4.0소스source

한 그리기에 받는 점광과 스포트라이트 수의 상한. (셰이더의 유니폼 배열 크기)

Upper limit of point lights and spotlights received in one draw. (Size of the uniform arrays in the shader)

반환Returnsnumber

짝Counterpart: vanilla-engine TOON_MAXIMUM_POINT_LIGHTS

상수constantTOON_MAXIMUM_BAND_STEPS = 8#0.4.0 부터since 0.4.0소스source

그늘 램프 칸 수의 상한. (셰이더의 유니폼 배열 크기)

Upper limit of shade ramp cells. (Size of the uniform arrays in the shader)

반환Returnsnumber

짝Counterpart: vanilla-engine TOON_MAXIMUM_BAND_STEPS