vanilladocs
vanillapunch.com
API / graphics3d/ambientocclusioneffect

graphics3d/ambientocclusioneffect

화면 공간 앰비언트 오클루전. (깊이 + 노멀 버퍼 → 반구 표본 차폐 → 깊이 인식 블러)

Screen-space ambient occlusion. (depth + normal buffer → hemisphere sample occlusion → depth-aware blur)

AmbientOcclusionEffectextends Object

짝Counterpart: vanilla-engine AmbientOcclusionEffect

화면 공간 앰비언트 오클루전. (깊이 + 노멀 버퍼 → 반구 표본 차폐 → 깊이 인식 블러)

  • render() 입력은 본 패스의 깊이 텍스처와 월드 노멀 텍스처(알파 = 커버리지), 카메라의 뷰 회전 / 투영 파라미터. 결과는 getResultTexture() 의 r 채널 가시율(1 = 차폐 없음).

Screen-space ambient occlusion. (depth + normal buffer → hemisphere sample occlusion → depth-aware blur)

  • render() input is the main pass depth texture and world normal texture (alpha = coverage), and the camera view rotation / projection parameters. The result is the visibility (1 = no occlusion) in the r channel of getResultTexture().
예제Example깊이와 노멀 텍스처로 차폐 구하기Compute occlusion from depth and normal textures
import { AmbientOcclusionEffect, RenderTarget, Camera3D, Vector3 } from "./build/vanilla.js";

const width = 640;
const height = 360;
const canvas = document.createElement("canvas");
const webGL2RenderingContext = canvas.getContext("webgl2");
const geometryRenderTarget = new RenderTarget(webGL2RenderingContext, width, height, true, { useDepthTexture: true });
geometryRenderTarget.bind();
webGL2RenderingContext.clearColor(0.0, 1.0, 0.0, 1.0);
webGL2RenderingContext.clear(webGL2RenderingContext.COLOR_BUFFER_BIT | webGL2RenderingContext.DEPTH_BUFFER_BIT);

const camera = new Camera3D();
camera.setPerspective(0.8, 0.1, 100);
camera.setAspectRatio(width / height);
const eyePosition = Vector3.create(0, 2, 6);
const targetPosition = Vector3.create(0, 0, 0);
camera.lookAt(eyePosition, targetPosition);
const viewMatrix = camera.getViewMatrix();
const viewMatrixElements = viewMatrix.getElements();
const fieldOfView = camera.getFieldOfView();
const aspectRatio = camera.getAspectRatio();
const nearDistance = camera.getNearDistance();
const farDistance = camera.getFarDistance();

const ambientOcclusionEffect = new AmbientOcclusionEffect(webGL2RenderingContext);
ambientOcclusionEffect.setScale(0.5);
ambientOcclusionEffect.resize(width, height);
ambientOcclusionEffect.setParameters(0.5, 1.2, 0.01);
const depthTexture = geometryRenderTarget.getDepthTexture();
const normalTexture = geometryRenderTarget.getColorTexture();
ambientOcclusionEffect.render(depthTexture, normalTexture, viewMatrixElements, fieldOfView, aspectRatio, nearDistance, farDistance);
const visibilityTexture = ambientOcclusionEffect.getResultTexture();
console.log(visibilityTexture !== null);
ambientOcclusionEffect.destroy();
geometryRenderTarget.destroy();
생성자constructorconstructor(webGL2RenderingContext)#0.3.0 부터since 0.3.0소스source

생성.

Constructor.

webGL2RenderingContextWebGL2RenderingContext
WebGL2 렌더링 컨텍스트.WebGL2 rendering context.

짝Counterpart: vanilla-engine AmbientOcclusionEffect.new

정적staticstatic buildSampleKernel()#0.4.0 부터since 0.4.0소스source

표본 커널 만들기. (WebGL 무관, 황금각 나선, 높이 고르게, 크기 0.15 ~ 1 제곱 분포)

