graphics3d/multilevelbloomeffect
다단 블룸 이펙트. (밝은 몫을 반 크기로 뽑아 반씩 줄여 가며 흐리고, 거꾸로 두 배씩 키우며 위 단에 더한다)
Multi-level bloom effect. (extracts the bright part at half size, blurs it while halving the size, then adds it back to the level above while doubling the size)
MultiLevelBloomEffectextends Object
다단 블룸 이펙트. (밝은 몫을 반 크기로 뽑아 반씩 줄여 가며 흐리고, 거꾸로 두 배씩 키우며 위 단에 더한다)
- 단 하나는 앞 단의 반 크기다. 첫 단(씬의 반 크기)이 결과다. (getResultTexture)
- 뽑기: 원본 네 점의 평균에서 밝기(세 채널 가운데 가장 큰 값)가 문턱을 넘는 몫. 문턱 둘레 무릎 폭만큼은 부드럽게 들어온다. (setThreshold(문턱, 무릎))
- 줄이기는 가운데 넷과 네 귀(대각 한 칸)를 섞는 이중 거르개, 키우기는 천막 꼴 아홉 점이다.
- 판은 useFloatColor 면 RGBA16F 라 1 을 넘는 밝은 값이 그대로 흐려진다. (HDR 씬에 쓴다, RGBA8 이면 1 에서 잘린다)
- 사용: resize(씬 너비, 높이) → render(씬 텍스처) → getResultTexture() 를 합성 패스에서 세기를 곱해 더한다.
- 부수 효과: 깊이 시험과 섞기를 끄고, TEXTURE0 을 활성으로, 프레임버퍼 바인드가 바뀐다. 섞기 함수는 앞의 것으로 돌린다.
Multi-level bloom effect. (extracts the bright part at half size, blurs it while halving the size, then adds it back to the level above while doubling the size)
- Each level is half the size of the previous level. The first level (half the scene size) is the result. (getResultTexture)
- Extraction: from the average of four source samples, the part whose brightness (the largest of the three channels) exceeds the threshold. Within the knee width around the threshold it comes in smoothly. (setThreshold(threshold, knee))
- Downsampling is a dual filter mixing the center four and the four corners (one diagonal step), and upsampling is a nine-tap tent.
- With useFloatColor the targets are RGBA16F, so bright values above 1 are blurred as they are. (for HDR scenes, with RGBA8 they are clipped at 1)
- Usage: resize(scene width, height) → render(scene texture) → getResultTexture() is multiplied by the strength and added in the composite pass.
- Side effects: disables the depth test and blending, makes TEXTURE0 active, and changes the framebuffer binding. The blend function is restored to the previous one.
import { MultiLevelBloomEffect, RenderTarget } from "./build/vanilla.js";
const width = 640;
const height = 360;
const canvas = document.createElement("canvas");
const webGL2RenderingContext = canvas.getContext("webgl2");
const sceneRenderTarget = new RenderTarget(webGL2RenderingContext, width, height, true, { useFloatColor: true });
sceneRenderTarget.bind();
webGL2RenderingContext.clearColor(2.0, 1.5, 0.5, 1.0);
webGL2RenderingContext.clear(webGL2RenderingContext.COLOR_BUFFER_BIT | webGL2RenderingContext.DEPTH_BUFFER_BIT);
const multiLevelBloomEffect = new MultiLevelBloomEffect(webGL2RenderingContext, 5, true);
multiLevelBloomEffect.resize(width, height);
multiLevelBloomEffect.setThreshold(1.0, 0.5);
const sceneColorTexture = sceneRenderTarget.getColorTexture();
multiLevelBloomEffect.render(sceneColorTexture);
const bloomTexture = multiLevelBloomEffect.getResultTexture();
const levelCount = multiLevelBloomEffect.getLevelCount();
console.log(levelCount, bloomTexture !== null);
multiLevelBloomEffect.destroy();
sceneRenderTarget.destroy();생성. (단 수, 실수 판인지)
Constructor. (level count, whether to use float targets)
- webGL2RenderingContextWebGL2RenderingContext
- WebGL2 렌더링 컨텍스트.WebGL2 rendering context.
- levelCountnumber
- 기본 5.Default 5.
- useFloatColorboolean
- 기본 true.Default true.
짝Counterpart: vanilla-engine MultiLevelBloomEffect.new
단마다의 판 다시 짓기. (씬 크기와 단 수로)
Rebuilds the per-level targets. (with the scene size and level count)
단마다의 판 지우기.
Deletes the per-level targets.
크기 변경. (씬 해상도 기준, 같으면 그대로)
Resizes. (based on the scene resolution, unchanged if the same)
- sceneWidthnumber
- 씬 가로 크기. (픽셀, 1 밑은 1, 첫 단은 그 반)Scene width. (pixels, below 1 becomes 1, the first level is half of it)
- sceneHeightnumber
- 씬 세로 크기. (픽셀, 1 밑은 1, 첫 단은 그 반)Scene height. (pixels, below 1 becomes 1, the first level is half of it)
짝Counterpart: vanilla-engine MultiLevelBloomEffect.resize
단 수 설정. (1 이상, 같으면 그대로)
Sets the level count. (1 or more, unchanged if the same)
- levelCountnumber
- 단 수. (소수는 버리고 1 밑은 1)Level count. (fractions are dropped, below 1 becomes 1)
짝Counterpart: vanilla-engine MultiLevelBloomEffect.set_level_count
단 수 반환.
Returns the level count.
반환Returnsnumber 단 수.Level count.
짝Counterpart: vanilla-engine MultiLevelBloomEffect.get_level_count
실수 판 사용 여부 반환.
Returns whether float targets are used.
반환Returnsboolean 단마다의 판이 RGBA16F 면 참.True when the per-level targets are RGBA16F.
짝Counterpart: vanilla-engine MultiLevelBloomEffect.get_use_float_color
뽑는 문턱 설정. (밝기, 무릎은 문턱 둘레의 부드러운 폭, 0 이면 딱 자름)
Sets the extraction threshold. (brightness, knee is the smooth width around the threshold, 0 means a hard cut)
- thresholdnumber
- 뽑는 문턱 밝기. (세 채널 가운데 가장 큰 값, 0 밑은 0, 기본 1)Extraction threshold brightness. (the largest of the three channels, below 0 becomes 0, default 1)
- kneenumber
- 문턱 둘레의 부드러운 폭. (0 밑은 0, 기본 0.25)Soft width around the threshold. (below 0 becomes 0, default 0.25)
짝Counterpart: vanilla-engine MultiLevelBloomEffect.set_threshold
블룸 렌더링. (호출 후 결과는 getResultTexture())
Renders the bloom. (after the call, the result is getResultTexture())
- sceneColorTextureWebGLTexture
- 밝은 몫을 뽑을 씬 컬러 텍스처.Scene color texture to extract the bright part from.
짝Counterpart: vanilla-engine MultiLevelBloomEffect.render
결과 텍스처 반환. (render() 이후, 첫 단)
Returns the result texture. (after render(), the first level)
반환ReturnsWebGLTexture | null 첫 단(씬의 반 크기)의 컬러 텍스처. (단이 없으면 null)Color texture of the first level (half the scene size). (null when there are no levels)
짝Counterpart: vanilla-engine MultiLevelBloomEffect.get_result_texture
파괴. (GL 리소스 해제)
Destroy. (Releases GL resources)
짝Counterpart: vanilla-engine MultiLevelBloomEffect.destroy
렌더링 컨텍스트 반환.
Returns the rendering context.
반환ReturnsWebGL2RenderingContext 렌더링 컨텍스트.Rendering context.