vanilladocs
vanillapunch.com
API / graphics3d/toon/toonvfx

graphics3d/toon/toonvfx

툰 3D GPU 효과의 바탕. (외계행성 광부 키우기와 애버런트가 따로 쓰던 판 안 효과의 범용 부분)

Base of toon 3D GPU effects. (The general-purpose part of the in-board effects that webgame-rimminer and aberrant each used separately)

예제Example툰 장면 위에 폭발 효과를 내고 한 프레임 그리기Show an explosion effect over a toon scene and draw one frame
import { ToonRenderer, ToonVfx, ToonVfxLook, ToonVfxShape, ToonVfxDecalMode, MeshBuilder, createBoxGeometry, Matrix4, Vector3 } from "./vanilla.js";
const webGL2RenderingContext = document.createElement("canvas").getContext("webgl2");
const renderer = new ToonRenderer(webGL2RenderingContext);
const builder = new MeshBuilder();
builder.addPart(createBoxGeometry(8, 0.2, 8), Matrix4.createTranslation(0, -0.1, 0), "#708090", { hasOutline: false });
const floorMesh = renderer.createMesh(builder.readArrays());
const vfx = new ToonVfx(webGL2RenderingContext);
vfx.setRamps([["#ffffff", "#ffe080", "#ff8020", "#a02010", "#301008"]]);
vfx.prepare();
vfx.addFireball({ position: [0, 0.8, 0], radius: 0.9, life: 1.2, ramp: 0 });
vfx.addShockwave({ x: 0, z: 0, endRadius: 3, life: 0.6, ramp: 0 });
vfx.addDecal({ x: 0, z: 0, radius: 1.4, life: 8, heatSeconds: 1.5, mode: ToonVfxDecalMode.scorch, ramp: 0 });
vfx.emitParticles({ count: 40, position: [0, 0.6, 0], shape: ToonVfxShape.sphere, radius: 0.3, speed: [2, 5], gravity: 6, size: [0.05, 0.12], life: [0.4, 0.9], look: ToonVfxLook.streak, stretch: 0.05, ramp: 0, isGrounded: true });
const viewMatrix = Matrix4.createLookAt(Vector3.create(4, 3, 5), Vector3.create(0, 0.5, 0), Vector3.create(0, 1, 0));
const projectionMatrix = Matrix4.createPerspective(Math.PI / 4, 1, 0.1, 100);
vfx.update(1 / 60);
renderer.beginFrameWithMatrices(viewMatrix, projectionMatrix);
renderer.drawMesh(floorMesh, Matrix4.createIdentity());
renderer.endFrame();
vfx.draw(viewMatrix, projectionMatrix);

ToonVfx

짝Counterpart: vanilla-engine ToonVfx

툰 3D GPU 효과의 바탕. (외계행성 광부 키우기와 애버런트가 따로 쓰던 판 안 효과의 범용 부분)

  • 텍스처: 그림 파일 없이 처음 그릴 때 코드로 짓는 아틀라스 한 장. 왼쪽 반은 연기 플립북 16 칸, 오른쪽 반은 ToonVfxSlot 칸과 색 램프 여덟 줄. 램프 색은 게임이 정한다. (setRamps, 줄마다 흰 심에서 어둠으로 가는 색들, 효과의 ramp 는 줄 번호, -1 이면 램프 없이 color 만)
  • 파티클: 인스턴스로 그리는 GPU 파티클. 낼 때 한 번 버퍼에 쓰고 자리, 크기, 색은 정점 셰이더가 나이로 셈한다. (끌림, 중력, 바닥에서 멈춤, 속도 쪽으로 늘인 줄기, 색 램프) 상한(setParticleCapacity)을 넘으면 가장 오래 전에 낸 것부터 덮고, setCountRatio 로 내는 수에 몫을 곱한다. (폰과 가벼운 길)
  • 효과 메쉬: 잡음으로 끓다 연기로 식는 불덩이(addFireball), 바깥으로 흐르며 찢기고 말려 오르는 충격파 띠와 그 밑 바닥 빛(addShockwave), 바닥 자국(addDecal, queueDecal), 말려 오르는 연기 기둥(addPlume), 결이 흐르고 겉이 일렁이는 회전체 빔(queueBeam), 카메라 쪽으로 편 리본(queueRibbon)과 그것을 감아 내린 번개(queueLightning), 사는 동안 다시 꺾이는 번개(addLightning), 그 자리의 빛 점(queueGlint).
  • 테: 빛 파티클의 rim, 리본의 glow 와 rim, 불덩이와 충격파의 rim 은 가장자리를 테 색(setRimColor)으로 덮어 밝은 바탕에서도 보이게 한다. (기본은 더하는 빛만)
  • 밝기 배: setLookGain(꼴, 배) 로 파티클과 빛 점의 꼴마다 밝기를 곱한다. (기본 1, HDR 판에서 불꽃 줄기, 빛살, 불씨를 선형 몇 배로 할 때)
  • 나이와 열쇠: emitParticles, addFireball, addShockwave, addDecal, addPlume, addLightning, addFlash 는 options.age(이미 지난 초, 음수면 그만큼 늦게)와 options.key(사건 열쇠, 이미 낸 열쇠면 다시 내지 않음, clear 가 잊음)를 받는다. 장면이 매 프레임 상태에서 사건을 다시 내도 한 번만, 늦게 보인 효과는 그 나이부터 튼다. 흔들림(addShake)은 Shaker 의 지수 감쇠(초당 9)라 늦게 보인 사건은 세기 x exp(-9 x 나이) 로 넘기면 같다.
  • 발밑 그늘: queueBlobShadow 는 그 프레임의 둥근 그늘 자국(ToonVfxDecalMode.shade)이다.
  • 화면: 섬광(addFlash)은 draw 끝에 지금 뷰포트(가위가 걸려 있으면 그 안)를 그 색으로 덮고 걷힌다. 카메라 흔들림(addShake)은 엔진 Shaker 로 셈하고, readShake 가 준 오프셋을 게임이 카메라의 오른쪽과 위쪽으로 더한다.
  • 어느 사건에 어느 효과를 어떤 값으로 낼지(처방)는 게임 몫이다. 엔진은 매개변수만 받는다.
  • 바닥: setFloorHeightReader((x, z) => 높이) 로 게임이 바닥 높이를 알려 주면 자국, 충격파, 연기 기둥은 그 높이에, isGrounded 파티클은 그 높이에서 멈춘다. (없으면 0)
  • 시계: update(초) 가 이 바탕의 시계를 나아가게 한다. 판이 멈추면 효과도 멈춘다. queue 로 넘긴 것은 그 프레임에 한 번 그리고 비운다.
  • 그리기: draw(보기, 투영) 를 툰 모형을 그린 뒤 부른다. 깊이 시험은 켜고 깊이는 쓰지 않으며 미리 곱한 알파로 섞는다. 앞의 상태를 적어 두었다 돌린다.

