graphics3d/bloomeffect
블룸 이펙트. (원본 graphics3d/bloomeffect.js)
- 밝은 영역 추출 → 하프 해상도 가우시안 블러 핑퐁. render() 결과 텍스처를 최종 합성 패스에서 가산하는 방식으로 쓴다.
- 셰이더와 패스 순서, 기본값(임계 0.5 ~ 0.95, 반복 2)은 원본과 같다.
- 주고받는 판은 기본 RGBA8 이라 1 을 넘는 밝은 값이 잘린다. set_use_float_color(true) 면 RGBA16F 로 지어 HDR 값을 그대로 흐린다.
- GL 을 쓰는 함수는 gl 을 받고, 생성과 크기 변경은 GL 객체를 못 만들면 오류(Result)를 돌려준다.
Bloom effect. (the original graphics3d/bloomeffect.js)
- Bright area extraction → half resolution Gaussian blur ping-pong. The render() result texture is used by adding it in the final composite pass.
- Shaders, pass order and defaults (threshold 0.5 ~ 0.95, iterations 2) are the same as the original.
- The exchanged buffers are RGBA8 by default, so bright values above 1 are clipped. With set_use_float_color(true) they are built as RGBA16F and HDR values are blurred as they are.
- Functions that use GL take gl, and creation and resizing return an error (Result) if GL objects cannot be made.
BloomEffectstruct
블룸 이펙트.
Bloom effect.
use vanilla::{BloomEffect, RenderTarget};
fn create_bloom(gl: &vanilla::GlContext) -> Result<BloomEffect, String> {
let mut bloom_effect = BloomEffect::new(gl)?;
bloom_effect.set_threshold(0.7, 0.95);
Ok(bloom_effect)
}
fn render_bloom(gl: &vanilla::GlContext, bloom_effect: &mut BloomEffect, scene_render_target: &RenderTarget) -> Result<(), String> {
bloom_effect.resize(gl, scene_render_target.get_width(), scene_render_target.get_height())?;
bloom_effect.render(gl, scene_render_target.get_color_texture(0));
unsafe {
gl.active_texture(glow::TEXTURE1);
gl.bind_texture(glow::TEXTURE_2D, bloom_effect.get_result_texture());
gl.active_texture(glow::TEXTURE0);
}
Ok(())
}생성. (패스 2개 + 2x2 렌더 타겟 2장, resize 로 크기를 맞춘다)
Creates. (2 passes + 2 2x2 render targets, sized with resize)
- gl&GlContext
- GL 컨텍스트. (Graphic::get_gl 로 꺼낸다)GL context. (taken out with Graphic::get_gl)
반환ReturnsResult<BloomEffect, String> 새 블룸 이펙트. (임계 0.5 ~ 0.95, 반복 2, RGBA8 판) 셰이더 컴파일이나 GL 객체 만들기에 실패하면 Err(오류 글).New bloom effect. (threshold 0.5 ~ 0.95, iterations 2, RGBA8 buffers) Err(error text) if shader compilation or GL object creation fails.
짝Counterpart: vanilla.js BloomEffect.constructor
pub fn resize(&mut self, gl: &GlContext, scene_width: i32, scene_height: i32) -> Result<(), String>#크기 변경. (씬 해상도 기준, 내부는 하프 해상도)
Resize. (Based on the scene resolution, internally half resolution)
- gl&GlContext
- GL 컨텍스트.GL context.
- scene_widthi32
- 씬 가로 크기. (픽셀, 판은 그 절반, 최소 1)Scene width. (pixels, the buffers are half of it, at least 1)
- scene_heighti32
- 씬 세로 크기. (픽셀, 판은 그 절반, 최소 1)Scene height. (pixels, the buffers are half of it, at least 1)
반환ReturnsResult<(), String> 판을 맞췄으면 Ok. 다시 짓다 GL 객체를 못 만들면 Err(GL 의 오류 글).Ok if the buffers were fitted. Err(GL error text) if GL objects cannot be made while rebuilding.
짝Counterpart: vanilla.js BloomEffect.resize
블룸 렌더링. (호출 후 결과는 get_result_texture())
- 부수 효과: 깊이/블렌드 비활성, TEXTURE0 활성, 프레임버퍼 바인드가 변경된다.
Renders bloom. (the result is get_result_texture() after the call)
- Side effects: depth/blend disabled, TEXTURE0 active, the framebuffer binding changes.
- gl&GlContext
- GL 컨텍스트.GL context.
- scene_color_textureOption<GlTexture>
- 밝은 영역을 뽑을 씬 컬러 텍스처. (보통 씬 RenderTarget 의 get_color_texture(0))Scene color texture to extract bright areas from. (usually get_color_texture(0) of the scene RenderTarget)
짝Counterpart: vanilla.js BloomEffect.render
결과 텍스처 반환. (render() 이후)
Returns the result texture. (after render())
반환ReturnsOption<GlTexture> 블러를 마친 텍스처. (핑 판의 컬러, 씬의 절반 크기) destroy 뒤면 None.Texture after blurring. (color of the ping buffer, half the scene size) None after destroy.
짝Counterpart: vanilla.js BloomEffect.getResultTexture
추출 임계값 설정. (씬 밝기 특성에 맞게 조정)
Sets the extraction threshold. (Adjust to the scene's brightness characteristics)
- threshold_startf64
- 뽑기 시작 밝기. (세 채널 가운데 가장 큰 값, 이보다 어두우면 뽑지 않는다, 기본 0.5)Brightness where extraction starts. (the largest of the three channels, darker than this is not extracted, default 0.5)
- threshold_endf64
- 다 뽑는 밝기. (이보다 밝으면 그대로, 사이는 smoothstep, 기본 0.95)Brightness of full extraction. (brighter than this is kept as is, smoothstep in between, default 0.95)
짝Counterpart: vanilla.js BloomEffect.setThreshold
블러 반복 횟수 설정.
Sets the blur iteration count.
- iteration_countu32
- 가로와 세로 블러 한 쌍을 되풀이할 횟수. (기본 2, 0 이면 밝은 영역 뽑기만)Number of times to repeat a pair of horizontal and vertical blurs. (default 2, 0 only extracts bright areas)
짝Counterpart: vanilla.js BloomEffect.setIterationCount
pub fn set_use_float_color(&mut self, gl: &GlContext, use_float_color: bool) -> Result<(), String>#실수 컬러 설정. (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)
- gl&GlContext
- GL 컨텍스트.GL context.
- use_float_colorbool
- true 면 RGBA16F, false 면 RGBA8.RGBA16F if true, RGBA8 if false.
반환ReturnsResult<(), String> 바꿨거나 이미 같으면 Ok. 새 판을 못 지으면 Err(GL 의 오류 글, 앞의 판은 그대로 둔다).Ok if changed or already the same. Err(GL error text, the previous buffers are kept) if new buffers cannot be built.
짝Counterpart: vanilla.js BloomEffect.setUseFloatColor
use vanilla::BloomEffect;
fn create_hdr_bloom(gl: &vanilla::GlContext) -> Result<BloomEffect, String> {
let mut bloom_effect = BloomEffect::new(gl)?;
bloom_effect.set_use_float_color(gl, true)?;
bloom_effect.set_threshold(1.0, 1.5);
assert!(bloom_effect.get_use_float_color());
Ok(bloom_effect)
}실수 컬러 사용 여부 반환.
Returns whether float color is used.
반환Returnsbool 판이 RGBA16F 면 true, RGBA8 이면 false.true if the buffers are RGBA16F, false if RGBA8.
짝Counterpart: vanilla.js BloomEffect.getUseFloatColor
블러 반복 횟수 반환.
Returns the blur iteration count.
반환Returnsu32 블러 반복 횟수.Blur iteration count.
짝Counterpart: vanilla.js BloomEffect.getIterationCount
파괴. (GL 리소스 해제)
Destroy. (Releases GL resources)
- gl&GlContext
- 만들 때 쓴 GL 컨텍스트.GL context used at creation.
짝Counterpart: vanilla.js BloomEffect.destroy
밝은 영역 추출 패스 반환.
Returns the bright area extraction pass.
반환Returns&FullscreenPass 밝은 영역 추출 패스. (유니폼 sceneTexture, thresholdRange)Bright area extraction pass. (uniforms sceneTexture, thresholdRange)
짝Counterpart: vanilla.js BloomEffect.getBrightPass
블러 패스 반환.
Returns the blur pass.
반환Returns&FullscreenPass 9 탭 가우시안 블러 패스. (유니폼 sourceTexture, blurDirection)9 tap Gaussian blur pass. (uniforms sourceTexture, blurDirection)
짝Counterpart: vanilla.js BloomEffect.getBlurPass
핑 렌더 타겟 반환. (최종 결과 보관)
Returns the ping render target. (holds the final result)
반환Returns&RenderTarget 핑 렌더 타겟. (밝은 영역과 세로 블러를 받는 판, 결과 텍스처의 주인)Ping render target. (the buffer receiving the bright areas and the vertical blur, owner of the result texture)
짝Counterpart: vanilla.js BloomEffect.getPingRenderTarget
퐁 렌더 타겟 반환.
Returns the pong render target.
반환Returns&RenderTarget 퐁 렌더 타겟. (가로 블러를 받는 판)Pong render target. (the buffer receiving the horizontal blur)
짝Counterpart: vanilla.js BloomEffect.getPongRenderTarget