graphics3d/subsurfacescatteringeffect
화면 공간 서브서피스 스캐터링. (분리형, 확산 조도 버퍼를 깊이 인식 가로/세로 블러)
Screen-space subsurface scattering. (separable, depth-aware horizontal/vertical blur of the diffuse irradiance buffer)
SubsurfaceScatteringEffectextends Object
화면 공간 서브서피스 스캐터링. (분리형, 확산 조도 버퍼를 깊이 인식 가로/세로 블러)
- 피부 확산 프로파일(가우시안 합)로 채널별 커널을 만들고, 산란 폭(월드 단위)을 깊이에 맞춰 화면에 투영한다.
- render() 입력은 알파에 산란 마스크를 담은 조도 텍스처와 같은 패스의 깊이 텍스처. 결과는 getResultTexture().
Screen-space subsurface scattering. (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.
- render() input is the irradiance texture holding the scattering mask in alpha and the depth texture of the same pass. The result is getResultTexture().
import { SubsurfaceScatteringEffect, RenderTarget, Camera3D } from "./build/vanilla.js";
const width = 640;
const height = 360;
const canvas = document.createElement("canvas");
const webGL2RenderingContext = canvas.getContext("webgl2");
const irradianceRenderTarget = new RenderTarget(webGL2RenderingContext, width, height, true, { useFloatColor: true, useDepthTexture: true });
irradianceRenderTarget.bind();
webGL2RenderingContext.clearColor(0.8, 0.5, 0.4, 1.0);
webGL2RenderingContext.clear(webGL2RenderingContext.COLOR_BUFFER_BIT | webGL2RenderingContext.DEPTH_BUFFER_BIT);
const camera = new Camera3D();
camera.setPerspective(0.6, 0.05, 50);
camera.setAspectRatio(width / height);
const fieldOfView = camera.getFieldOfView();
const aspectRatio = camera.getAspectRatio();
const nearDistance = camera.getNearDistance();
const farDistance = camera.getFarDistance();
const subsurfaceScatteringEffect = new SubsurfaceScatteringEffect(webGL2RenderingContext);
subsurfaceScatteringEffect.resize(width, height);
subsurfaceScatteringEffect.setScatterWidth(0.012);
subsurfaceScatteringEffect.setProfile([1.0, 0.37, 0.3], [0.48, 0.41, 0.28]);
const irradianceTexture = irradianceRenderTarget.getColorTexture();
const depthTexture = irradianceRenderTarget.getDepthTexture();
subsurfaceScatteringEffect.render(irradianceTexture, depthTexture, fieldOfView, aspectRatio, nearDistance, farDistance);
const scatteredTexture = subsurfaceScatteringEffect.getResultTexture();
console.log(scatteredTexture !== null);
subsurfaceScatteringEffect.destroy();
irradianceRenderTarget.destroy();생성.
Constructor.
- webGL2RenderingContextWebGL2RenderingContext
- WebGL2 렌더링 컨텍스트.WebGL2 rendering context.
짝Counterpart: vanilla-engine SubsurfaceScatteringEffect.new
커널 만들기. (WebGL 무관, 표본마다 rgb 가중치 + w 오프셋)
Builds the kernel. (WebGL-independent, rgb weight + w offset per sample)
- falloffColornumber[]
- 채널마다의 폴오프. ([r, g, b], 클수록 그 채널이 멀리 퍼진다)Per-channel falloff. ([r, g, b], larger values spread that channel farther)
- strengthColornumber[]
- 채널마다의 산란 강도. ([r, g, b], 0 이면 중앙 표본만, 1 이면 커널 가중치 그대로)Per-channel scattering strength. ([r, g, b], 0 keeps only the center sample, 1 uses the kernel weights as is)
반환ReturnsFloat32Array 표본 17 개마다 rgb 가중치와 w 오프셋을 담은 배열. (길이 68, 0 번이 중앙 표본)Array holding rgb weights and a w offset for each of the 17 samples. (length 68, index 0 is the center sample)
짝Counterpart: vanilla-engine SubsurfaceScatteringEffect.build_kernel
import { SubsurfaceScatteringEffect } from "./build/vanilla.js";
const kernel = SubsurfaceScatteringEffect.buildKernel([1.0, 0.37, 0.3], [0.48, 0.41, 0.28]);
console.log(kernel.length, kernel[0], kernel[1], kernel[2], kernel[3]);커널 계산. (피부 확산 프로파일을 오프셋 구간 넓이로 적분, 중앙 샘플을 0번에)
Computes the kernel. (integrates the skin diffusion profile over the offset interval areas, center sample at index 0)
짝Counterpart: vanilla-engine SubsurfaceScatteringEffect.compute_kernel
크기 변경. (조도 버퍼 해상도 기준, 전체 해상도 실수 타겟 2장)
Resizes. (based on the irradiance buffer resolution, 2 full-resolution float targets)
- widthnumber
- 조도 버퍼 가로 크기. (픽셀)Irradiance buffer width. (pixels)
- heightnumber
- 조도 버퍼 세로 크기. (픽셀)Irradiance buffer height. (pixels)
짝Counterpart: vanilla-engine SubsurfaceScatteringEffect.resize
render(irradianceTexture, depthTexture, fieldOfViewRadian, aspectRatio, nearDistance, farDistance)#산란 렌더링. (가로 → 핑, 세로 → 퐁, 결과는 getResultTexture())
- 부수 효과: 깊이/블렌드 비활성, TEXTURE0 활성, 프레임버퍼 바인드가 변경된다.
Renders the scattering. (horizontal → ping, vertical → pong, result is getResultTexture())
- Side effects: depth/blend disabled, TEXTURE0 active, framebuffer binding changed.
- irradianceTextureWebGLTexture
- 알파에 산란 마스크를 담은 조도 텍스처.Irradiance texture holding the scattering mask in alpha.
- depthTextureWebGLTexture
- 같은 패스의 깊이 텍스처.Depth texture of the same pass.
- fieldOfViewRadiannumber
- 세로 시야각.Vertical field of view.
- aspectRationumber
- 가로 세로 비. (너비 / 높이)Aspect ratio. (width / height)
- nearDistancenumber
- 카메라의 가까운 거리. (깊이를 선형으로 풀 때 쓴다)Camera near distance. (used to linearize depth)
- farDistancenumber
- 카메라의 먼 거리. (깊이를 선형으로 풀 때 쓴다)Camera far distance. (used to linearize depth)
짝Counterpart: vanilla-engine SubsurfaceScatteringEffect.render
결과 텍스처 반환. (render() 이후)
Returns the result texture. (after render())
반환ReturnsWebGLTexture | null 산란 결과 텍스처. (퐁 판, RGBA16F, 알파는 산란 마스크)Scattering result texture. (pong target, RGBA16F, alpha is the scattering mask)
짝Counterpart: vanilla-engine SubsurfaceScatteringEffect.get_result_texture
산란 폭 설정. (월드 단위, 커널 전체 반경)
Sets the scattering width. (world units, full kernel radius)
- scatterWidthnumber
- 산란 폭. (월드 단위, 커널 전체 반경, 기본 0.2)Scatter width. (world units, the whole kernel radius, default 0.2)
짝Counterpart: vanilla-engine SubsurfaceScatteringEffect.set_scatter_width
산란 폭 반환.
Returns the scattering width.
반환Returnsnumber 산란 폭. (월드 단위)Scatter width. (world units)
짝Counterpart: vanilla-engine SubsurfaceScatteringEffect.get_scatter_width
확산 프로파일 설정. (채널별 폴오프 / 강도, 피부 기본 (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))
- falloffColornumber[]
- 채널마다의 폴오프. ([r, g, b], 앞 세 값을 복사한다, 피부 기본 [1, 0.37, 0.3])Per-channel falloff. ([r, g, b], the first three values are copied, skin default [1, 0.37, 0.3])
- strengthColornumber[]
- 채널마다의 산란 강도. ([r, g, b], 앞 세 값을 복사한다, 피부 기본 [0.48, 0.41, 0.28])Per-channel scattering strength. ([r, g, b], the first three values are copied, skin default [0.48, 0.41, 0.28])
짝Counterpart: vanilla-engine SubsurfaceScatteringEffect.set_profile
폴오프 색 반환.
Returns the falloff color.
반환Returnsnumber[] 채널마다의 폴오프. ([r, g, b])Per-channel falloff. ([r, g, b])
짝Counterpart: vanilla-engine SubsurfaceScatteringEffect.get_falloff_color
강도 색 반환.
Returns the strength color.
반환Returnsnumber[] 채널마다의 산란 강도. ([r, g, b])Per-channel scattering strength. ([r, g, b])
짝Counterpart: vanilla-engine SubsurfaceScatteringEffect.get_strength_color
파괴. (GL 리소스 해제)
Destroy. (Releases GL resources)
짝Counterpart: vanilla-engine SubsurfaceScatteringEffect.destroy
렌더링 컨텍스트 반환.
Returns the rendering context.
반환ReturnsWebGL2RenderingContext 렌더링 컨텍스트.Rendering context.
산란 패스 반환.
Returns the scattering pass.
반환ReturnsFullscreenPass 분리형 산란 블러 패스.Separable scattering blur pass.
짝Counterpart: vanilla-engine SubsurfaceScatteringEffect.get_scatter_pass
핑 렌더 타겟 반환. (가로 블러 결과)
Returns the ping render target. (horizontal blur result)
반환ReturnsRenderTarget 가로 블러 결과 렌더 타겟.Horizontal blur result render target.
짝Counterpart: vanilla-engine SubsurfaceScatteringEffect.get_ping_render_target
퐁 렌더 타겟 반환. (최종 결과 보관)
Returns the pong render target. (holds the final result)
반환ReturnsRenderTarget 세로 블러 결과 렌더 타겟. (최종 결과)Vertical blur result render target. (final result)
짝Counterpart: vanilla-engine SubsurfaceScatteringEffect.get_pong_render_target