vanilladocs
vanillapunch.com
API / graphics3d/multilevelbloomeffect

graphics3d/multilevelbloomeffect

다단 블룸 이펙트. (원본 graphics3d/multilevelbloomeffect.js)

  • 밝은 몫을 반 크기로 뽑아 반씩 줄여 가며 흐리고, 거꾸로 두 배씩 키우며 위 단에 더한다. 첫 단(씬의 반 크기)이 결과다. (get_result_texture)
  • 뽑기: 원본 네 점의 평균에서 밝기(세 채널 가운데 가장 큰 값)가 문턱을 넘는 몫. 문턱 둘레 무릎 폭만큼은 부드럽게 들어온다. (set_threshold(문턱, 무릎))
  • 줄이기는 가운데 넷과 네 귀(대각 한 칸)를 섞는 이중 거르개, 키우기는 천막 꼴 아홉 점이다. 셰이더는 원본과 글자까지 같다.
  • 판은 use_float_color 면 RGBA16F 라 1 을 넘는 밝은 값이 그대로 흐려진다. (HDR 씬에 쓴다, RGBA8 이면 1 에서 잘린다)
  • 사용: resize(gl, 씬 너비, 높이) → render(gl, 씬 텍스처) → get_result_texture() 를 합성 패스에서 세기를 곱해 더한다.
  • 부수 효과: 깊이 시험과 섞기를 끄고, TEXTURE0 을 활성으로, 프레임버퍼 바인드가 바뀐다. 섞기 함수는 앞의 것으로 돌린다.