Base of toon 3D GPU effects. (The general-purpose part of the in-board effects that webgame-rimminer and aberrant each used separately)

  • Texture: a single atlas built in code on the first draw, without image files. The left half is a 16-cell smoke flipbook, the right half is ToonVfxSlot cells and eight rows of color ramps. Ramp colors are decided by the game. (setRamps, each row is colors going from a white core to dark, an effect's ramp is the row number, -1 means color only without a ramp)
  • Particles: GPU particles drawn with instancing. Written to the buffer once when emitted, and position, size and color are computed by the vertex shader from age. (Drag, gravity, stopping on the floor, streaks stretched along velocity, color ramps) When the cap (setParticleCapacity) is exceeded, the oldest emitted are overwritten first, and setCountRatio multiplies the emitted count by a fraction. (Phones and the lite path)
  • Effect meshes: fireballs that boil with noise and cool into smoke (addFireball), shockwave rings that flow outward, tear and curl up, with a floor glow beneath (addShockwave), floor decals (addDecal, queueDecal), curling smoke plumes (addPlume), solid-of-revolution beams with flowing grain and a rippling surface (queueBeam), ribbons spread toward the camera (queueRibbon) and lightning made by winding them down (queueLightning), lightning that re-bends during its lifetime (addLightning), and point glints at a spot (queueGlint).
  • Rim: the rim of glow particles, the glow and rim of ribbons, and the rim of fireballs and shockwaves cover the edges with the rim color (setRimColor) so they are visible on bright backgrounds too. (Default is additive light only)
  • Brightness gain: setLookGain(look, gain) multiplies brightness per look of particles and glints. (Default 1, for making flame streaks, light rays and embers several times brighter in linear in the HDR version)
  • Age and key: emitParticles, addFireball, addShockwave, addDecal, addPlume, addLightning, addFlash take options.age (seconds already elapsed, negative delays by that much) and options.key (event key, not emitted again if already emitted, forgotten by clear). Even if the scene re-emits events from state every frame they appear only once, and effects shown late start from that age. Shake (addShake) uses Shaker's exponential decay (9 per second), so passing strength x exp(-9 x age) for a late-shown event gives the same result.
  • Foot shadow: queueBlobShadow is a round shade decal for that frame (ToonVfxDecalMode.shade).
  • Screen: the flash (addFlash) covers the current viewport (inside the scissor if one is set) with its color at the end of draw and then fades. Camera shake (addShake) is computed with the engine Shaker, and the game adds the offset given by readShake to the camera's right and up.
  • Which effect to emit for which event with what values (the recipe) is up to the game. The engine only takes parameters.
  • Floor: if the game reports the floor height with setFloorHeightReader((x, z) => height), decals, shockwaves and smoke plumes are placed at that height, and isGrounded particles stop at that height. (0 if none)
  • Clock: update(seconds) advances this base's clock. If the board stops, the effects stop too. Items passed with queue are drawn once in that frame and then cleared.
  • Drawing: call draw(view, projection) after drawing the toon models. Depth test on, depth write off, blends with premultiplied alpha. Records the previous state and restores it.
예제Example매 프레임 상태에서 사건을 다시 내도 열쇠로 한 번만 내기Fire an event only once by key even if the state re-fires it every frame
import { ToonVfx, ToonVfxLook, ToonVfxShape, Matrix4, Vector3 } from "./vanilla.js";
const webGL2RenderingContext = document.createElement("canvas").getContext("webgl2");
const vfx = new ToonVfx(webGL2RenderingContext, 2000);
vfx.setRamps([["#ffffff", "#ffd070", "#ff7020", "#802010", "#200808"]]);
const viewMatrix = Matrix4.createLookAt(Vector3.create(0, 3, 6), Vector3.create(0, 0.5, 0), Vector3.create(0, 1, 0));
const projectionMatrix = Matrix4.createPerspective(Math.PI / 4, 1, 0.1, 100);
for (let frameIndex = 0; frameIndex < 3; ++frameIndex) {
	vfx.addFireball({ position: [0, 0.8, 0], radius: 0.7, life: 1, ramp: 0, key: "explosion-1" });
	vfx.emitParticles({ count: 24, position: [0, 0.8, 0], shape: ToonVfxShape.sphere, radius: 0.2, speed: [2, 4], look: ToonVfxLook.ember, ramp: 0, life: 0.8, key: "explosion-1-sparks" });
	vfx.queueBlobShadow({ x: 1, z: 0, radius: 0.4 });
	vfx.update(1 / 60);
	vfx.draw(viewMatrix, projectionMatrix);
}
const counts = vfx.getActiveCounts();
vfx.destroy();
생성자constructorconstructor(webGL2RenderingContext, particleCapacity = TOON_VFX_DEFAULT_PARTICLE_CAPACITY)#0.4.0 부터since 0.4.0소스source

생성. (셰이더와 메쉬, 파티클 버퍼를 지음, 아틀라스는 처음 그릴 때)

Constructor. (Builds the shaders, meshes and particle buffer, the atlas on the first draw)

webGL2RenderingContextWebGL2RenderingContext
효과를 그릴 WebGL2 컨텍스트.WebGL2 context to draw effects with.
particleCapacitynumber
한꺼번에 떠 있는 파티클의 상한.Maximum number of particles alive at once.

짝Counterpart: vanilla-engine ToonVfx.new

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

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

Returns the shader sources. (For prelinking with ShaderWarmer)

반환ReturnsArray<object> { vertexShader, fragmentShader, attributeLocationTable } 의 배열.Array of { vertexShader, fragmentShader, attributeLocationTable }.

짝Counterpart: vanilla-engine ToonVfx.read_program_sources

예제Example켤 때 효과 셰이더를 미리 링크해 두기Link the effect shaders in advance when starting
import { ToonVfx, ShaderWarmer } from "./vanilla.js";
const webGL2RenderingContext = document.createElement("canvas").getContext("webgl2");
const shaderWarmer = new ShaderWarmer(webGL2RenderingContext, ToonVfx.readProgramSources());
shaderWarmer.update();
if (shaderWarmer.isFinished()) {
	const vfx = new ToonVfx(webGL2RenderingContext);
	vfx.prepare();
}
메서드methodcreateBuffer()#0.4.0 부터since 0.4.0소스source

버퍼 하나 만들기. (지울 목록에 넣는다)

Creates one buffer. (Adds it to the delete list)

반환ReturnsWebGLBuffer 새 버퍼.New buffer.

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

색 램프 설정. (줄마다 흰 심에서 어둠으로 가는 "#rrggbb" 나 [r, g, b] 의 배열, 여덟 줄까지, 효과의 ramp 는 이 차례)

Sets the color ramps. (Each row is an array of "#rrggbb" or [r, g, b] going from a white core to dark, up to eight rows, an effect's ramp follows this order)

rampsArray<Array<string | Array<number>>>
줄마다 흰 심에서 어둠으로 가는 색들. (여덟 줄까지, 빈 줄은 버림)Colors per row going from a white core into darkness. (Up to eight rows, empty rows are dropped)

짝Counterpart: vanilla-engine ToonVfx.set_ramps

예제Example불과 얼음 램프 두 줄을 주고 줄 번호로 고르기Give two ramp rows, fire and ice, and choose by row number
import { ToonVfx, ToonVfxLook } from "./vanilla.js";
const vfx = new ToonVfx(document.createElement("canvas").getContext("webgl2"));
vfx.setRamps([
	["#ffffff", "#ffe080", "#ff8020", "#801808", "#200804"],
	["#ffffff", [0.7, 0.95, 1], [0.3, 0.6, 1], [0.05, 0.1, 0.3]],
]);
vfx.emitParticles({ count: 20, position: [0, 1, 0], ramp: 0, look: ToonVfxLook.ember, speed: [1, 3], life: 0.8 });
vfx.emitParticles({ count: 20, position: [2, 1, 0], ramp: 1, look: ToonVfxLook.star, speed: [0.5, 1], life: 0.6 });
메서드methodprepare()#0.4.0 부터since 0.4.0소스source

아틀라스를 미리 지어 두기. (처음 터질 때 멈칫하지 않게, 판에 들어갈 때)

Prebuilds the atlas. (So it does not stall on the first burst, when entering the board)

짝Counterpart: vanilla-engine ToonVfx.prepare

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

파티클 상한 설정. (떠 있던 파티클은 지운다)

Sets the particle cap. (Clears alive particles)

particleCapacitynumber
한꺼번에 떠 있는 파티클의 상한. (1 이상)Upper limit of particles alive at once. (1 or more)

짝Counterpart: vanilla-engine ToonVfx.set_particle_capacity

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

파티클 상한 반환.

Returns the particle cap.

반환Returnsnumber 한꺼번에 떠 있는 파티클의 상한.Maximum number of particles alive at once.

짝Counterpart: vanilla-engine ToonVfx.get_particle_capacity

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

내는 파티클 수의 몫 설정. (폰이나 가벼운 길에서 짜임은 그대로 두고 수만 줄임, 0 ~ 1, 내면 적어도 하나)

Sets the emitted particle count fraction. (Reduces only the count while keeping the composition on phones or the lite path, 0 ~ 1, at least one when emitting)

countRationumber
내는 파티클 수에 곱하는 몫. (0 ~ 1)Fraction multiplied into the number of particles emitted. (0 ~ 1)

짝Counterpart: vanilla-engine ToonVfx.set_count_ratio

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

내는 파티클 수의 몫 반환.

Returns the emitted particle count fraction.

반환Returnsnumber 내는 파티클 수에 곱하는 몫. (0 ~ 1)Fraction multiplied into the number of particles emitted. (0 ~ 1)

짝Counterpart: vanilla-engine ToonVfx.get_count_ratio

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

빛 점 상한 설정. (프레임마다 queueGlint 로 넘기는 수, 기본 96, 이번 프레임에 넘긴 빛 점은 지운다)

Sets the glint cap. (Number passed with queueGlint per frame, default 96, clears the glints passed this frame)

glintCapacitynumber
프레임마다 넘기는 빛 점의 상한. (1 이상)Upper limit of light points submitted per frame. (1 or more)

짝Counterpart: vanilla-engine ToonVfx.set_glint_capacity

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

빛 점 상한 반환.

Returns the glint cap.

반환Returnsnumber 프레임마다 넘기는 빛 점의 상한.Upper limit of light points submitted per frame.

짝Counterpart: vanilla-engine ToonVfx.get_glint_capacity

메서드methodsetLookGain(look, gain)#0.4.0 부터since 0.4.0소스source

꼴마다 밝기 배 설정. (ToonVfxLook 의 꼴, 파티클과 빛 점의 밝기에 곱함, 기본 1)

Sets the brightness gain per look. (Look of ToonVfxLook, multiplied into particle and glint brightness, default 1)

looknumber
꼴. (ToonVfxLook)Look. (ToonVfxLook)
gainnumber
밝기 배. (0 이상, 기본 1)Brightness multiplier. (0 or more, default 1)

짝Counterpart: vanilla-engine ToonVfx.set_look_gain

예제ExampleHDR 판에서 불꽃 줄기와 빛살과 불씨만 더 밝게Make only the spark streaks, light rays and embers brighter on an HDR target
import { ToonVfx, ToonVfxLook } from "./vanilla.js";
const vfx = new ToonVfx(document.createElement("canvas").getContext("webgl2"));
vfx.setLookGain(ToonVfxLook.streak, 3);
vfx.setLookGain(ToonVfxLook.star, 4);
vfx.setLookGain(ToonVfxLook.ember, 2.5);
const streakGain = vfx.getLookGain(ToonVfxLook.streak);
메서드methodgetLookGain(look)#0.4.0 부터since 0.4.0소스source

꼴마다 밝기 배 반환.

Returns the brightness gain per look.

looknumber
꼴. (ToonVfxLook)Look. (ToonVfxLook)

반환Returnsnumber 그 꼴의 밝기 배. (꼴이 범위 밖이면 1)Brightness multiplier of that look. (1 if the look is out of range)

짝Counterpart: vanilla-engine ToonVfx.get_look_gain

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

사건 열쇠 적기. (열쇠가 없으면 늘 true, 처음 보는 열쇠면 적고 true, 이미 낸 열쇠면 false, clear 가 잊는다)

Records an event key. (Always true if there is no key, records it and returns true for a new key, false for an already emitted key, forgotten by clear)

keynumber | string | undefined | null
사건 열쇠. (없으면 늘 낸다)Event key. (Always fires if none)

반환Returnsboolean 내도 되면 true, 이미 낸 열쇠면 false.true if it may fire, false if the key already fired.

짝Counterpart: vanilla-engine ToonVfx.register_event_key

예제Example효과 밖의 일도 같은 사건 열쇠로 한 번만Do work outside the effects only once with the same event key
import { ToonVfx } from "./vanilla.js";
const vfx = new ToonVfx(document.createElement("canvas").getContext("webgl2"));
let playCount = 0;
for (let frameIndex = 0; frameIndex < 3; ++frameIndex) {
	if (vfx.registerEventKey("door-7-open")) {
		playCount += 1;
	}
}
vfx.clear();
const isNewAfterClear = vfx.registerEventKey("door-7-open");
메서드methodsetRimColor(rimColor)#0.4.0 부터since 0.4.0소스source

효과 테의 색 설정. ([r, g, b] 0 ~ 1, 테를 두른 파티클과 번짐 리본의 가장자리, 기본은 ToonRenderer 의 기본 바깥선 색)

Sets the effect rim color. ([r, g, b] 0 ~ 1, edges of rimmed particles and glow ribbons, default is ToonRenderer's default outline color)

rimColorArray<number>
테의 색. ([r, g, b] 0 ~ 1)Rim color. ([r, g, b] 0 ~ 1)

짝Counterpart: vanilla-engine ToonVfx.set_rim_color

예제Example밝은 바탕에서도 보이게 테를 두른 빛 알갱이와 불덩이Light grains and fireballs with a rim so they show on a bright background
import { ToonVfx, ToonVfxLook } from "./vanilla.js";
const vfx = new ToonVfx(document.createElement("canvas").getContext("webgl2"));
vfx.setRimColor([0.12, 0.06, 0.03]);
vfx.emitParticles({ count: 12, position: [0, 1, 0], look: ToonVfxLook.soft, color: [1, 0.8, 0.3], rim: 1, size: 0.3, speed: 1.5, life: 0.6 });
vfx.addFireball({ position: [0, 1, 0], radius: 0.8, life: 1, rim: 0.7 });
메서드methodgetRimColor()#0.4.0 부터since 0.4.0소스source

효과 테의 색 반환.

Returns the effect rim color.

반환ReturnsArray<number> 효과 테의 색. ([r, g, b] 0 ~ 1)Color of the effect rim. ([r, g, b] 0 ~ 1)

짝Counterpart: vanilla-engine ToonVfx.get_rim_color

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

바닥 높이를 읽는 함수 설정. ((x, z) → 높이, null 이면 0)

Sets the floor height reader function. ((x, z) → height, 0 if null)

floorHeightReaderfunction | null
(x, z) 로 바닥 높이를 돌려주는 함수. (null 이면 늘 0)Function returning the floor height for (x, z). (Always 0 if null)

짝Counterpart: vanilla-engine ToonVfx.set_floor_height_reader

예제Example울퉁불퉁한 바닥 높이를 알려 주기Tell it the height of a bumpy floor
import { ToonVfx, ToonVfxLook } from "./vanilla.js";
const vfx = new ToonVfx(document.createElement("canvas").getContext("webgl2"));
vfx.setFloorHeightReader((x, z) => {
	return Math.sin(x * 0.5) * 0.3 + Math.cos(z * 0.5) * 0.2;
});
vfx.addDecal({ x: 1, z: 2, radius: 1, life: 4 });
vfx.emitParticles({ count: 16, position: [1, 1, 2], isGrounded: true, gravity: 9, speed: [1, 2], look: ToonVfxLook.grit, color: [0.4, 0.3, 0.2] });
const floorHeight = vfx.readFloorHeight(1, 2);
vfx.setFloorHeightReader(null);
메서드methodreadFloorHeight(x, z)#0.4.0 부터since 0.4.0소스source

그 자리의 바닥 높이.

Floor height at that position.

xnumber
장면의 x.Scene x.
znumber
장면의 z.Scene z.

반환Returnsnumber 그 자리의 바닥 높이.Floor height at that position.

짝Counterpart: vanilla-engine ToonVfx.read_floor_height

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

이 바탕의 시계. (초)

This base's clock. (Seconds)

반환Returnsnumber 이 바탕의 시계. (초, update 로 나아감)Clock of this base. (Seconds, advanced by update)

짝Counterpart: vanilla-engine ToonVfx.get_time

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

떠 있는 효과의 수. ({ particleCount (아직 살아 있을 수 있는 칸), fireballCount, shockwaveCount, decalCount, plumeCount, lightningCount, flashCount })

Number of live effects. ({ particleCount (slots that may still be alive), fireballCount, shockwaveCount, decalCount, plumeCount, lightningCount, flashCount })

반환Returnsobject { particleCount, fireballCount, shockwaveCount, decalCount, plumeCount, lightningCount, flashCount }.

짝Counterpart: vanilla-engine ToonVfx.get_active_counts

예제Example효과가 다 사라졌는지 보기Check whether all effects have disappeared
import { ToonVfx } from "./vanilla.js";
const vfx = new ToonVfx(document.createElement("canvas").getContext("webgl2"));
vfx.addFireball({ position: [0, 1, 0], radius: 1, life: 0.5 });
vfx.emitParticles({ count: 10, position: [0, 1, 0], life: 0.3 });
vfx.update(1);
const counts = vfx.getActiveCounts();
const isQuiet = counts.particleCount === 0 && counts.fireballCount === 0;
메서드methodclear()#0.4.0 부터since 0.4.0소스source

다 지우기. (판이 바뀔 때, 사건 열쇠도 잊는다)

Clears everything. (When the board changes, also forgets event keys)

짝Counterpart: vanilla-engine ToonVfx.clear

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

이번 프레임에 넘긴 것 비우기. (그린 뒤)

Clears the items passed this frame. (After drawing)

짝Counterpart: vanilla-engine ToonVfx.clear_queue

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

한 프레임 나이 먹이기. (시계를 나아가게 하고 다 된 불덩이, 띠, 자국, 기둥, 번개, 섬광을 지움, 흔들림을 잦아들게 함)

Ages one frame. (Advances the clock, removes finished fireballs, rings, decals, plumes, lightning and flashes, damps the shake)

deltaTimenumber
초.Seconds.

짝Counterpart: vanilla-engine ToonVfx.update

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

파티클 내기. options: { count, position([x, y, z], 기본 [0, 0, 0]), shape(ToonVfxShape), radius, direction, spread(라디안), length, isUpward, isInward, speed, rise, gravity, drag, size, sizeEnd(시작 크기에 곱함), sizeCurve, life, delay, color, ramp, look(ToonVfxLook), stretch, spin, floor, isGrounded, brightness, alpha, fadeIn, rim(빛의 꼴의 테, 0 이면 더하는 빛만, 1 이면 테로 덮음, 음수면 엷게 덮는 빛무리), age(이미 지난 초, 음수면 그만큼 늦게), key(사건 열쇠, 이미 낸 열쇠면 내지 않음) } 범위가 되는 값(speed, rise, size, sizeEnd, life, delay, spin)은 수 하나나 [최소, 최대] 다. 색은 0 ~ 1 의 [r, g, b], 램프는 줄 번호(없으면 -1)다. floor 를 주면 그 높이에서, isGrounded 면 낸 자리의 바닥 높이에서 멈춘다. isInward 면 속도를 무시하고 나이가 다할 때 낸 자리로 빨려 든다.

Emits particles. options: { count, position([x, y, z], default [0, 0, 0]), shape(ToonVfxShape), radius, direction, spread(radians), length, isUpward, isInward, speed, rise, gravity, drag, size, sizeEnd(multiplied by the start size), sizeCurve, life, delay, color, ramp, look(ToonVfxLook), stretch, spin, floor, isGrounded, brightness, alpha, fadeIn, rim(rim of the glow look, 0 additive light only, 1 covers with the rim, negative is a faintly covering halo), age(seconds already elapsed, negative delays by that much), key(event key, not emitted if already emitted) } Range values (speed, rise, size, sizeEnd, life, delay, spin) are a single number or [min, max]. Color is [r, g, b] in 0 ~ 1, ramp is the row number (-1 if none). If floor is given it stops at that height, if isGrounded it stops at the floor height of the emission point. If isInward, velocity is ignored and it is sucked into the emission point as its age runs out.

optionsobject
내는 값. (꼴은 위 머리 주석의 options)Emission values. (The form is the options in the header comment above)

짝Counterpart: vanilla-engine ToonVfx.emit_particles

예제Example원뿔로 튀는 불꽃 줄기, 같은 열쇠로 다시 내면 무시Spark streaks bursting in a cone, ignored if fired again with the same key
import { ToonVfx, ToonVfxLook, ToonVfxShape } from "./vanilla.js";
const vfx = new ToonVfx(document.createElement("canvas").getContext("webgl2"));
const sparkOptions = {
	count: 30, position: [0, 1, 0],
	shape: ToonVfxShape.cone, direction: [0, 1, 0], spread: 0.4,
	speed: [3, 6], gravity: 9, drag: 1.5, size: [0.04, 0.08], sizeEnd: 0.3,
	life: [0.5, 1], look: ToonVfxLook.streak, stretch: 0.04, color: [1, 0.7, 0.3],
	isGrounded: true, age: 0.1, key: "spark-12",
};
vfx.emitParticles(sparkOptions);
vfx.emitParticles(sparkOptions);
메서드methodaddFireball(options)#0.4.0 부터since 0.4.0소스source

불덩이 더하기. (잡음으로 끓는 구가 부풀며 식어 연기가 되고 위로 떠오름) options: { position([x, y, z], 기본 [0, 0, 0]), radius, life, ramp, smokeColor, rise, growSeconds, boil, rim(덮는 꼴의 몫, 0 이면 더하는 빛만), age, key }

Adds a fireball. (A sphere boiling with noise swells, cools into smoke and rises) options: { position([x, y, z], default [0, 0, 0]), radius, life, ramp, smokeColor, rise, growSeconds, boil, rim(fraction of the covering look, 0 additive light only), age, key }

optionsobject
불덩이 값. (꼴은 위 머리 주석의 options)Fireball values. (The form is the options in the header comment above)

짝Counterpart: vanilla-engine ToonVfx.add_fireball

예제Example부풀어 식으며 떠오르는 불덩이A fireball that swells, cools and rises
import { ToonVfx } from "./vanilla.js";
const vfx = new ToonVfx(document.createElement("canvas").getContext("webgl2"));
vfx.setRamps([["#ffffff", "#ffe080", "#ff8020", "#801808", "#200804"]]);
vfx.addFireball({ position: [0, 1, 0], radius: 1.2, life: 1.5, ramp: 0, rise: 1, growSeconds: 0.25, boil: 0.4, smokeColor: [0.2, 0.18, 0.16], key: "barrel-3" });
메서드methodaddShockwave(options)#0.4.0 부터since 0.4.0소스source

충격파 띠 더하기. (빠르게 퍼지다 천천히, 바깥 끝이 말려 오르고 잡음으로 찢기며 엷어짐, 밑의 바닥이 잠깐 밝아짐, 바닥 높이에 놓임) options: { x, z, startRadius, endRadius, width, life, ramp, color, lift(말려 오르는 높이), height(바닥 위 띄움), delay, rim(덮는 꼴의 몫, 0 이면 더하는 빛만), age, key }

Adds a shockwave ring. (Spreads fast then slowly, the outer edge curls up and fades while torn by noise, the floor beneath brightens briefly, placed at floor height) options: { x, z, startRadius, endRadius, width, life, ramp, color, lift(curl-up height), height(offset above the floor), delay, rim(fraction of the covering look, 0 additive light only), age, key }

optionsobject
충격파 값. (꼴은 위 머리 주석의 options)Shockwave values. (The form is the options in the header comment above)

짝Counterpart: vanilla-engine ToonVfx.add_shockwave

예제Example조금 늦게 퍼지며 말려 오르는 충격파 띠A shockwave band that spreads a little later and curls up
import { ToonVfx } from "./vanilla.js";
const vfx = new ToonVfx(document.createElement("canvas").getContext("webgl2"));
vfx.addShockwave({ x: 0, z: 0, startRadius: 0.2, endRadius: 4, width: 0.8, life: 0.7, ramp: 0, color: [1, 0.9, 0.7], lift: 0.4, delay: 0.05, rim: 0.5 });
메서드methodaddDecal(options)#0.4.0 부터since 0.4.0소스source

바닥 자국 더하기. (그을음은 열기에서 식고 끝 1 초에 엷어짐, startRadius 에서 growSeconds 동안 radius 로 퍼질 수 있음, 바닥 높이에 놓임) options: { x, z, radius, startRadius, growSeconds, life, heatSeconds, slot(ToonVfxSlot), mode(ToonVfxDecalMode), ramp, tint, alpha, angle, ring, flicker(깜빡이는 반주기 초, 0 이면 없음), age, key }

Adds a floor decal. (Scorch cools from heat and fades in the last 1 second, can spread from startRadius to radius over growSeconds, placed at floor height) options: { x, z, radius, startRadius, growSeconds, life, heatSeconds, slot(ToonVfxSlot), mode(ToonVfxDecalMode), ramp, tint, alpha, angle, ring, flicker(flicker half-period in seconds, 0 none), age, key }

optionsobject
자국 값. (꼴은 위 머리 주석의 options, life 를 주지 않으면 바로 사라짐)Scorch values. (The form is the options in the header comment above, disappears at once if life is not given)

짝Counterpart: vanilla-engine ToonVfx.add_decal

예제Example퍼지며 식는 그을음과 깜빡이는 얼룩Soot that spreads and cools, and a flickering stain
import { ToonVfx, ToonVfxSlot, ToonVfxDecalMode } from "./vanilla.js";
const vfx = new ToonVfx(document.createElement("canvas").getContext("webgl2"));
vfx.addDecal({ x: 0, z: 0, radius: 1.5, startRadius: 0.4, growSeconds: 0.3, life: 10, heatSeconds: 2, slot: ToonVfxSlot.scorch, mode: ToonVfxDecalMode.scorch, ramp: 0 });
vfx.addDecal({ x: 3, z: 0, radius: 0.8, life: 6, mode: ToonVfxDecalMode.stain, tint: [0.2, 0.45, 0.1], alpha: 0.7, flicker: 0.25 });
메서드methodqueueBlobShadow(options)#0.4.0 부터since 0.4.0소스source

이번 프레임에만 그리는 발밑 그늘 넘기기. (가운데 alpha 에서 바깥으로 둥글게 엷어지는 그늘, 바닥 높이에 놓임) options: { x, z, radius, alpha(기본 0.45) }

Passes a foot shadow drawn only this frame. (Shade fading roundly outward from alpha at the center, placed at floor height) options: { x, z, radius, alpha(default 0.45) }

optionsobject
그늘 값. (꼴은 위 머리 주석의 options)Shadow values. (The form is the options in the header comment above)

짝Counterpart: vanilla-engine ToonVfx.queue_blob_shadow

예제Example캐릭터마다 발밑 그늘을 매 프레임 넘기기Submit a shadow under each character's feet every frame
import { ToonVfx, Matrix4, Vector3 } from "./vanilla.js";
const vfx = new ToonVfx(document.createElement("canvas").getContext("webgl2"));
const viewMatrix = Matrix4.createLookAt(Vector3.create(0, 4, 6), Vector3.create(0, 0, 0), Vector3.create(0, 1, 0));
const projectionMatrix = Matrix4.createPerspective(Math.PI / 4, 1, 0.1, 100);
const characterPositions = [[0, 0], [1.5, -0.5], [-1, 1]];
for (const position of characterPositions) {
	vfx.queueBlobShadow({ x: position[0], z: position[1], radius: 0.5 });
}
vfx.draw(viewMatrix, projectionMatrix);
메서드methodqueueDecal(options)#0.4.0 부터since 0.4.0소스source

이번 프레임에만 그리는 바닥 자국 넘기기. (꼴이 프레임마다 정해지는 것, addDecal 과 같고 나이 대신 heat(0 ~ 1)를 바로 준다, 돎과 씨앗은 주지 않으면 0)

Passes a floor decal drawn only this frame. (For shapes decided every frame, same as addDecal but gives heat (0 ~ 1) directly instead of age, rotation and seed are 0 if not given)

optionsobject
자국 값. (addDecal 의 값에 heat(0 ~ 1)와 seed)Scorch values. (Values of addDecal plus heat (0 ~ 1) and seed)

짝Counterpart: vanilla-engine ToonVfx.queue_decal

예제Example고른 자리에 흐르는 테와 빛 자국을 매 프레임 넘기기Submit a flowing ring and light mark at the chosen spot every frame
import { ToonVfx, ToonVfxSlot, ToonVfxDecalMode } from "./vanilla.js";
const vfx = new ToonVfx(document.createElement("canvas").getContext("webgl2"));
vfx.queueDecal({ x: 0, z: 0, radius: 1.2, mode: ToonVfxDecalMode.ring, tint: [0.4, 0.9, 1], heat: 1, alpha: 1, ring: [0.8, 0.06, 3, 0.6], seed: 4 });
vfx.queueDecal({ x: 2, z: 0, radius: 0.9, slot: ToonVfxSlot.glow, mode: ToonVfxDecalMode.glow, tint: [1, 0.6, 0.2], heat: 0.8, alpha: 0.9, angle: 0.5 });
메서드methodaddPlume(options)#0.4.0 부터since 0.4.0소스source

연기 기둥 더하기. (기둥이 솟고 갓이 말려 오르며 커지고, 갓 밑이 달아올랐다 식으며 엷어짐, 바닥 높이에 섬) options: { x, z, height, capRadius, stemRadius, life, ramp, smokeColor, age, key }

Adds a smoke plume. (The column rises, the cap curls up and grows, the underside of the cap heats up then cools and fades, stands at floor height) options: { x, z, height, capRadius, stemRadius, life, ramp, smokeColor, age, key }

optionsobject
연기 기둥 값. (꼴은 위 머리 주석의 options)Smoke column values. (The form is the options in the header comment above)

짝Counterpart: vanilla-engine ToonVfx.add_plume

예제Example큰 폭발 뒤에 솟는 연기 기둥A smoke column rising after a big explosion
import { ToonVfx } from "./vanilla.js";
const vfx = new ToonVfx(document.createElement("canvas").getContext("webgl2"));
vfx.addPlume({ x: 0, z: 0, height: 4, capRadius: 1.6, stemRadius: 0.35, life: 5, ramp: 0, smokeColor: [0.3, 0.28, 0.26], key: "blast-9-plume" });
메서드methodqueueBeam(options)#0.4.0 부터since 0.4.0소스source

이번 프레임에만 그리는 회전체 빔 넘기기. options: { start, end([x, y, z], 결은 start 에서 end 쪽으로 흐름), radius, isCore(심이면 흰빛, 아니면 램프의 겉집), alpha(기본 1), brightness, ramp, wobble, flowSpeed, grainRepeat(길이 한 칸마다의 결), time, seed }

Passes a solid-of-revolution beam drawn only this frame. options: { start, end([x, y, z], grain flows from start toward end), radius, isCore(white light if core, otherwise the ramp's outer sheath), alpha(default 1), brightness, ramp, wobble, flowSpeed, grainRepeat(grain per unit of length), time, seed }

optionsobject
빔 값. (꼴은 위 머리 주석의 options, radius 와 alpha 가 0 보다 커야 넘어감)Beam values. (The form is the options in the header comment above, submitted only if radius and alpha are above 0)

짝Counterpart: vanilla-engine ToonVfx.queue_beam

예제Example흰 심과 램프 겉집 두 겹의 빔A beam with two layers, a white core and a ramp shell
import { ToonVfx, Matrix4, Vector3 } from "./vanilla.js";
const vfx = new ToonVfx(document.createElement("canvas").getContext("webgl2"));
const viewMatrix = Matrix4.createLookAt(Vector3.create(4, 3, 4), Vector3.create(0, 1, -4), Vector3.create(0, 1, 0));
const projectionMatrix = Matrix4.createPerspective(Math.PI / 4, 1, 0.1, 100);
const start = [0, 1, 0];
const end = [0, 1, -8];
vfx.queueBeam({ start: start, end: end, radius: 0.12, isCore: true, alpha: 1, brightness: 1.5 });
vfx.queueBeam({ start: start, end: end, radius: 0.3, alpha: 0.8, ramp: 0, wobble: 0.15, flowSpeed: 6, grainRepeat: 0.6, seed: 2 });
vfx.draw(viewMatrix, projectionMatrix);
메서드methodqueueRibbon(options)#0.4.0 부터since 0.4.0소스source

이번 프레임에만 그리는 리본 넘기기. (점열을 카메라 쪽으로 편 띠) options: { points([[x, y, z], ...], 둘 이상), width, taper(0 이면 고른 너비, 1 이면 두 끝이 0), color, ramp, alpha(기본 1), brightness, grainRepeat, flow, glow(번짐 색 [r, g, b], 주면 흰 심과 그 색 둘레와 테 색 가장자리로 덮는다, 없으면 더하는 빛), rim(glow 가 없을 때 몸을 테 색으로 덮고 심은 색인 꼴의 몫, 0 이면 더하는 빛만) }

Passes a ribbon drawn only this frame. (A strip of a point sequence spread toward the camera) options: { points([[x, y, z], ...], two or more), width, taper(0 uniform width, 1 both ends 0), color, ramp, alpha(default 1), brightness, grainRepeat, flow, glow(glow color [r, g, b], if given covers with a white core, that color around it and rim-colored edges, otherwise additive light), rim(when there is no glow, fraction of the look that covers the body with the rim color and keeps the core in color, 0 additive light only) }

optionsobject
리본 값. (꼴은 위 머리 주석의 options, 점이 둘 이상이고 width 와 alpha(주지 않으면 1) 가 0 보다 커야 넘어감)Ribbon values. (The form is the options in the header comment above, submitted only with two or more points and width and alpha (1 if omitted) above 0)

짝Counterpart: vanilla-engine ToonVfx.queue_ribbon

예제Example휘두른 자취를 번짐 리본과 더하는 빛 리본으로A swing trail as a blur ribbon and an additive light ribbon
import { ToonVfx } from "./vanilla.js";
const vfx = new ToonVfx(document.createElement("canvas").getContext("webgl2"));
const trailPoints = [[-1, 1, 0], [-0.5, 1.3, -0.4], [0, 1.4, -0.6], [0.5, 1.3, -0.4], [1, 1, 0]];
vfx.queueRibbon({ points: trailPoints, width: 0.25, taper: 1, alpha: 1, brightness: 1.2, glow: [0.4, 0.8, 1] });
vfx.queueRibbon({ points: trailPoints, width: 0.1, color: [1, 0.9, 0.6], alpha: 0.8, grainRepeat: 2, flow: vfx.getTime() * 4 });
메서드methodqueueLightning(options)#0.4.0 부터since 0.4.0소스source

이번 프레임의 번개 넘기기. (축을 감아 내려가는 리본 여럿, 0.08 초마다 다시 꺾임, 같은 시각과 씨앗이면 같은 꼴) options: { start, end, radius(감는 반지름), count, width, turns(감는 바퀴), color, ramp, alpha, brightness, time(주지 않으면 이 바탕의 시계), seed, glow(리본의 번짐 색), rim(리본의 rim) }

Passes this frame's lightning. (Several ribbons winding down around an axis, re-bends every 0.08 seconds, same shape for the same time and seed) options: { start, end, radius(winding radius), count, width, turns(winding turns), color, ramp, alpha, brightness, time(this base's clock if not given), seed, glow(ribbon glow color), rim(ribbon rim) }

optionsobject
번개 값. (꼴은 위 머리 주석의 options, radius 와 width 는 꼭 준다)Lightning values. (The form is the options in the header comment above, radius and width must be given)

짝Counterpart: vanilla-engine ToonVfx.queue_lightning

예제Example하늘에서 내리치는 번개 셋을 이번 프레임에Three lightning bolts striking from the sky this frame
import { ToonVfx } from "./vanilla.js";
const vfx = new ToonVfx(document.createElement("canvas").getContext("webgl2"));
vfx.queueLightning({ start: [0, 4, 0], end: [0, 0, 0], radius: 0.15, count: 3, width: 0.06, turns: 1.5, color: [0.8, 0.9, 1], alpha: 1, brightness: 1.5, seed: 7 });
메서드methodqueueGlint(options)#0.4.0 부터since 0.4.0소스source

이번 프레임에만 그리는 빛 점 넘기기. (파티클과 같은 꼴, 나이 없이 그 자리에 그대로, setGlintCapacity 까지(기본 96)) options: { position([x, y, z], 기본 [0, 0, 0]), size(기본 0.2), color, ramp, look, brightness, alpha(기본 1), angle, rim(파티클의 rim 과 같음) }

Passes a glint drawn only this frame. (Same look as particles, stays in place without age, up to setGlintCapacity (default 96)) options: { position([x, y, z], default [0, 0, 0]), size(default 0.2), color, ramp, look, brightness, alpha(default 1), angle, rim(same as the particle rim) }

optionsobject
빛 점 값. (꼴은 위 머리 주석의 options, size 는 꼭 준다)Light point values. (The form is the options in the header comment above, size must be given)

짝Counterpart: vanilla-engine ToonVfx.queue_glint

예제Example보석 위에 반짝이는 빛살을 매 프레임Light rays twinkling over a gem every frame
import { ToonVfx, ToonVfxLook } from "./vanilla.js";
const vfx = new ToonVfx(document.createElement("canvas").getContext("webgl2"));
vfx.setGlintCapacity(32);
const twinkle = 0.5 + 0.5 * Math.sin(vfx.getTime() * 6);
vfx.queueGlint({ position: [0.5, 1.2, 0], size: 0.4 * twinkle, look: ToonVfxLook.star, color: [1, 0.95, 0.7], angle: 0.3, brightness: 1.5 });
메서드methodaddLightning(options)#0.4.0 부터since 0.4.0소스source

사는 동안 다시 꺾이는 번개 더하기. (그릴 때마다 queueLightning 으로 넘긴다, 끝 0.1 초에 엷어짐, age 가 음수면 그만큼 늦게 나타남) options: { start, end, life(초), age, radius, count, width, turns, color, ramp, alpha, brightness, seed(주지 않으면 무작위), glow, rim, key }

Adds lightning that re-bends during its lifetime. (Passed with queueLightning on each draw, fades in the last 0.1 seconds, appears that much later if age is negative) options: { start, end, life(seconds), age, radius, count, width, turns, color, ramp, alpha, brightness, seed(random if not given), glow, rim, key }

optionsobject
번개 값. (꼴은 위 머리 주석의 options)Lightning values. (The form is the options in the header comment above)

짝Counterpart: vanilla-engine ToonVfx.add_lightning

예제Example0.4 초 동안 다시 꺾이며 사는 번개Lightning that lives for 0.4 seconds, re-bending as it goes
import { ToonVfx, Matrix4, Vector3 } from "./vanilla.js";
const vfx = new ToonVfx(document.createElement("canvas").getContext("webgl2"));
const viewMatrix = Matrix4.createLookAt(Vector3.create(0, 2, 6), Vector3.create(0, 2, 0), Vector3.create(0, 1, 0));
const projectionMatrix = Matrix4.createPerspective(Math.PI / 4, 1, 0.1, 100);
vfx.addLightning({ start: [0, 4, 0], end: [0.5, 0, 0.2], life: 0.4, count: 2, width: 0.08, radius: 0.2, glow: [0.5, 0.7, 1], key: "strike-5" });
for (let frameIndex = 0; frameIndex < 3; ++frameIndex) {
	vfx.update(1 / 60);
	vfx.draw(viewMatrix, projectionMatrix);
}
메서드methodaddFlash(options)#0.4.0 부터since 0.4.0소스source

화면 섬광 더하기. (뷰포트를 그 색으로 잠깐 덮고 빠르게 걷힘) options: { color([r, g, b], 기본 흰), strength(처음 덮는 몫, 기본 0.8), life(초, 기본 0.08), age, key }

Adds a screen flash. (Briefly covers the viewport with its color and fades quickly) options: { color([r, g, b], default white), strength(initial covering fraction, default 0.8), life(seconds, default 0.08), age, key }

optionsobject
섬광 값. (꼴은 위 머리 주석의 options)Flash values. (The form is the options in the header comment above)

짝Counterpart: vanilla-engine ToonVfx.add_flash

예제Example터질 때 화면을 잠깐 밝게 덮기Briefly cover the screen with light on an explosion
import { ToonVfx } from "./vanilla.js";
const vfx = new ToonVfx(document.createElement("canvas").getContext("webgl2"));
vfx.addFlash({ color: [1, 0.9, 0.7], strength: 0.6, life: 0.12, key: "blast-9-flash" });
메서드methodaddShake(strength)#0.4.0 부터since 0.4.0소스source

카메라 흔들림 더하기. (장면 길이의 최대 오프셋, 엔진 Shaker 가 위상이 다른 두 사인파와 지수 감쇠로 셈, 흔들리는 중이면 센 쪽) 자리 3 축과 돌림, 겹쳐 더하기, 나이로 이어 붙이기는 CameraShake 를 쓴다. (Camera3D.setViewOffset 으로 건다)

Adds camera shake. (Maximum offset in scene length, computed by the engine Shaker with two phase-shifted sine waves and exponential decay, the stronger one if already shaking) Use CameraShake for 3 position axes and rotation, stacking and continuing by age. (applied with Camera3D.setViewOffset)

strengthnumber
흔들림의 최대 오프셋. (장면 길이)Maximum offset of the shake. (Scene length)

짝Counterpart: vanilla-engine ToonVfx.add_shake

예제Example흔들림을 카메라 오른쪽과 위쪽에 더하기Add the shake to the camera's right and up
import { ToonVfx, Matrix4, Vector3 } from "./vanilla.js";
const vfx = new ToonVfx(document.createElement("canvas").getContext("webgl2"));
vfx.addShake(0.2);
vfx.update(1 / 60);
const shake = vfx.readShake();
const eye = Vector3.create(shake.x, 1.5 + shake.y, 6);
const target = Vector3.create(shake.x, 1.5 + shake.y, 0);
const viewMatrix = Matrix4.createLookAt(eye, target, Vector3.create(0, 1, 0));
const isStill = !vfx.isShaking();
메서드methodreadShake()#0.4.0 부터since 0.4.0소스source

지금의 카메라 흔들림. (장면 길이, x 는 카메라 오른쪽, y 는 카메라 위쪽으로 카메라 자리와 보는 곳에 같이 더한다)

Current camera shake. (Scene length, x toward the camera's right and y toward the camera's up, added to both the camera position and the look-at point)

반환ReturnsVector2 흔들림 오프셋. (장면 길이, x 는 카메라 오른쪽, y 는 카메라 위쪽)Shake offset. (Scene length, x is the camera's right, y is the camera's up)

짝Counterpart: vanilla-engine ToonVfx.read_shake

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

카메라가 흔들리는 중인지.

Whether the camera is shaking.

반환Returnsboolean 흔들리는 중이면 true.true while shaking.

짝Counterpart: vanilla-engine ToonVfx.is_shaking

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

그리기. (바닥 자국, 띠, 연기 기둥, 불덩이, 빔, 리본, 파티클, 섬광 차례, 사는 번개는 이번 프레임의 리본으로 넘김, 넘긴 것은 그린 뒤 비움) 보기 행렬에서 카메라 쪽, 오른쪽, 위쪽, 자리를 읽는다. 투영이 원근이면 빔과 리본은 카메라 자리를 향하고, 직교면 카메라 쪽을 향한다.

Draws. (In the order floor decals, rings, smoke plumes, fireballs, beams, ribbons, particles, flashes, living lightning is passed as this frame's ribbons, passed items are cleared after drawing) Reads the camera direction, right, up and position from the view matrix. If the projection is perspective, beams and ribbons face the camera position, if orthographic they face the camera direction.

viewMatrixMatrix4
카메라의 보기 행렬.View matrix of the camera.
projectionMatrixMatrix4
투영 행렬. (원근이나 직교)Projection matrix. (Perspective or orthographic)

짝Counterpart: vanilla-engine ToonVfx.draw

예제Example직교 투영 장면에 효과 그리기Draw effects in an orthographic projection scene
import { ToonVfx, ToonVfxLook, Matrix4, Vector3 } from "./vanilla.js";
const vfx = new ToonVfx(document.createElement("canvas").getContext("webgl2"));
const viewMatrix = Matrix4.createLookAt(Vector3.create(5, 5, 5), Vector3.create(0, 0, 0), Vector3.create(0, 1, 0));
const projectionMatrix = Matrix4.createOrthographic(-4, 4, -4, 4, 0.1, 50);
vfx.emitParticles({ count: 20, position: [0, 0.5, 0], look: ToonVfxLook.glow, color: [0.4, 0.8, 1], speed: 1, size: 0.4, life: 1 });
vfx.queueBeam({ start: [-2, 0.5, 0], end: [2, 0.5, 0], radius: 0.1, isCore: true, alpha: 1 });
vfx.update(0.1);
vfx.draw(viewMatrix, projectionMatrix);
메서드methodreadFrame(viewMatrix, projectionMatrix)#0.4.0 부터since 0.4.0소스source

그리는 프레임의 카메라. ({ viewProjectionElements, viewDirection(장면에서 카메라 쪽), cameraRight, cameraUp, cameraPoint([자리, 1] 원근, [카메라 쪽, 0] 직교) })

Camera of the frame being drawn. ({ viewProjectionElements, viewDirection(toward the camera in the scene), cameraRight, cameraUp, cameraPoint([position, 1] perspective, [camera direction, 0] orthographic) })

viewMatrixMatrix4
카메라의 보기 행렬.View matrix of the camera.
projectionMatrixMatrix4
투영 행렬. (원근이나 직교)Projection matrix. (Perspective or orthographic)

반환Returnsobject { viewProjectionElements, viewDirection, cameraRight, cameraUp, cameraPoint }.

메서드methoduseProgram(shaderProgram, frame)#0.4.0 부터since 0.4.0소스source

프로그램을 쓰고 보기와 투영과 아틀라스 유니폼 올리기.

Uses the program and uploads the view, projection and atlas uniforms.

shaderProgramShaderProgram
쓸 효과 셰이더.Effect shader to use.
frameobject
readFrame 이 돌려준 그리는 프레임의 카메라.Camera of the drawing frame returned by readFrame.
메서드methoddestroy()#0.4.0 부터since 0.4.0소스source

다 쓴 뒤 지우기.

Deletes after use.

짝Counterpart: vanilla-engine ToonVfx.destroy

상수Constants

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

색 램프 줄의 수 상한. (아틀라스의 램프 칸 하나에 여덟 줄)

Maximum number of color ramp rows. (Eight rows in one ramp cell of the atlas)

반환Returnsnumber

짝Counterpart: vanilla-engine TOON_VFX_MAXIMUM_RAMPS

상수constantTOON_VFX_DEFAULT_PARTICLE_CAPACITY = 3000#0.4.0 부터since 0.4.0소스source

한꺼번에 떠 있는 파티클의 기본 상한. (넘으면 가장 오래 전에 낸 것부터 덮는다)

Default maximum number of particles alive at once. (When exceeded, the oldest emitted are overwritten first)

반환Returnsnumber

짝Counterpart: vanilla-engine TOON_VFX_DEFAULT_PARTICLE_CAPACITY

ToonVfxSlotenum

짝Counterpart: vanilla-engine ToonVfxSlot

아틀라스 오른쪽 반의 칸. (셰이더의 readSlot 번호와 같다, 6, 7, 11 ~ 15 는 비어 있다)

Cells of the atlas's right half. (Same as the shader's readSlot index, 6, 7, 11 ~ 15 are empty)

예제Example바닥 자국에 쓸 칸 고르기Choose the cell to use for a floor scorch
import { ToonVfx, ToonVfxSlot, ToonVfxDecalMode } from "./vanilla.js";
const vfx = new ToonVfx(document.createElement("canvas").getContext("webgl2"));
vfx.addDecal({ x: 0, z: 0, radius: 1.2, life: 8, slot: ToonVfxSlot.dent, mode: ToonVfxDecalMode.scorch });
vfx.queueDecal({ x: 2, z: 0, radius: 1, slot: ToonVfxSlot.glow, mode: ToonVfxDecalMode.glow, tint: [1, 0.6, 0.2], heat: 1 });
이름Name값Value설명Description
soft0부드러운 알갱이.Soft grain.
streak1불꽃 줄기. (v 1 쪽이 머리)Flame streak. (The v 1 side is the head)
star2빛살.Light ray.
shockBand3충격 띠. (u 는 둘레로 이어지는 타일, v 는 안쪽 0 에서 바깥 1)Shock ring. (u is a tile continuing around the circumference, v goes from inner 0 to outer 1)
beamGrain4빔 결. (두 방향 타일)Beam grain. (Tiled in both directions)
scorch5그을음. (알파는 어둡게 덮는 몫, 빨간 채널은 열기)Scorch. (Alpha is the darkening cover fraction, the red channel is heat)
ramps8색 램프 여덟 줄.Eight color ramp rows.
dent9패인 땅.Cratered ground.
glow10넓은 둘레 빛.Wide halo glow.

ToonVfxLookenum

짝Counterpart: vanilla-engine ToonVfxLook

파티클의 꼴.

Particle look.

예제Example덮는 연기와 바닥에 멈추는 흙 알갱이Covering smoke and soil grains that stop on the floor
import { ToonVfx, ToonVfxLook } from "./vanilla.js";
const vfx = new ToonVfx(document.createElement("canvas").getContext("webgl2"));
vfx.emitParticles({ count: 8, position: [0, 0.5, 0], look: ToonVfxLook.smoke, color: [0.5, 0.48, 0.45], speed: 0.4, rise: 0.8, size: 0.6, sizeEnd: 2.5, life: [1.5, 2.5], spin: [-1, 1] });
vfx.emitParticles({ count: 20, position: [0, 0.2, 0], look: ToonVfxLook.grit, color: [0.35, 0.28, 0.2], speed: [2, 4], gravity: 9, isUpward: true, isGrounded: true, size: 0.06, life: 1.2 });
이름Name값Value설명Description
soft0부드러운 알갱이. (더하는 빛)Soft grain. (Additive light)
streak1속도 쪽으로 늘인 불꽃 줄기. (더하는 빛, stretch 가 속도에 곱하는 늘임)Flame streak stretched along velocity. (Additive light, stretch is the stretch multiplied by velocity)
smoke2연기 플립북. (덮기)Smoke flipbook. (Covering)
star3빛살. (더하는 빛)Light ray. (Additive light)
ember4깜빡이는 불씨. (더하는 빛)Flickering ember. (Additive light)
glow5넓은 둘레 빛. (더하는 빛)Wide halo glow. (Additive light)
grit6빛을 내지 않는 돌과 흙 알갱이. (덮기)Non-emissive rock and dirt grain. (Covering)

ToonVfxShapeenum

짝Counterpart: vanilla-engine ToonVfxShape

파티클을 내는 꼴.

Particle emission shape.

예제Example바닥 고리로 퍼지는 먼지와 선을 따라 늘어선 빛Dust spreading in a floor ring and lights lined up along a line
import { ToonVfx, ToonVfxLook, ToonVfxShape } from "./vanilla.js";
const vfx = new ToonVfx(document.createElement("canvas").getContext("webgl2"));
vfx.emitParticles({ count: 32, position: [0, 0.1, 0], shape: ToonVfxShape.ring, radius: 0.5, speed: 3, drag: 4, look: ToonVfxLook.soft, size: 0.15, life: 0.5 });
vfx.emitParticles({ count: 40, position: [0, 1, 0], shape: ToonVfxShape.line, direction: [1, 0, 0], length: 5, radius: 0.05, speed: 0.5, look: ToonVfxLook.glow, size: 0.3, life: 0.4 });
이름Name값Value설명Description
pointpoint한 점에서 모든 쪽으로.From one point in all directions.
spheresphere반지름 radius 공 안에서 바깥쪽으로.Outward within a ball of radius radius.
ringring바닥과 나란한 고리 위에서 바깥쪽으로.Outward on a ring parallel to the floor.
discdisc바닥과 나란한 원판 안에서 바깥쪽으로.Outward within a disc parallel to the floor.
coneconedirection 을 가운데로 spread 각 안의 원뿔.Cone within the spread angle centered on direction.
linelinedirection 쪽으로 length 까지의 선 위(둘레 radius 안)에서 direction 쪽으로.Toward direction, from a line along direction up to length (within radius around it).

ToonVfxDecalModeenum

짝Counterpart: vanilla-engine ToonVfxDecalMode

바닥 자국의 꼴.

Floor decal mode.

예제Example기름 윤 자국과 발밑 그늘An oily sheen mark and a shadow under the feet
import { ToonVfx, ToonVfxSlot, ToonVfxDecalMode } from "./vanilla.js";
const vfx = new ToonVfx(document.createElement("canvas").getContext("webgl2"));
vfx.addDecal({ x: 0, z: 0, radius: 1, life: 6, slot: ToonVfxSlot.soft, mode: ToonVfxDecalMode.sheen, tint: [0.05, 0.05, 0.08] });
vfx.queueDecal({ x: 2, z: 0, radius: 0.6, mode: ToonVfxDecalMode.shade, alpha: 0.5 });
이름Name값Value설명Description
scorch0알파로 어둡게 덮고 빨간 채널의 금에서 열기가 식는다.Darkens by alpha, and heat cools in the cracks of the red channel.
glow1칸의 알파만큼 더하는 빛.Additive light by the cell's alpha.
ring2둘레로 흐르는 잡음 테. (ring 이 (테 반지름, 테 너비, 잡음 잘기, 흐르는 빠르기) 의 반지름 몫)Noise rim flowing around the circumference. (ring is the radius fractions of (rim radius, rim width, noise fineness, flow speed))
stain3칸의 알파만큼 tint 색으로 덮고, 칸의 가운데 짙기(테 둘레)는 테 색(setRimColor) 쪽으로 물든다. (밝은 바닥의 얼룩, 서리)Covers with the tint color by the cell's alpha, and the cell's center density (around the rim) is tinted toward the rim color (setRimColor). (Stains on bright floors, frost)
sheen4칸의 알파 몸을 tint 로 덮고 몸 가장자리에 흰 윤을 두른다. (기름 윤)Covers the cell's alpha body with tint and puts a white sheen around the body's edges. (Oil sheen)
shade5가운데에서 바깥으로 둥글게 엷어지는 그늘. (알파만큼 어둡게 덮음, 칸은 보지 않음, 발밑 그늘 queueBlobShadow)Shade fading roundly from the center outward. (Darkens by alpha, ignores the cell, foot shadow queueBlobShadow)