effect/heathazeeffect
아지랑이 효과 컴포넌트.
Heat haze effect component.
HeatHazeEffectextends Component
아지랑이 효과 컴포넌트.
- 붙은 노드가 그려지기 전까지의 캔버스 내용을 노드 영역만큼 가져와서 일렁이는 효과를 줍니다.
- 따라서 씬의 가장 마지막(맨 위)에 그려지는 노드에 붙여야 효과가 보입니다. 자식 노드는 효과 위에 그려진다.
- ParticleSystem, TrailRenderer 처럼 노드에 붙이는 컴포넌트다. 영역은 노드의 내용 크기(contentSize)와 피봇을 쓴다. 붙을 때 노드 내용 크기가 비어 있으면 300 x 300 으로 정한다.
- 사용:
const heatHazeEffect = node.addComponent(HeatHazeEffect);
heatHazeEffect.setAmplitude(4);- WebGL Graphic 에서는 묶음을 먼저 그린 뒤, 노드 영역의 화면 바운딩 박스(드로잉 버퍼 픽셀)를 copyTexSubImage2D 로 텍스처에 떠 오고, 줄마다 쿼드 한 장씩 정점 색 쿼드(drawColoredQuads)로 사인 곡선만큼 옮겨 그린다. (러스트 vanilla-engine 과 같은 방식)
- 영역이 화면 밖으로 나가면 화면 가장자리 픽셀을 늘인다. (CLAMP_TO_EDGE)
- 떠 온 텍스처는 GL 자원이라 다 쓰면 destroy() 를 부른다.
Heat haze effect component.
- Takes the canvas content drawn before the attached node, over the node's area, and applies a shimmering effect.
- Therefore the effect is visible only when attached to the node drawn last (topmost) in the scene. Child nodes are drawn over the effect.
- A component attached to a node, like ParticleSystem and TrailRenderer. The area uses the node's content size (contentSize) and pivot. If the node's content size is empty when attached, it is set to 300 x 300.
- Usage:
const heatHazeEffect = node.addComponent(HeatHazeEffect);
heatHazeEffect.setAmplitude(4);- In the WebGL Graphic, it flushes the batch first, copies the screen bounding box of the node area (drawing buffer pixels) into a texture with copyTexSubImage2D, and redraws it shifted along a sine curve, one quad per line, as vertex color quads (drawColoredQuads). (same method as the Rust vanilla-engine)
- If the area goes off screen, the screen edge pixels are stretched. (CLAMP_TO_EDGE)
- The copied texture is a GL resource, so call destroy() when done with it.
import { Engine, EngineConfiguration, Scene, WorldNode, HeatHazeEffect, Colors, Rect, Vector2 } from "./build/vanilla.js";
class MainScene extends Scene {
initialize(engine) {
super.initialize(engine);
const hazeNode = new WorldNode();
hazeNode.setLocalPosition(Vector2.create(320, 180));
hazeNode.setContentSize(Vector2.create(300, 240));
const root = this.getRoot();
root.addChild(hazeNode);
const heatHazeEffect = hazeNode.addComponent(HeatHazeEffect);
heatHazeEffect.setAmplitude(4);
heatHazeEffect.setFrequency(0.08);
heatHazeEffect.setSpeed(3);
}
preDraw(graphic) {
super.preDraw(graphic);
graphic.setFillColor(Colors.white);
graphic.drawRect(Rect.create(220, 100, 200, 160));
}
}
const engineConfiguration = new EngineConfiguration();
const engine = new Engine(engineConfiguration);
engine.run(new MainScene());노드에 붙음. (노드 내용 크기가 비어 있으면 300 x 300)
Attached to a node. (300 x 300 if the node's content size is empty)
- nodeComponentNode
- 붙는 노드.Node being attached to.
갱신.
Update.
- timeDeltanumber
- 지난 시간. (초, 속도를 곱해 흔들림 시계에 더한다)Elapsed time. (seconds, multiplied by the speed and added to the wave clock)
떠 올 텍스처 준비. (크기가 바뀌면 다시 잡는다, 화면과 같은 RGB8)
Prepares the texture to copy into. (reallocated when the size changes, RGB8 like the screen)
- graphicGraphic
- 텍스처를 만들 그래픽.Graphic to make the texture with.
- widthnumber
- 가로. (드로잉 버퍼 픽셀)Width. (drawing buffer pixels)
- heightnumber
- 세로. (드로잉 버퍼 픽셀)Height. (drawing buffer pixels)
반환ReturnsWebGLTexture 떠 올 텍스처.Texture to capture into.
떠 온 텍스처 지우기.
Deletes the copied texture.
파괴. (떠 온 텍스처를 지운다)
Destroys. (deletes the copied texture)
짝Counterpart: vanilla-engine HeatHazeEffect.destroy
속도 설정.
Sets the speed.
- valuenumber
- 흔들림 시계가 흐르는 빠르기. (초당 라디안, 기본 2)Speed of the wave clock. (radians per second, default 2)
짝Counterpart: vanilla-engine HeatHazeEffect.set_speed
속도 반환.
Returns the speed.
반환Returnsnumber 흔들림 빠르기. (초당 라디안)Wave speed. (radians per second)
짝Counterpart: vanilla-engine HeatHazeEffect.get_speed
강도 설정.
Sets the intensity.
- valuenumber
- 좌우로 옮기는 폭. (노드 로컬 픽셀, 기본 3)Horizontal shift amount. (node local pixels, default 3)
짝Counterpart: vanilla-engine HeatHazeEffect.set_amplitude
강도 반환.
Returns the strength.
반환Returnsnumber 흔들림 폭. (노드 로컬 픽셀)Wave amplitude. (node local pixels)
짝Counterpart: vanilla-engine HeatHazeEffect.get_amplitude
빈도 설정.
Sets the frequency.
- valuenumber
- 줄 위치에 곱하는 빈도. (노드 로컬 픽셀당 라디안, 기본 0.05)Frequency multiplied by the row position. (radians per node local pixel, default 0.05)
짝Counterpart: vanilla-engine HeatHazeEffect.set_frequency
빈도 반환.
Returns the frequency.
반환Returnsnumber 줄 위치에 곱하는 빈도. (노드 로컬 픽셀당 라디안)Frequency multiplied by the row position. (radians per node local pixel)
짝Counterpart: vanilla-engine HeatHazeEffect.get_frequency
흔들림 시계 반환. (tick 마다 timeDelta * 속도씩 흐른다)
Returns the wobble clock. (advances by timeDelta * speed every tick)
반환Returnsnumber 흔들림 시계. (라디안)Wave clock. (radians)
짝Counterpart: vanilla-engine HeatHazeEffect.get_timer
그리는 사각형을 rect 에 적기. (오버라이드: 내용 영역을 줄마다 좌우로 흔들림 폭만큼 옮겨 그리므로 양옆으로 폭만큼 넘친다)
Writes the drawn rectangle to rect. (Override: each row of the content area is shifted left and right by the wobble amplitude, so it spills by that much on both sides)
- rectRect
- 그리는 사각형을 적을 곳. (노드 내용 영역의 왼쪽 위가 원점)Where to write the drawn rectangle. (origin at the top-left of the node's content area)
반환Returnsboolean 노드에 붙어 있으면 참.True if attached to a node.
import { WorldNode, HeatHazeEffect, Rect, Vector2 } from "./build/vanilla.js";
const node = new WorldNode();
node.setContentSize(Vector2.create(100, 40));
const heatHazeEffect = node.addComponent(HeatHazeEffect);
heatHazeEffect.setAmplitude(4);
const drawnRect = Rect.zero();
heatHazeEffect.calculateDrawnRect(drawnRect);
console.log(drawnRect.position.x, drawnRect.size.x);줄의 좌우 흔들림. (sin(시계 + 줄 위치 * 빈도) * 폭)
Horizontal wobble of a line. (sin(clock + line position * frequency) * amplitude)
- localYnumber
- 줄의 위쪽 위치. (노드 로컬 픽셀)Top position of the row. (node local pixels)
반환Returnsnumber 좌우로 옮길 거리. (노드 로컬 픽셀)Horizontal shift distance. (node local pixels)
짝Counterpart: vanilla-engine HeatHazeEffect.calculate_row_offset