Multi-level bloom effect. (the original graphics3d/multilevelbloomeffect.js)

  • 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. The first level (half the scene size) is the result. (get_result_texture)
  • 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. (set_threshold(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. The shaders match the original character for character.
  • With use_float_color 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(gl, scene width, height) → render(gl, scene texture) → get_result_texture() 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.

MultiLevelBloomEffectstruct

짝Counterpart: vanilla.js MultiLevelBloomEffect소스source

다단 블룸 이펙트.

Multi-level bloom effect.

예제Example머리말의 쓰임: resize, render, get_result_texture 를 합성 패스에 묶기Usage from the header comment: wire resize, render and get_result_texture into a composite pass
use vanilla::{MultiLevelBloomEffect, RenderTarget};

fn create_bloom(gl: &vanilla::GlContext) -> Result<MultiLevelBloomEffect, String> {
	let mut multi_level_bloom_effect = MultiLevelBloomEffect::new(gl, 5, true)?;
	multi_level_bloom_effect.set_threshold(1.0, 0.25);
	Ok(multi_level_bloom_effect)
}

fn render_bloom(gl: &vanilla::GlContext, multi_level_bloom_effect: &mut MultiLevelBloomEffect, scene_render_target: &RenderTarget) -> Result<(), String> {
	multi_level_bloom_effect.resize(gl, scene_render_target.get_width(), scene_render_target.get_height())?;
	multi_level_bloom_effect.render(gl, scene_render_target.get_color_texture(0));
	unsafe {
		gl.active_texture(glow::TEXTURE1);
		gl.bind_texture(glow::TEXTURE_2D, multi_level_bloom_effect.get_result_texture());
		gl.active_texture(glow::TEXTURE0);
	}
	Ok(())
}
생성자constructorpub fn new(gl: &GlContext, level_count: usize, use_float_color: bool) -> Result<MultiLevelBloomEffect, String>#0.4.0 부터since 0.4.0소스source

생성. (단 수, 실수 판인지, 원본 기본값은 5 와 true)

  • 판은 씬 크기 2 x 2 로 지어 두므로 그리기 전에 resize 로 씬 크기를 준다.

Constructor. (level count, whether to use float targets, the original defaults are 5 and true)

  • The targets are built at a scene size of 2 x 2, so give the scene size with resize before drawing.
gl&GlContext
GL 컨텍스트. (Graphic::get_gl 로 꺼낸다)GL context. (taken out with Graphic::get_gl)
level_countusize
단 수. (0 이면 1, 단마다 반 크기)Level count. (1 if 0, each level is half size)
use_float_colorbool
판을 RGBA16F 로 지을지. (false 면 RGBA8 이라 1 에서 잘린다)Whether to build the targets as RGBA16F. (RGBA8 when false, so clipped at 1)

반환ReturnsResult<MultiLevelBloomEffect, String> 새 다단 블룸. (문턱 1, 무릎 0.25) 셰이더 컴파일이나 판 만들기에 실패하면 Err(오류 글).New multi-level bloom. (threshold 1, knee 0.25) Err(error message) if shader compilation or target creation fails.

짝Counterpart: vanilla.js MultiLevelBloomEffect.constructor

메서드methodpub fn resize(&mut self, gl: &GlContext, scene_width: i32, scene_height: i32) -> Result<(), String>#0.4.0 부터since 0.4.0소스source

크기 변경. (씬 해상도 기준, 같으면 그대로)

Resizes. (based on the scene resolution, unchanged if the same)

gl&GlContext
GL 컨텍스트.GL context.
scene_widthi32
씬 가로 크기. (픽셀, 1 밑이면 1, 첫 단은 그 절반)Scene width. (pixels, 1 if below 1, the first level is half of it)
scene_heighti32
씬 세로 크기. (픽셀, 1 밑이면 1, 첫 단은 그 절반)Scene height. (pixels, 1 if below 1, the first level is half of it)

반환ReturnsResult<(), String> 판을 맞췄으면 Ok. 다시 짓다 판을 못 만들면 Err(GL 의 오류 글).Ok if the targets were fitted. Err(GL error message) if a target cannot be made while rebuilding.

짝Counterpart: vanilla.js MultiLevelBloomEffect.resize

메서드methodpub fn set_level_count(&mut self, gl: &GlContext, level_count: usize) -> Result<(), String>#0.4.0 부터since 0.4.0소스source

단 수 설정. (1 이상, 같으면 그대로)

Sets the level count. (1 or more, unchanged if the same)

gl&GlContext
GL 컨텍스트.GL context.
level_countusize
단 수. (0 이면 1)Level count. (1 if 0)

반환ReturnsResult<(), String> 판을 맞췄으면 Ok. 다시 짓다 판을 못 만들면 Err(GL 의 오류 글).Ok if the targets were fitted. Err(GL error message) if a target cannot be made while rebuilding.

짝Counterpart: vanilla.js MultiLevelBloomEffect.setLevelCount

메서드methodpub fn get_level_count(&self) -> usize#0.4.0 부터since 0.4.0소스source

단 수 반환.

Returns the level count.

반환Returnsusize 단 수. (1 이상)Level count. (1 or more)

짝Counterpart: vanilla.js MultiLevelBloomEffect.getLevelCount

메서드methodpub fn get_use_float_color(&self) -> bool#0.4.0 부터since 0.4.0소스source

실수 판 사용 여부 반환.

Returns whether float targets are used.

반환Returnsbool 판이 RGBA16F 면 true, RGBA8 이면 false.true if the buffers are RGBA16F, false if RGBA8.

짝Counterpart: vanilla.js MultiLevelBloomEffect.getUseFloatColor

메서드methodpub fn set_threshold(&mut self, threshold: f64, knee: f64)#0.4.0 부터since 0.4.0소스source

뽑는 문턱 설정. (밝기, 무릎은 문턱 둘레의 부드러운 폭, 0 이면 딱 자름)

Sets the extraction threshold. (brightness, knee is the smooth width around the threshold, 0 means a hard cut)

thresholdf64
뽑는 문턱. (세 채널 가운데 가장 큰 값으로 잰 밝기, 0 밑은 0, 기본 1)Extraction threshold. (brightness measured as the largest of the three channels, 0 if below 0, default 1)
kneef64
문턱 둘레의 부드러운 폭. (0 밑은 0, 기본 0.25)Soft width around the threshold. (below 0 becomes 0, default 0.25)

짝Counterpart: vanilla.js MultiLevelBloomEffect.setThreshold

메서드methodpub fn render(&self, gl: &GlContext, scene_color_texture: Option<GlTexture>)#0.4.0 부터since 0.4.0소스source

블룸 렌더링. (호출 후 결과는 get_result_texture())

  • 판이 없으면(destroy 뒤) 아무것도 하지 않는다.

Renders the bloom. (after the call, the result is get_result_texture())

  • Does nothing if there are no targets (after destroy).
gl&GlContext
GL 컨텍스트.GL context.
scene_color_textureOption<GlTexture>
씬 컬러 텍스처. (크기는 resize 로 준 씬 크기와 같아야 뽑기의 텍셀 간격이 맞는다)Scene color texture. (its size must match the scene size given to resize so the extraction texel spacing is right)

짝Counterpart: vanilla.js MultiLevelBloomEffect.render

메서드methodpub fn get_result_texture(&self) -> Option<GlTexture>#0.4.0 부터since 0.4.0소스source

결과 텍스처 반환. (render() 이후, 첫 단)

Returns the result texture. (after render(), the first level)

반환ReturnsOption<GlTexture> 첫 단(씬의 반 크기)의 컬러 텍스처. destroy 뒤면 None.Color texture of the first level (half the scene size). None after destroy.

짝Counterpart: vanilla.js MultiLevelBloomEffect.getResultTexture

메서드methodpub fn destroy(&mut self, gl: &GlContext)#0.4.0 부터since 0.4.0소스source

파괴. (GL 리소스 해제)

Destroy. (Releases GL resources)

gl&GlContext
만들 때 쓴 GL 컨텍스트.GL context used at creation.

짝Counterpart: vanilla.js MultiLevelBloomEffect.destroy