graphics3d/subsurfacescatteringeffect
화면 공간 서브서피스 스캐터링. (원본 graphics3d/subsurfacescatteringeffect.js)
- 분리형, 확산 조도 버퍼를 깊이 인식 가로/세로 블러. 피부 확산 프로파일(가우시안 합)로 채널별 커널을 만들고, 산란 폭(월드 단위)을 깊이에 맞춰 화면에 투영한다.
- render() 입력은 알파에 산란 마스크를 담은 조도 텍스처와 같은 패스의 깊이 텍스처. 결과는 get_result_texture().
- GLSL, 커널 식, 기본값(산란 폭 0.2, 폴오프 (1, 0.37, 0.3), 강도 (0.48, 0.41, 0.28))은 원본과 같다. 원본 ${KERNEL_SAMPLE_COUNT} / ${KERNEL_RANGE} 는 숫자 17 / 3 으로 옮겼다.
- GL 을 쓰는 함수는 gl 을 받고, 생성과 크기 변경은 GL 객체를 못 만들면 오류(Result)를 돌려준다.
Screen-space subsurface scattering. (the original graphics3d/subsurfacescatteringeffect.js)
- Separable, depth-aware horizontal/vertical blur of the diffuse irradiance buffer. Builds per-channel kernels from the skin diffusion profile (sum of Gaussians), and projects the scattering width (world units) onto the screen according to depth.
- The render() input is an irradiance texture with the scattering mask in alpha and the depth texture of the same pass. The result is get_result_texture().
- The GLSL, kernel formula and defaults (scattering width 0.2, falloff (1, 0.37, 0.3), strength (0.48, 0.41, 0.28)) are the same as the original. The original ${KERNEL_SAMPLE_COUNT} / ${KERNEL_RANGE} became the numbers 17 / 3.
- Functions that use GL take gl, and construction and resizing return an error (Result) if GL objects cannot be created.
SubsurfaceScatteringEffectstruct
화면 공간 서브서피스 스캐터링.
Screen-space subsurface scattering.
use vanilla::{Camera3D, RenderTarget, SubsurfaceScatteringEffect};
fn create_scattering(gl: &vanilla::GlContext) -> Result<SubsurfaceScatteringEffect, String> {
let mut subsurface_scattering_effect = SubsurfaceScatteringEffect::new(gl)?;
subsurface_scattering_effect.set_scatter_width(0.015);
Ok(subsurface_scattering_effect)
}
fn render_scattering(gl: &vanilla::GlContext, subsurface_scattering_effect: &mut SubsurfaceScatteringEffect, scene_render_target: &RenderTarget, camera: &Camera3D) -> Result<(), String> {
subsurface_scattering_effect.resize(gl, scene_render_target.get_width(), scene_render_target.get_height())?;
subsurface_scattering_effect.render(gl, scene_render_target.get_color_texture(0), scene_render_target.get_depth_texture(), camera.get_field_of_view(), camera.get_aspect_ratio(), camera.get_near_distance(), camera.get_far_distance());
let scattered_irradiance_texture = subsurface_scattering_effect.get_result_texture();
assert!(scattered_irradiance_texture.is_some());
Ok(())
}생성. (패스 1개 + 반정밀 실수 타겟 2장, resize 로 크기를 맞춘다)
Constructor. (1 pass + 2 half-float targets, match the size with resize)
- gl&GlContext
- GL 컨텍스트. (Graphic::get_gl 로 꺼낸다)GL context. (taken out with Graphic::get_gl)
반환ReturnsResult<SubsurfaceScatteringEffect, String> 새 이펙트. (산란 폭 0.2, 폴오프 (1, 0.37, 0.3), 강도 (0.48, 0.41, 0.28), 커널까지 셈한 것) 셰이더 컴파일이나 판 만들기에 실패하면 Err(오류 글).New effect. (scattering width 0.2, falloff (1, 0.37, 0.3), strength (0.48, 0.41, 0.28), with the kernel computed) Err(error message) if shader compilation or target creation fails.
짝Counterpart: vanilla.js SubsurfaceScatteringEffect.constructor
pub fn build_kernel(falloff_color: [f64; 3], strength_color: [f64; 3]) -> [f32; KERNEL_SAMPLE_COUNT * 4]#커널 만들기. (GL 무관, 표본마다 rgb 가중치 + w 오프셋)
Builds the kernel. (GL independent, rgb weight + w offset per sample)
- falloff_color[f64; 3]
- 채널별 폴오프. (r, g, b, 클수록 그 채널이 멀리 퍼진다)Per-channel falloff. (r, g, b, larger values spread that channel farther)
- strength_color[f64; 3]
- 채널별 강도. (r, g, b, 0 이면 그 채널은 흩지 않고 중앙만 1)Per-channel strength. (r, g, b, at 0 that channel does not scatter and only the center is 1)
반환Returns[f32; KERNEL_SAMPLE_COUNT * 4] 표본 KERNEL_SAMPLE_COUNT(17) 개의 r 가중, g 가중, b 가중, 오프셋을 차례로 이은 배열. (0 번이 중앙이고 오프셋 0, 채널마다 가중치 합 1, 오프셋은 -3 ~ 3)Array of r weight, g weight, b weight and offset for KERNEL_SAMPLE_COUNT (17) samples in order. (sample 0 is the center with offset 0, the weights sum to 1 per channel, offsets are -3 ~ 3)
짝Counterpart: vanilla.js SubsurfaceScatteringEffect.buildKernel
use vanilla::graphics3d::subsurfacescatteringeffect::KERNEL_SAMPLE_COUNT;
use vanilla::SubsurfaceScatteringEffect;
let kernel = SubsurfaceScatteringEffect::build_kernel([1.0, 0.37, 0.3], [0.48, 0.41, 0.28]);
for channel_index in 0..3 {
let weight_sum: f64 = (0..KERNEL_SAMPLE_COUNT).map(|sample_index| kernel[sample_index * 4 + channel_index] as f64).sum();
assert!((weight_sum - 1.0).abs() < 1.0e-5);
}
assert_eq!(kernel[3], 0.0);
let identity_kernel = SubsurfaceScatteringEffect::build_kernel([1.0, 0.37, 0.3], [0.0, 0.0, 0.0]);
assert_eq!(identity_kernel[0], 1.0);
assert_eq!(identity_kernel[4], 0.0);커널 계산. (피부 확산 프로파일을 오프셋 구간 넓이로 적분, 중앙 샘플을 0번에)
Computes the kernel. (integrates the skin diffusion profile over the offset interval areas, center sample at index 0)
짝Counterpart: vanilla.js SubsurfaceScatteringEffect.computeKernel
크기 변경. (조도 버퍼 해상도 기준, 전체 해상도 실수 타겟 2장)
Resizes. (based on the irradiance buffer resolution, 2 full-resolution float targets)
- gl&GlContext
- GL 컨텍스트.GL context.
- widthi32
- 조도 버퍼 가로 크기. (픽셀, 판도 같은 크기)Irradiance buffer width. (pixels, the targets are the same size)
- heighti32
- 조도 버퍼 세로 크기. (픽셀, 판도 같은 크기)Irradiance buffer height. (pixels, the targets are the same size)
반환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 SubsurfaceScatteringEffect.resize
pub fn render(&self, gl: &GlContext, irradiance_texture: Option<GlTexture>, depth_texture: Option<GlTexture>, field_of_view_radian: f64, aspect_ratio: f64, near_distance: f64, far_distance: f64)#산란 렌더링. (가로 → 핑, 세로 → 퐁, 결과는 get_result_texture())
- 부수 효과: 깊이/블렌드 비활성, TEXTURE0 활성, 프레임버퍼 바인드가 변경된다.
- 깊이 텍스처는 1 번 유닛에 묶었다가 끝에 풀어 둔다. (1 번은 섀도우 샘플러 자리)
Renders the scattering. (horizontal → ping, vertical → pong, the result is get_result_texture())
- Side effects: depth/blend disabled, TEXTURE0 active, framebuffer binding changed.
- The depth texture is bound to unit 1 and unbound at the end. (unit 1 is the shadow sampler slot)
- gl&GlContext
- GL 컨텍스트.GL context.
- irradiance_textureOption<GlTexture>
- 확산 조도 텍스처. (rgb 조도, a 산란 마스크, 마스크가 0.001 밑인 곳은 그대로 둔다)Diffuse irradiance texture. (rgb irradiance, a scattering mask, areas where the mask is below 0.001 are left as is)
- depth_textureOption<GlTexture>
- 같은 패스의 깊이 텍스처. (하드웨어 깊이 0 ~ 1)Depth texture of the same pass. (hardware depth 0 ~ 1)
- field_of_view_radianf64
- 세로 시야각. (라디안, 산란 폭을 화면에 투영할 때)Vertical field of view. (radians, for projecting the scattering width onto the screen)
- aspect_ratiof64
- 가로 세로 비. (너비 / 높이, 가로 걸음을 보정한다)Aspect ratio. (width / height, corrects the horizontal step)
- near_distancef64
- 투영의 가까운 거리. (깊이를 선형으로 풀 때)Near distance of the projection. (for linearizing depth)
- far_distancef64
- 투영의 먼 거리.Far distance of the projection.
짝Counterpart: vanilla.js SubsurfaceScatteringEffect.render
결과 텍스처 반환. (render() 이후)
Returns the result texture. (after render())
반환ReturnsOption<GlTexture> 흩은 조도 텍스처. (퐁 판, a 에 산란 마스크) destroy 뒤면 None.Scattered irradiance texture. (the pong target, scattering mask in a) None after destroy.
짝Counterpart: vanilla.js SubsurfaceScatteringEffect.getResultTexture
산란 폭 설정. (월드 단위, 커널 전체 반경)
Sets the scattering width. (world units, full kernel radius)
- scatter_widthf64
- 산란 폭. (월드 단위, 기본 0.2, 화면에 투영한 폭은 화면 높이의 0.05 를 넘지 않게 셰이더가 자른다)Scattering width. (world units, default 0.2, the shader clamps the projected width to at most 0.05 of the screen height)
짝Counterpart: vanilla.js SubsurfaceScatteringEffect.setScatterWidth
산란 폭 반환.
Returns the scattering width.
반환Returnsf64 산란 폭. (월드 단위)Scatter width. (world units)
짝Counterpart: vanilla.js SubsurfaceScatteringEffect.getScatterWidth
확산 프로파일 설정. (채널별 폴오프 / 강도, 피부 기본 (1, 0.37, 0.3) / (0.48, 0.41, 0.28))
- 커널을 바로 다시 셈한다.
Sets the diffusion profile. (per-channel falloff / strength, skin default (1, 0.37, 0.3) / (0.48, 0.41, 0.28))
- Recomputes the kernel right away.
- falloff_color[f64; 3]
- 채널별 폴오프. (r, g, b, 클수록 그 채널이 멀리 퍼진다)Per-channel falloff. (r, g, b, larger values spread that channel farther)
- strength_color[f64; 3]
- 채널별 강도. (r, g, b, 0 이면 그 채널은 흩지 않는다)Per-channel strength. (r, g, b, at 0 that channel does not scatter)
짝Counterpart: vanilla.js SubsurfaceScatteringEffect.setProfile
폴오프 색 반환.
Returns the falloff color.
반환Returns[f64; 3] 채널별 폴오프. (r, g, b)Per-channel falloff. (r, g, b)
짝Counterpart: vanilla.js SubsurfaceScatteringEffect.getFalloffColor
강도 색 반환.
Returns the strength color.
반환Returns[f64; 3] 채널별 강도. (r, g, b)Per-channel strength. (r, g, b)
짝Counterpart: vanilla.js SubsurfaceScatteringEffect.getStrengthColor
파괴. (GL 리소스 해제)
Destroy. (Releases GL resources)
- gl&GlContext
- 만들 때 쓴 GL 컨텍스트.GL context used at creation.
짝Counterpart: vanilla.js SubsurfaceScatteringEffect.destroy
산란 패스 반환.
Returns the scattering pass.
반환Returns&FullscreenPass 산란 패스. (가로, 세로 둘 다 이 패스)Scattering pass. (used for both horizontal and vertical)
짝Counterpart: vanilla.js SubsurfaceScatteringEffect.getScatterPass
핑 렌더 타겟 반환. (가로 블러 결과)
Returns the ping render target. (horizontal blur result)
반환Returns&RenderTarget 핑 렌더 타겟. (가로 산란 결과)Ping render target. (horizontal scattering result)
짝Counterpart: vanilla.js SubsurfaceScatteringEffect.getPingRenderTarget
퐁 렌더 타겟 반환. (최종 결과 보관)
Returns the pong render target. (holds the final result)
반환Returns&RenderTarget 퐁 렌더 타겟. (세로 산란 결과, 결과 텍스처의 주인)Pong render target. (vertical scattering result, owner of the result texture)
짝Counterpart: vanilla.js SubsurfaceScatteringEffect.getPongRenderTarget
상수Constants
커널 샘플 수. (중앙 1 + 양측, 홀수, 셰이더의 17 과 같아야 한다)
Kernel sample count. (center 1 + both sides, odd, must match the 17 in the shader)
반환Returnsusize
커널 오프셋 범위. (확산 프로파일 단위, 셰이더에서 산란 폭으로 정규화, 셰이더의 3 과 같아야 한다)
Kernel offset range. (in diffusion profile units, normalized by the scattering width in the shader, must match the 3 in the shader)
반환Returnsf64