Builds the sample kernel. (WebGL-independent, golden-angle spiral, even heights, size 0.15 ~ 1 squared distribution)

반환ReturnsFloat32Array 표본마다 x, y, z.x, y, z per sample.

짝Counterpart: vanilla-engine AmbientOcclusionEffect.build_sample_kernel

메서드methodcomputeKernel()#0.3.0 부터since 0.3.0소스source

표본 커널 계산. (반구 안에 고르게, 중심 쪽에 더 촘촘히)

Computes the sample kernel. (evenly within the hemisphere, denser toward the center)

짝Counterpart: vanilla-engine AmbientOcclusionEffect.compute_kernel

메서드methodresize(width, height)#0.3.0 부터since 0.3.0소스source

크기 변경. (본 패스 해상도, 내부는 축소 배율 적용)

Resizes. (main pass resolution, the downscale factor is applied internally)

widthnumber
본 패스 가로 크기. (픽셀, 내부 판은 배율을 곱해 내리고 최소 1)Main pass width. (pixels, the internal targets are multiplied by the scale, floored and at least 1)
heightnumber
본 패스 세로 크기. (픽셀, 내부 판은 배율을 곱해 내리고 최소 1)Main pass height. (pixels, the internal targets are multiplied by the scale, floored and at least 1)

짝Counterpart: vanilla-engine AmbientOcclusionEffect.resize

메서드methodrender(depthTexture, normalTexture, viewMatrixElements, fieldOfViewRadian, aspectRatio, nearDistance, farDistance)#0.3.0 부터since 0.3.0소스source

차폐 렌더링. (차폐 → 가로 블러 → 세로 블러, 결과는 getResultTexture())

  • 부수 효과: 깊이/블렌드 비활성, TEXTURE0 활성, 프레임버퍼 바인드가 변경된다.

Renders the occlusion. (occlusion → horizontal blur → vertical blur, result is getResultTexture())

  • Side effects: depth/blend disabled, TEXTURE0 active, framebuffer binding changed.
depthTextureWebGLTexture
본 패스 깊이 텍스처.Main pass depth texture.
normalTextureWebGLTexture
월드 노멀 텍스처. (알파 = 커버리지)World normal texture. (alpha = coverage)
viewMatrixElementsFloat32Array
뷰 행렬 원소. (열 우선 4x4)View matrix elements. (column-major 4x4)
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 AmbientOcclusionEffect.render

메서드methodgetResultTexture()#0.3.0 부터since 0.3.0소스source

결과 텍스처 반환. (render() 이후, r 가시율)

Returns the result texture. (after render(), r visibility)

반환ReturnsWebGLTexture | null 가시율 텍스처. (r 이 가시율 0 ~ 1 이고 1 이면 차폐 없음, g 는 선형 깊이)Visibility texture. (r is visibility 0 ~ 1 where 1 means no occlusion, g is linear depth)

짝Counterpart: vanilla-engine AmbientOcclusionEffect.get_result_texture

메서드methodsetParameters(radius, intensity, bias)#0.3.0 부터since 0.3.0소스source

파라미터 설정. (표본 반경(월드) / 강도 / 깊이 바이어스)

Sets the parameters. (sample radius (world) / strength / depth bias)

radiusnumber
표본 반경. (뷰 공간 월드 단위, 기본 0.03)Sample radius. (view-space world units, default 0.03)
intensitynumber
차폐 세기 배율. (기본 1)Occlusion intensity multiplier. (default 1)
biasnumber
깊이 비교 바이어스. (월드 단위, 제 면 차폐를 막는다, 기본 0.002)Depth comparison bias. (world units, prevents self-occlusion, default 0.002)

짝Counterpart: vanilla-engine AmbientOcclusionEffect.set_parameters

메서드methodsetScale(scale)#0.3.0 부터since 0.3.0소스source

내부 해상도 배율 설정. (resize 전에 호출)

Sets the internal resolution scale. (call before resize)

