UNPKG

@babylonjs/core

Version:

Getting started? Play directly with the Babylon.js API using our [playground](https://playground.babylonjs.com/). It also contains a lot of samples to learn how to use it.

312 lines (311 loc) 15.1 kB
import { __decorate } from "../../../../tslib.es6.js"; import { RegisterClass } from "../../../../Misc/typeStore.js"; import { NodeRenderGraphBlockConnectionPointTypes } from "../../Types/nodeRenderGraphTypes.js"; import { editableInPropertyPage } from "../../../../Decorators/nodeDecorator.js"; import { FrameGraphSSAO2RenderingPipelineTask } from "../../../Tasks/PostProcesses/ssao2RenderingPipelineTask.js"; import { NodeRenderGraphBasePostProcessBlock } from "./basePostProcessBlock.js"; /** * Block that implements the SSAO2 post process */ export class NodeRenderGraphSSAO2PostProcessBlock extends NodeRenderGraphBasePostProcessBlock { /** * Gets the frame graph task associated with this block */ get task() { return this._frameGraphTask; } /** * Create a new NodeRenderGraphSSAO2PostProcessBlock * @param name defines the block name * @param frameGraph defines the hosting frame graph * @param scene defines the hosting scene * @param ratioSSAO The ratio between the SSAO texture size and the source texture size (default: 1) * @param ratioBlur The ratio between the SSAO blur texture size and the source texture size (default: 1) * @param textureType The texture type used by the different post processes created by SSAO2 (default: 0) */ constructor(name, frameGraph, scene, ratioSSAO = 1, ratioBlur = 1, textureType = 0) { super(name, frameGraph, scene); this._additionalConstructionParameters = [ratioSSAO, ratioBlur, textureType]; this.registerInput("camera", NodeRenderGraphBlockConnectionPointTypes.Camera); this.registerInput("geomDepth", NodeRenderGraphBlockConnectionPointTypes.TextureViewDepth); this.registerInput("geomNormal", NodeRenderGraphBlockConnectionPointTypes.TextureViewNormal); this._finalizeInputOutputRegistering(); this._frameGraphTask = new FrameGraphSSAO2RenderingPipelineTask(this.name, frameGraph, ratioSSAO, ratioBlur, textureType); } _createTask(ratioSSAO, ratioBlur, textureType) { const sourceSamplingMode = this.sourceSamplingMode; const samples = this.samples; const totalStrength = this.totalStrength; const base = this.base; const maxZ = this.maxZ; const minZAspect = this.minZAspect; const radius = this.radius; const epsilon = this.epsilon; const useViewportInCombineStage = this.useViewportInCombineStage; const bypassBlur = this.bypassBlur; const expensiveBlur = this.expensiveBlur; const bilateralSoften = this.bilateralSoften; const bilateralSamples = this.bilateralSamples; const bilateralTolerance = this.bilateralTolerance; this._frameGraphTask.dispose(); this._frameGraphTask = new FrameGraphSSAO2RenderingPipelineTask(this.name, this._frameGraph, ratioSSAO, ratioBlur, textureType); this.sourceSamplingMode = sourceSamplingMode; this.samples = samples; this.totalStrength = totalStrength; this.base = base; this.maxZ = maxZ; this.minZAspect = minZAspect; this.radius = radius; this.epsilon = epsilon; this.useViewportInCombineStage = useViewportInCombineStage; this.bypassBlur = bypassBlur; this.expensiveBlur = expensiveBlur; this.bilateralSoften = bilateralSoften; this.bilateralSamples = bilateralSamples; this.bilateralTolerance = bilateralTolerance; this._additionalConstructionParameters = [ratioSSAO, ratioBlur, textureType]; } /** The texture type used by the different post processes created by SSAO2 */ get textureType() { return this._frameGraphTask.textureType; } set textureType(value) { this._createTask(this._frameGraphTask.ratioSSAO, this._frameGraphTask.ratioBlur, value); } /** The ratio between the SSAO texture size and the source texture size */ get ratioSSAO() { return this._frameGraphTask.ratioSSAO; } set ratioSSAO(value) { this._createTask(value, this._frameGraphTask.ratioBlur, this._frameGraphTask.textureType); } /** The ratio between the SSAO blur texture size and the source texture size */ get ratioBlur() { return this._frameGraphTask.ratioBlur; } set ratioBlur(value) { this._createTask(this._frameGraphTask.ratioSSAO, value, this._frameGraphTask.textureType); } /** Number of samples used for the SSAO calculations. Default value is 8. */ get samples() { return this._frameGraphTask.ssao.samples; } set samples(value) { this._frameGraphTask.ssao.samples = value; } /** The strength of the SSAO post-process. Default value is 1.0. */ get totalStrength() { return this._frameGraphTask.ssao.totalStrength; } set totalStrength(value) { this._frameGraphTask.ssao.totalStrength = value; } /** The base color of the SSAO post-process. The final result is "base + ssao" between [0, 1] */ get base() { return this._frameGraphTask.ssao.base; } set base(value) { this._frameGraphTask.ssao.base = value; } /** Maximum depth value to still render AO. A smooth falloff makes the dimming more natural, so there will be no abrupt shading change. */ get maxZ() { return this._frameGraphTask.ssao.maxZ; } set maxZ(value) { this._frameGraphTask.ssao.maxZ = value; } /** In order to save performances, SSAO radius is clamped on close geometry. This ratio changes by how much. */ get minZAspect() { return this._frameGraphTask.ssao.minZAspect; } set minZAspect(value) { this._frameGraphTask.ssao.minZAspect = value; } /** The radius around the analyzed pixel used by the SSAO post-process. */ get radius() { return this._frameGraphTask.ssao.radius; } set radius(value) { this._frameGraphTask.ssao.radius = value; } /** Used in SSAO calculations to compensate for accuracy issues with depth values. */ get epsilon() { return this._frameGraphTask.ssao.epsilon; } set epsilon(value) { this._frameGraphTask.ssao.epsilon = value; } /** Indicates that the combine stage should use the current camera viewport to render the SSAO result on only a portion of the output texture. */ get useViewportInCombineStage() { return this._frameGraphTask.ssao.useViewportInCombineStage; } set useViewportInCombineStage(value) { this._frameGraphTask.ssao.useViewportInCombineStage = value; } /** Skips the denoising (blur) stage of the SSAO calculations. */ get bypassBlur() { return this._frameGraphTask.ssao.bypassBlur; } set bypassBlur(value) { this._frameGraphTask.ssao.bypassBlur = value; } /** Enables the configurable bilateral denoising (blurring) filter. */ get expensiveBlur() { return this._frameGraphTask.ssao.expensiveBlur; } set expensiveBlur(value) { this._frameGraphTask.ssao.expensiveBlur = value; } /** The number of samples the bilateral filter uses in both dimensions when denoising the SSAO calculations. */ get bilateralSamples() { return this._frameGraphTask.ssao.bilateralSamples; } set bilateralSamples(value) { this._frameGraphTask.ssao.bilateralSamples = value; } /** Controls the shape of the denoising kernel used by the bilateral filter. */ get bilateralSoften() { return this._frameGraphTask.ssao.bilateralSoften; } set bilateralSoften(value) { this._frameGraphTask.ssao.bilateralSoften = value; } /** How forgiving the bilateral denoiser should be when rejecting samples. */ get bilateralTolerance() { return this._frameGraphTask.ssao.bilateralTolerance; } set bilateralTolerance(value) { this._frameGraphTask.ssao.bilateralTolerance = value; } /** * Gets the current class name * @returns the class name */ getClassName() { return "NodeRenderGraphSSAO2PostProcessBlock"; } /** * Gets the camera input component */ get camera() { return this._inputs[2]; } /** * Gets the geometry depth input component */ get geomDepth() { return this._inputs[3]; } /** * Gets the geometry normal input component */ get geomNormal() { return this._inputs[4]; } _buildBlock(state) { super._buildBlock(state); this._frameGraphTask.normalTexture = this.geomNormal.connectedPoint?.value; this._frameGraphTask.depthTexture = this.geomDepth.connectedPoint?.value; this._frameGraphTask.camera = this.camera.connectedPoint?.value; } _dumpPropertiesCode() { const codes = []; codes.push(`${this._codeVariableName}.samples = ${this.samples};`); codes.push(`${this._codeVariableName}.totalStrength = ${this.totalStrength};`); codes.push(`${this._codeVariableName}.base = ${this.base};`); codes.push(`${this._codeVariableName}.maxZ = ${this.maxZ};`); codes.push(`${this._codeVariableName}.minZAspect = ${this.minZAspect};`); codes.push(`${this._codeVariableName}.radius = ${this.radius};`); codes.push(`${this._codeVariableName}.epsilon = ${this.epsilon};`); codes.push(`${this._codeVariableName}.useViewportInCombineStage = ${this.useViewportInCombineStage};`); codes.push(`${this._codeVariableName}.bypassBlur = ${this.bypassBlur};`); codes.push(`${this._codeVariableName}.expensiveBlur = ${this.expensiveBlur};`); codes.push(`${this._codeVariableName}.bilateralSamples = ${this.bilateralSamples};`); codes.push(`${this._codeVariableName}.bilateralSoften = ${this.bilateralSoften};`); codes.push(`${this._codeVariableName}.bilateralTolerance = ${this.bilateralTolerance};`); return super._dumpPropertiesCode() + codes.join("\n"); } serialize() { const serializationObject = super.serialize(); serializationObject.samples = this.samples; serializationObject.totalStrength = this.totalStrength; serializationObject.base = this.base; serializationObject.maxZ = this.maxZ; serializationObject.minZAspect = this.minZAspect; serializationObject.radius = this.radius; serializationObject.epsilon = this.epsilon; serializationObject.useViewportInCombineStage = this.useViewportInCombineStage; serializationObject.bypassBlur = this.bypassBlur; serializationObject.expensiveBlur = this.expensiveBlur; serializationObject.bilateralSoften = this.bilateralSoften; serializationObject.bilateralSamples = this.bilateralSamples; serializationObject.bilateralTolerance = this.bilateralTolerance; return serializationObject; } _deserialize(serializationObject) { super._deserialize(serializationObject); this.samples = serializationObject.samples; this.totalStrength = serializationObject.totalStrength; this.base = serializationObject.base; this.maxZ = serializationObject.maxZ; this.minZAspect = serializationObject.minZAspect; this.radius = serializationObject.radius; this.epsilon = serializationObject.epsilon; this.useViewportInCombineStage = serializationObject.useViewportInCombineStage; this.bypassBlur = serializationObject.bypassBlur; this.expensiveBlur = serializationObject.expensiveBlur; this.bilateralSoften = serializationObject.bilateralSoften; this.bilateralSamples = serializationObject.bilateralSamples; this.bilateralTolerance = serializationObject.bilateralTolerance; } } __decorate([ editableInPropertyPage("Texture type", 10 /* PropertyTypeForEdition.TextureType */, "TEXTURE") ], NodeRenderGraphSSAO2PostProcessBlock.prototype, "textureType", null); __decorate([ editableInPropertyPage("SSAO texture ratio", 1 /* PropertyTypeForEdition.Float */, "TEXTURE", { min: 0.1, max: 1 }) ], NodeRenderGraphSSAO2PostProcessBlock.prototype, "ratioSSAO", null); __decorate([ editableInPropertyPage("SSAO blur texture ratio", 1 /* PropertyTypeForEdition.Float */, "TEXTURE", { min: 0.1, max: 1 }) ], NodeRenderGraphSSAO2PostProcessBlock.prototype, "ratioBlur", null); __decorate([ editableInPropertyPage("Samples", 2 /* PropertyTypeForEdition.Int */, "SSAO", { min: 1, max: 128 }) ], NodeRenderGraphSSAO2PostProcessBlock.prototype, "samples", null); __decorate([ editableInPropertyPage("Strength", 1 /* PropertyTypeForEdition.Float */, "SSAO", { min: 0, max: 3 }) ], NodeRenderGraphSSAO2PostProcessBlock.prototype, "totalStrength", null); __decorate([ editableInPropertyPage("Base", 1 /* PropertyTypeForEdition.Float */, "SSAO", { min: 0, max: 1 }) ], NodeRenderGraphSSAO2PostProcessBlock.prototype, "base", null); __decorate([ editableInPropertyPage("Max Z", 1 /* PropertyTypeForEdition.Float */, "SSAO", { min: 0, max: 10000 }) ], NodeRenderGraphSSAO2PostProcessBlock.prototype, "maxZ", null); __decorate([ editableInPropertyPage("Min Z aspect", 1 /* PropertyTypeForEdition.Float */, "SSAO", { min: 0, max: 0.5 }) ], NodeRenderGraphSSAO2PostProcessBlock.prototype, "minZAspect", null); __decorate([ editableInPropertyPage("Radius", 1 /* PropertyTypeForEdition.Float */, "SSAO", { min: 0, max: 10 }) ], NodeRenderGraphSSAO2PostProcessBlock.prototype, "radius", null); __decorate([ editableInPropertyPage("Epsilon", 1 /* PropertyTypeForEdition.Float */, "SSAO", { min: 0, max: 1 }) ], NodeRenderGraphSSAO2PostProcessBlock.prototype, "epsilon", null); __decorate([ editableInPropertyPage("Use viewport in combine stage", 0 /* PropertyTypeForEdition.Boolean */, "SSAO") ], NodeRenderGraphSSAO2PostProcessBlock.prototype, "useViewportInCombineStage", null); __decorate([ editableInPropertyPage("Bypass blur", 0 /* PropertyTypeForEdition.Boolean */, "Blur") ], NodeRenderGraphSSAO2PostProcessBlock.prototype, "bypassBlur", null); __decorate([ editableInPropertyPage("Expensive blur", 0 /* PropertyTypeForEdition.Boolean */, "Blur") ], NodeRenderGraphSSAO2PostProcessBlock.prototype, "expensiveBlur", null); __decorate([ editableInPropertyPage("Samples", 2 /* PropertyTypeForEdition.Int */, "Blur", { min: 1, max: 128 }) ], NodeRenderGraphSSAO2PostProcessBlock.prototype, "bilateralSamples", null); __decorate([ editableInPropertyPage("Soften", 1 /* PropertyTypeForEdition.Float */, "Blur", { min: 0, max: 1 }) ], NodeRenderGraphSSAO2PostProcessBlock.prototype, "bilateralSoften", null); __decorate([ editableInPropertyPage("Tolerance", 1 /* PropertyTypeForEdition.Float */, "Blur", { min: 0, max: 1 }) ], NodeRenderGraphSSAO2PostProcessBlock.prototype, "bilateralTolerance", null); RegisterClass("BABYLON.NodeRenderGraphSSAO2PostProcessBlock", NodeRenderGraphSSAO2PostProcessBlock); //# sourceMappingURL=ssao2PostProcessBlock.js.map