vanilladocs
vanillapunch.com
API / effect/heathazeeffect

effect/heathazeeffect

아지랑이 효과 컴포넌트. (원본 effect/heathazeeffect.js 의 HeatHazeEffect)

  • 이 노드가 그려지기 전까지 화면에 그려진 것을 노드 영역만큼 떠 와서, 한 줄씩 사인 곡선을 따라 좌우로 흔들어 다시 그린다. 그래서 씬의 맨 위(마지막)에 그려지는 노드에 붙여야 보인다. 자식 노드는 효과 위에 그려진다.
  • 원본처럼 묶음을 내보낸 뒤 노드의 화면 영역(픽셀)을 copyTexSubImage2D 로 텍스처에 떠 오고, 줄마다 쿼드 한 장씩 정점 색 쿼드(draw_colored_quads)로 그린다. 노드 영역이 화면 밖으로 나가면 화면 가장자리 픽셀을 늘인다. (CLAMP_TO_EDGE)
  • 원본처럼 노드에 붙이는 컴포넌트이고, 붙을 때 노드 content_size 가 비어 있으면 300 x 300 으로 정한다.
  • 원본과 다른 점:
  • 떠 온 텍스처는 GL 자원이라 다 쓰면 destroy() 를 부른다. 원본처럼 텍스처를 만든 컨텍스트(약한 손잡이)를 쥐어 인자가 없고, 컴포넌트가 버려질 때(Drop, 노드를 지우거나 씬을 내릴 때)도 스스로 지운다. (ScreenEffect 와 같다)
  • 줄이 한 번에 그릴 수 있는 정점 수(Graphic 한도)를 넘으면 나눠 그린다. 원본은 배열을 늘려 한 번에 그린다.

Heat haze effect component. (HeatHazeEffect of the original effect/heathazeeffect.js)

  • Copies what was drawn on screen before this node, as large as the node area, and redraws it shaking each row left and right along a sine curve. So it shows only when attached to a node drawn at the top (last) of the scene. Child nodes are drawn over the effect.
  • Like the original, it flushes the batch, copies the node's screen area (pixels) into a texture with copyTexSubImage2D, and draws one quad per row as vertex color quads (draw_colored_quads). When the node area goes off screen, the edge pixels of the screen are stretched. (CLAMP_TO_EDGE)
  • Like the original, it is a component attached to a node, and sets the node content_size to 300 x 300 when attached if it is empty.
  • Differences from the original:
  • The copied texture is a GL resource, so call destroy() when done. Like the original it holds the context that made the texture (a weak handle) so it takes no argument, and it also deletes it by itself when the component is dropped (Drop, when the node is removed or the scene is unloaded). (same as ScreenEffect)
  • When a row exceeds the vertex count that can be drawn at once (the Graphic limit), it is drawn in parts. The original grows the array and draws at once.

HeatHazeEffectstruct traits Default, Drop, Component

짝Counterpart: vanilla.js HeatHazeEffect소스source

아지랑이 효과 컴포넌트.

  • 맨 마지막에 그려지는 노드에 붙인다. 그 노드 영역에 앞서 그려진 화면을 줄마다 sin(시계 + 줄 y x 빈도) x 폭만큼 좌우로 민다.

Heat haze effect component.

  • Attached to the node drawn last. Pushes the screen drawn before it in that node's area left and right per row by sin(clock + row y x frequency) x amplitude.
예제Example노드에 붙여 폭과 빈도 정하기Attach to a node and set the amplitude and frequency
use vanilla::{HeatHazeEffect, NodeTree, Vector2};

let mut node_tree = NodeTree::new();
let root_id = node_tree.get_root_id();
let haze_id = node_tree.create_child(root_id, "HeatHaze");
let heat_haze_effect = node_tree.add_component(haze_id, HeatHazeEffect::new()).expect("heat haze");
heat_haze_effect.set_amplitude(6.0);
heat_haze_effect.set_frequency(0.08);
assert_eq!(heat_haze_effect.calculate_row_offset(0.0), 0.0);
assert!(heat_haze_effect.calculate_row_offset(10.0).abs() <= 6.0);
assert_eq!(node_tree[haze_id].get_content_size(), Vector2::create(300.0, 300.0));
생성자constructorpub fn new() -> HeatHazeEffect#0.3.2 부터since 0.3.2소스source

생성. (속도 2, 폭 3, 빈도 0.05)

Creates. (speed 2, amplitude 3, frequency 0.05)

