graphics3d/bloomeffect
블룸 이펙트. (밝은 영역 추출 → 하프 해상도 가우시안 블러 핑퐁)
Bloom effect. (bright area extraction → half resolution Gaussian blur ping-pong)
BloomEffectextends Object
블룸 이펙트. (밝은 영역 추출 → 하프 해상도 가우시안 블러 핑퐁)
- render() 결과 텍스처를 최종 합성 패스에서 가산하는 방식으로 사용한다.
- 주고받는 판은 기본 RGBA8 이라 1 을 넘는 밝은 값이 잘린다. setUseFloatColor(true) 면 RGBA16F 로 지어 HDR 값을 그대로 흐린다.
Bloom effect. (bright area extraction → half resolution Gaussian blur ping-pong)
- Used by additively blending the render() result texture in the final composite pass.
- The ping-pong buffers are RGBA8 by default, so bright values above 1 are clipped. With setUseFloatColor(true) they are built as RGBA16F and HDR values are blurred as is.
import { BloomEffect, RenderTarget, FullscreenPass } from "./build/vanilla.js";
const width = 320;
const height = 180;
const canvas = document.createElement("canvas");
canvas.width = width;
canvas.height = height;
document.body.appendChild(canvas);
const webGL2RenderingContext = canvas.getContext("webgl2");
const sceneRenderTarget = new RenderTarget(webGL2RenderingContext, width, height, true);
sceneRenderTarget.bind();
webGL2RenderingContext.clearColor(1.0, 0.9, 0.6, 1.0);
webGL2RenderingContext.clear(webGL2RenderingContext.COLOR_BUFFER_BIT | webGL2RenderingContext.DEPTH_BUFFER_BIT);
const bloomEffect = new BloomEffect(webGL2RenderingContext);
bloomEffect.resize(width, height);
bloomEffect.setThreshold(0.6, 0.9);
bloomEffect.setIterationCount(3);
const sceneColorTexture = sceneRenderTarget.getColorTexture();
bloomEffect.render(sceneColorTexture);
const bloomTexture = bloomEffect.getResultTexture();
const compositeShaderSource = `#version 300 es
precision highp float;
in vec2 fragmentTextureCoordinate;
uniform sampler2D sceneTexture;
uniform sampler2D bloomTexture;
out vec4 outputColor;
void main() {
vec3 sceneColor = texture(sceneTexture, fragmentTextureCoordinate).rgb;
vec3 bloomColor = texture(bloomTexture, fragmentTextureCoordinate).rgb;
outputColor = vec4(sceneColor + bloomColor * 0.8, 1.0);
}
`;
const compositePass = new FullscreenPass(webGL2RenderingContext, compositeShaderSource);
webGL2RenderingContext.bindFramebuffer(webGL2RenderingContext.FRAMEBUFFER, null);
webGL2RenderingContext.viewport(0, 0, width, height);
compositePass.useProgram();
const sceneTextureLocation = compositePass.getUniformLocation("sceneTexture");
const bloomTextureLocation = compositePass.getUniformLocation("bloomTexture");
webGL2RenderingContext.uniform1i(sceneTextureLocation, 0);
webGL2RenderingContext.uniform1i(bloomTextureLocation, 1);
webGL2RenderingContext.activeTexture(webGL2RenderingContext.TEXTURE0);
webGL2RenderingContext.bindTexture(webGL2RenderingContext.TEXTURE_2D, sceneColorTexture);
webGL2RenderingContext.activeTexture(webGL2RenderingContext.TEXTURE1);
webGL2RenderingContext.bindTexture(webGL2RenderingContext.TEXTURE_2D, bloomTexture);
compositePass.draw();
webGL2RenderingContext.activeTexture(webGL2RenderingContext.TEXTURE0);생성.
Constructor.
- webGL2RenderingContextWebGL2RenderingContext
- WebGL2 렌더링 컨텍스트.WebGL2 rendering context.
짝Counterpart: vanilla-engine BloomEffect.new
크기 변경. (씬 해상도 기준, 내부는 하프 해상도)
Resize. (Based on the scene resolution, internally half resolution)
- sceneWidthnumber
- 씬 가로 크기. (픽셀, 내부 판은 그 반이고 최소 1)Scene width. (pixels, the internal targets are half of it and at least 1)
- sceneHeightnumber
- 씬 세로 크기. (픽셀, 내부 판은 그 반이고 최소 1)Scene height. (pixels, the internal targets are half of it and at least 1)
짝Counterpart: vanilla-engine BloomEffect.resize
블룸 렌더링. (호출 후 결과는 getResultTexture())
- 부수 효과: 깊이/블렌드 비활성, TEXTURE0 활성, 프레임버퍼 바인드가 변경된다.
Bloom rendering. (After the call, the result is getResultTexture())
- Side effects: depth/blend disabled, TEXTURE0 active, framebuffer binding changed.
- sceneColorTextureWebGLTexture
- 밝은 영역을 뽑을 씬 컬러 텍스처.Scene color texture to extract bright areas from.
짝Counterpart: vanilla-engine BloomEffect.render
결과 텍스처 반환. (render() 이후)
Returns the result texture. (after render())
반환ReturnsWebGLTexture | null 흐린 결과 텍스처. (핑 판의 컬러 텍스처)Blurred result texture. (the ping target's color texture)
짝Counterpart: vanilla-engine BloomEffect.get_result_texture
추출 임계값 설정. (씬 밝기 특성에 맞게 조정)
Sets the extraction threshold. (Adjust to the scene's brightness characteristics)
- thresholdStartnumber
- 이 밝기부터 뽑기 시작한다. (세 채널 가운데 가장 큰 값, 기본 0.5)Extraction starts at this brightness. (the largest of the three channels, default 0.5)
- thresholdEndnumber
- 이 밝기 이상은 그대로 뽑는다. (사이는 smoothstep, 기본 0.95)Brightness at or above this is extracted fully. (smoothstep in between, default 0.95)
짝Counterpart: vanilla-engine BloomEffect.set_threshold
블러 반복 횟수 설정.
Sets the blur iteration count.
- iterationCountnumber
- 가로, 세로 블러 한 쌍을 되풀이할 횟수. (기본 2, 0 이면 뽑기만)Number of times to repeat a horizontal and vertical blur pair. (default 2, 0 only extracts)
짝Counterpart: vanilla-engine BloomEffect.set_iteration_count
실수 컬러 설정. (true 면 주고받는 판을 RGBA16F 로 다시 지어 1 을 넘는 밝은 값이 잘리지 않는다, 기본 false 는 RGBA8, 같으면 그대로)
Sets float color. (If true, rebuilds the ping-pong buffers as RGBA16F so bright values above 1 are not clipped, default false is RGBA8, unchanged if the same)
- useFloatColorboolean
- 참이면 RGBA16F, 거짓이면 RGBA8.RGBA16F when true, RGBA8 when false.
짝Counterpart: vanilla-engine BloomEffect.set_use_float_color
실수 컬러 사용 여부 반환.
Returns whether float color is used.
반환Returnsboolean 주고받는 판이 RGBA16F 면 참.True when the ping-pong targets are RGBA16F.
짝Counterpart: vanilla-engine BloomEffect.get_use_float_color
블러 반복 횟수 반환.
Returns the blur iteration count.
반환Returnsnumber 블러 반복 횟수.Blur iteration count.
짝Counterpart: vanilla-engine BloomEffect.get_iteration_count
파괴. (GL 리소스 해제)
Destroy. (Releases GL resources)
짝Counterpart: vanilla-engine BloomEffect.destroy
렌더링 컨텍스트 반환.
Returns the rendering context.
반환ReturnsWebGL2RenderingContext 렌더링 컨텍스트.Rendering context.
밝은 영역 추출 패스 반환.
Returns the bright area extraction pass.
반환ReturnsFullscreenPass 밝은 영역 추출 패스.Bright area extraction pass.
짝Counterpart: vanilla-engine BloomEffect.get_bright_pass
블러 패스 반환.
Returns the blur pass.
반환ReturnsFullscreenPass 가우시안 블러 패스.Gaussian blur pass.
짝Counterpart: vanilla-engine BloomEffect.get_blur_pass
핑 렌더 타겟 반환. (최종 결과 보관)
Returns the ping render target. (holds the final result)
반환ReturnsRenderTarget 핑 렌더 타겟. (결과를 담는다)Ping render target. (holds the result)
짝Counterpart: vanilla-engine BloomEffect.get_ping_render_target
퐁 렌더 타겟 반환.
Returns the pong render target.
반환ReturnsRenderTarget 퐁 렌더 타겟. (가로 블러 중간 결과)Pong render target. (intermediate horizontal blur result)
짝Counterpart: vanilla-engine BloomEffect.get_pong_render_target