UNPKG

@needle-tools/engine

Version:

Needle Engine is a web-based runtime for 3D apps. It runs on your machine for development with great integrations into editors like Unity or Blender - and can be deployed onto any device! It is flexible, extensible and networking and XR are built-in.

92 lines 4.27 kB
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; return c > 3 && r && Object.defineProperty(target, key, r), r; }; import { Color, PerspectiveCamera } from "three"; import { MODULES } from "../../../engine/engine_modules.js"; import { serializable } from "../../../engine/engine_serialization.js"; import { PostProcessingEffect } from "../PostProcessingEffect.js"; import { VolumeParameter } from "../VolumeParameter.js"; import { registerCustomEffectType } from "../VolumeProfile.js"; /** Screenspace Ambient Occlusion post-processing effect. * We recommend using ScreenSpaceAmbientOcclusionN8 instead. * @category Effects * @group Components */ export class ScreenSpaceAmbientOcclusion extends PostProcessingEffect { get typeName() { return "ScreenSpaceAmbientOcclusion"; } intensity = new VolumeParameter(2); falloff = new VolumeParameter(1); samples = new VolumeParameter(9); color = new VolumeParameter(new Color(0, 0, 0)); luminanceInfluence = new VolumeParameter(.7); onBeforeRender() { if (this._ssao && this.context.mainCamera instanceof PerspectiveCamera) { const fadeDistance = this.context.mainCamera.far - this.context.mainCamera.near; this._ssao.ssaoMaterial.worldDistanceFalloff = fadeDistance * .01; this._ssao.ssaoMaterial.worldDistanceThreshold = this.context.mainCamera.far; } } _ssao; onCreateEffect() { const cam = this.context.mainCamera; const normalPass = new MODULES.POSTPROCESSING.MODULE.NormalPass(this.context.scene, cam); const depthDownsamplingPass = new MODULES.POSTPROCESSING.MODULE.DepthDownsamplingPass({ normalBuffer: normalPass.texture, resolutionScale: .5 }); const ssao = this._ssao = new MODULES.POSTPROCESSING.MODULE.SSAOEffect(cam, normalPass.texture, { normalDepthBuffer: depthDownsamplingPass.texture, worldDistanceThreshold: 1, worldDistanceFalloff: 1, worldProximityThreshold: .1, worldProximityFalloff: 2, intensity: 1, blendFunction: MODULES.POSTPROCESSING.MODULE.BlendFunction.MULTIPLY, luminanceInfluence: .5, }); this.intensity.onValueChanged = newValue => { ssao.intensity = newValue; }; this.falloff.onValueChanged = newValue => { ssao.ssaoMaterial.radius = newValue * .1; }; this.samples.onValueChanged = newValue => { ssao.ssaoMaterial.samples = newValue; }; this.color.onValueChanged = newValue => { if (!ssao.color) ssao.color = new Color(); ssao.color.copy(newValue); }; this.luminanceInfluence.onValueChanged = newValue => { ssao.luminanceInfluence = newValue; }; const arr = new Array(); arr.push(normalPass); arr.push(depthDownsamplingPass); arr.push(ssao); return arr; } } __decorate([ serializable(VolumeParameter) ], ScreenSpaceAmbientOcclusion.prototype, "intensity", void 0); __decorate([ serializable(VolumeParameter) ], ScreenSpaceAmbientOcclusion.prototype, "falloff", void 0); __decorate([ serializable(VolumeParameter) ], ScreenSpaceAmbientOcclusion.prototype, "samples", void 0); __decorate([ serializable(VolumeParameter) ], ScreenSpaceAmbientOcclusion.prototype, "color", void 0); __decorate([ serializable(VolumeParameter) ], ScreenSpaceAmbientOcclusion.prototype, "luminanceInfluence", void 0); registerCustomEffectType("ScreenSpaceAmbientOcclusion", ScreenSpaceAmbientOcclusion); //# sourceMappingURL=ScreenspaceAmbientOcclusion.js.map