반환ReturnsHeatHazeEffect 시계가 0 이고 떠 온 텍스처가 없는 효과.An effect with the clock at 0 and no copied texture.

짝Counterpart: vanilla.js HeatHazeEffect.constructor

메서드methodpub fn set_speed(&mut self, value: f64)#0.3.2 부터since 0.3.2소스source

속도 설정.

Sets the speed.

valuef64
흔들림 시계가 흐르는 빠르기. (초당 라디안, tick 마다 time_delta x 속도만큼 흐른다. 기본 2)Speed at which the sway clock runs. (radians per second, advances by time_delta x speed every tick. default 2)

짝Counterpart: vanilla.js HeatHazeEffect.setSpeed

메서드methodpub fn get_speed(&self) -> f64#0.3.2 부터since 0.3.2소스source

속도 반환.

Returns the speed.

반환Returnsf64 흔들림 시계가 흐르는 빠르기. (초당 라디안)Speed at which the sway clock runs. (radians per second)

짝Counterpart: vanilla.js HeatHazeEffect.getSpeed

메서드methodpub fn set_amplitude(&mut self, value: f64)#0.3.2 부터since 0.3.2소스source

강도 설정.

Sets the intensity.

valuef64
줄이 좌우로 밀리는 가장 큰 폭. (노드 좌표 픽셀, 기본 3)Largest amplitude a row is pushed left or right. (node coordinate pixels, default 3)

짝Counterpart: vanilla.js HeatHazeEffect.setAmplitude

메서드methodpub fn get_amplitude(&self) -> f64#0.3.2 부터since 0.3.2소스source

강도 반환.

Returns the strength.

반환Returnsf64 줄이 좌우로 밀리는 가장 큰 폭. (노드 좌표 픽셀)Largest amplitude a row is pushed left or right. (node coordinate pixels)

짝Counterpart: vanilla.js HeatHazeEffect.getAmplitude

메서드methodpub fn set_frequency(&mut self, value: f64)#0.3.2 부터since 0.3.2소스source

빈도 설정.

Sets the frequency.

valuef64
줄 위치에 곱하는 빈도. (노드 세로 1 픽셀마다 라디안, 클수록 물결이 촘촘하다. 기본 0.05)Frequency multiplied by the row position. (radians per vertical node pixel, larger means denser waves. default 0.05)

짝Counterpart: vanilla.js HeatHazeEffect.setFrequency

메서드methodpub fn get_frequency(&self) -> f64#0.3.2 부터since 0.3.2소스source

빈도 반환.

Returns the frequency.

반환Returnsf64 줄 위치에 곱하는 빈도. (노드 세로 1 픽셀마다 라디안)Frequency multiplied by the row position. (radians per vertical node pixel)

짝Counterpart: vanilla.js HeatHazeEffect.getFrequency

메서드methodpub fn get_timer(&self) -> f64#0.3.2 부터since 0.3.2소스source

흔들림 시계 반환. (tick 마다 time_delta * 속도씩 흐른다)

Returns the sway clock. (advances by time_delta * speed every tick)

반환Returnsf64 흔들림 시계. (라디안, 처음 0)Sway clock. (radians, initially 0)

짝Counterpart: vanilla.js HeatHazeEffect.getTimer

메서드methodpub fn calculate_row_offset(&self, local_y: f64) -> f64#0.3.2 부터since 0.3.2소스source

줄의 좌우 흔들림. (sin(시계 + 줄 위치 * 빈도) * 폭)

Horizontal wobble of a line. (sin(clock + line position * frequency) * amplitude)

local_yf64
줄의 노드 로컬 y. (노드 위가 0)Node local y of the row. (top of the node is 0)

반환Returnsf64 줄을 밀 x 거리. (노드 좌표, -폭 ~ 폭)x distance to push the row. (node coordinates, -amplitude ~ amplitude)

짝Counterpart: vanilla.js HeatHazeEffect.calculateRowOffset

메서드methodpub fn destroy(&mut self)#0.3.2 부터since 0.3.2소스source

GL 자원 해제. (떠 온 텍스처, 원본 destroy)

  • 버려질 때(Drop)도 스스로 부른다. GL 컨텍스트가 이미 사라졌으면 텍스처도 같이 사라졌으므로 잊기만 한다.

Releases GL resources. (the copied texture, the original destroy)

  • Also called by itself when dropped (Drop). If the GL context is already gone, the texture is gone with it, so it only forgets it.

짝Counterpart: vanilla.js HeatHazeEffect.destroy