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.

179 lines 7.93 kB
import { __decorate } from "../../../../tslib.es6.js"; import { RegisterClass } from "../../../../Misc/typeStore.js"; import { editableInPropertyPage } from "../../../../Decorators/nodeDecorator.js"; import { NodeRenderGraphBlock } from "../../nodeRenderGraphBlock.js"; import { FrameGraphVolumetricLightingTask } from "../../../Tasks/PostProcesses/volumetricLightingTask.js"; import { NodeRenderGraphBlockConnectionPointTypes } from "../../Types/nodeRenderGraphTypes.js"; import { Vector3 } from "../../../../Maths/math.vector.js"; import { Color3 } from "../../../../Maths/math.color.js"; /** * Block that implements the volumetric lighting post process */ export class NodeRenderGraphVolumetricLightingBlock extends NodeRenderGraphBlock { /** * Gets the frame graph task associated with this block */ get task() { return this._frameGraphTask; } /** * Create a new NodeRenderGraphVolumetricLightingBlock * @param name defines the block name * @param frameGraph defines the hosting frame graph * @param scene defines the hosting scene * @param enableExtinction defines whether to enable extinction coefficients */ constructor(name, frameGraph, scene, enableExtinction = false) { super(name, frameGraph, scene); this._additionalConstructionParameters = [enableExtinction]; this.registerInput("target", NodeRenderGraphBlockConnectionPointTypes.AutoDetect); this.registerInput("depth", NodeRenderGraphBlockConnectionPointTypes.AutoDetect); this.registerInput("camera", NodeRenderGraphBlockConnectionPointTypes.Camera); this.registerInput("lightingVolumeMesh", NodeRenderGraphBlockConnectionPointTypes.ObjectList); this.registerInput("light", NodeRenderGraphBlockConnectionPointTypes.ShadowLight); this.registerInput("lightingVolumeTexture", NodeRenderGraphBlockConnectionPointTypes.AutoDetect, true); this.target.addExcludedConnectionPointFromAllowedTypes(NodeRenderGraphBlockConnectionPointTypes.TextureAllButBackBuffer); this.lightingVolumeTexture.addExcludedConnectionPointFromAllowedTypes(NodeRenderGraphBlockConnectionPointTypes.TextureAllButBackBuffer); this.depth.addExcludedConnectionPointFromAllowedTypes(NodeRenderGraphBlockConnectionPointTypes.TextureDepthStencilAttachment | NodeRenderGraphBlockConnectionPointTypes.TextureScreenDepth); this._addDependenciesInput(); this.registerOutput("output", NodeRenderGraphBlockConnectionPointTypes.BasedOnInput); this.output._typeConnectionSource = () => { return this.target; }; this._frameGraphTask = new FrameGraphVolumetricLightingTask(name, frameGraph, enableExtinction); } _createTask(enableExtinction) { const sourceSamplingMode = this._frameGraphTask.sourceSamplingMode; const phaseG = this._frameGraphTask.phaseG; const extinction = this._frameGraphTask.extinction; const lightPower = this._frameGraphTask.lightPower; this._frameGraphTask.dispose(); this._frameGraphTask = new FrameGraphVolumetricLightingTask(this.name, this._frameGraph, enableExtinction); this._frameGraphTask.sourceSamplingMode = sourceSamplingMode; this._frameGraphTask.phaseG = phaseG; this._frameGraphTask.extinction = extinction; this._frameGraphTask.lightPower = lightPower; this._additionalConstructionParameters = [enableExtinction]; } /** Gets or sets the phaseG parameter */ get phaseG() { return this._frameGraphTask.phaseG; } set phaseG(value) { this._frameGraphTask.phaseG = value; } /** If extinction coefficients should be used */ get enableExtinction() { return this._frameGraphTask.enableExtinction; } set enableExtinction(value) { this._createTask(value); } /** Gets or sets the extinction color */ get extinction() { return this._frameGraphTask.extinction; } set extinction(value) { this._frameGraphTask.extinction = value; } /** Gets or sets the light power */ get lightPower() { return this._frameGraphTask.lightPower; } set lightPower(value) { this._frameGraphTask.lightPower = value; } /** * Gets the current class name * @returns the class name */ getClassName() { return "NodeRenderGraphVolumetricLightingBlock"; } /** * Gets the target input component */ get target() { return this._inputs[0]; } /** * Gets the depth texture input component */ get depth() { return this._inputs[1]; } /** * Gets the camera input component */ get camera() { return this._inputs[2]; } /** * Gets the lighting volume mesh input component */ get lightingVolumeMesh() { return this._inputs[3]; } /** * Gets the light input component */ get light() { return this._inputs[4]; } /** * Gets the lighting volume texture input component */ get lightingVolumeTexture() { return this._inputs[5]; } /** * Gets the output component */ get output() { return this._outputs[0]; } _buildBlock(state) { super._buildBlock(state); this.output.value = this._frameGraphTask.outputTexture; this._frameGraphTask.targetTexture = this.target.connectedPoint?.value; this._frameGraphTask.depthTexture = this.depth.connectedPoint?.value; this._frameGraphTask.camera = this.camera.connectedPoint?.value; this._frameGraphTask.lightingVolumeMesh = this.lightingVolumeMesh.connectedPoint?.value; this._frameGraphTask.light = this.light.connectedPoint?.value; this._frameGraphTask.lightingVolumeTexture = this.lightingVolumeTexture.connectedPoint?.value; } _dumpPropertiesCode() { const codes = []; codes.push(`${this._codeVariableName}.phaseG = ${this.phaseG};`); codes.push(`${this._codeVariableName}.extinction = new BABYLON.Vector3(${this.extinction.x}, ${this.extinction.y}, ${this.extinction.z});`); codes.push(`${this._codeVariableName}.lightPower = new Color3(${this.lightPower.r}, ${this.lightPower.g}, ${this.lightPower.b});`); return super._dumpPropertiesCode() + codes.join("\n"); } serialize() { const serializationObject = super.serialize(); serializationObject.phaseG = this.phaseG; serializationObject.extinction = this.extinction.asArray(); serializationObject.lightPower = this.lightPower.asArray(); return serializationObject; } _deserialize(serializationObject) { super._deserialize(serializationObject); this.phaseG = serializationObject.phaseG; this.extinction = Vector3.FromArray(serializationObject.extinction); this.lightPower = Color3.FromArray(serializationObject.lightPower); } } __decorate([ editableInPropertyPage("PhaseG", 1 /* PropertyTypeForEdition.Float */, "PROPERTIES", { min: -0.9, max: 0.9 }) ], NodeRenderGraphVolumetricLightingBlock.prototype, "phaseG", null); __decorate([ editableInPropertyPage("Enable extinction", 0 /* PropertyTypeForEdition.Boolean */, "PROPERTIES") ], NodeRenderGraphVolumetricLightingBlock.prototype, "enableExtinction", null); __decorate([ editableInPropertyPage("Extinction", 4 /* PropertyTypeForEdition.Vector3 */, "PROPERTIES") ], NodeRenderGraphVolumetricLightingBlock.prototype, "extinction", null); __decorate([ editableInPropertyPage("Light power", 6 /* PropertyTypeForEdition.Color3 */, "PROPERTIES") ], NodeRenderGraphVolumetricLightingBlock.prototype, "lightPower", null); RegisterClass("BABYLON.NodeRenderGraphVolumetricLightingBlock", NodeRenderGraphVolumetricLightingBlock); //# sourceMappingURL=volumetricLightingBlock.js.map