scalenumber
내부 해상도 배율. (본 패스 크기에 곱한다, 기본 0.5, 다음 resize 부터 쓴다)Internal resolution scale. (multiplied by the main pass size, default 0.5, takes effect from the next resize)

짝Counterpart: vanilla-engine AmbientOcclusionEffect.set_scale

메서드methoddestroy()#0.3.0 부터since 0.3.0소스source

파괴. (GL 리소스 해제)

Destroy. (Releases GL resources)

짝Counterpart: vanilla-engine AmbientOcclusionEffect.destroy

메서드methodgetWebGL2RenderingContext()#0.3.0 부터since 0.3.0소스source

렌더링 컨텍스트 반환.

Returns the rendering context.

반환ReturnsWebGL2RenderingContext 렌더링 컨텍스트.Rendering context.

메서드methodgetOcclusionPass()#0.3.0 부터since 0.3.0소스source

차폐 패스 반환.

Returns the occlusion pass.

반환ReturnsFullscreenPass 차폐 패스.Occlusion pass.

짝Counterpart: vanilla-engine AmbientOcclusionEffect.get_occlusion_pass

메서드methodgetBlurPass()#0.3.0 부터since 0.3.0소스source

블러 패스 반환.

Returns the blur pass.

반환ReturnsFullscreenPass 깊이 인식 블러 패스.Depth-aware blur pass.

짝Counterpart: vanilla-engine AmbientOcclusionEffect.get_blur_pass

메서드methodgetOcclusionRenderTarget()#0.3.0 부터since 0.3.0소스source

차폐 렌더 타겟 반환.

Returns the occlusion render target.

반환ReturnsRenderTarget 차폐 결과 렌더 타겟. (RGBA16F)Occlusion result render target. (RGBA16F)

짝Counterpart: vanilla-engine AmbientOcclusionEffect.get_occlusion_render_target

메서드methodgetPingRenderTarget()#0.3.0 부터since 0.3.0소스source

핑 렌더 타겟 반환. (가로 블러 결과)

Returns the ping render target. (horizontal blur result)

반환ReturnsRenderTarget 가로 블러 결과 렌더 타겟.Horizontal blur result render target.

짝Counterpart: vanilla-engine AmbientOcclusionEffect.get_ping_render_target

메서드methodgetPongRenderTarget()#0.3.0 부터since 0.3.0소스source

퐁 렌더 타겟 반환. (최종 결과 보관)

Returns the pong render target. (holds the final result)

반환ReturnsRenderTarget 세로 블러 결과 렌더 타겟. (최종 결과)Vertical blur result render target. (final result)

짝Counterpart: vanilla-engine AmbientOcclusionEffect.get_pong_render_target

메서드methodgetRadius()#0.3.0 부터since 0.3.0소스source

표본 반경 반환.

Returns the sample radius.

반환Returnsnumber 표본 반경. (뷰 공간 월드 단위)Sample radius. (view-space world units)

짝Counterpart: vanilla-engine AmbientOcclusionEffect.get_radius

메서드methodgetIntensity()#0.3.0 부터since 0.3.0소스source

강도 반환.

Returns the strength.

반환Returnsnumber 차폐 세기 배율.Occlusion intensity multiplier.

짝Counterpart: vanilla-engine AmbientOcclusionEffect.get_intensity

메서드methodgetBias()#0.3.0 부터since 0.3.0소스source

깊이 바이어스 반환.

Returns the depth bias.

반환Returnsnumber 깊이 비교 바이어스. (월드 단위)Depth comparison bias. (world units)

짝Counterpart: vanilla-engine AmbientOcclusionEffect.get_bias

메서드methodgetScale()#0.3.0 부터since 0.3.0소스source

내부 해상도 배율 반환.

Returns the internal resolution scale.

반환Returnsnumber 내부 해상도 배율.Internal resolution scale.

짝Counterpart: vanilla-engine AmbientOcclusionEffect.get_scale