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.

508 lines (507 loc) 25.8 kB
import { __decorate } from "../../../../tslib.es6.js"; import { NodeRenderGraphBaseObjectRendererBlock } from "./baseObjectRendererBlock.js"; import { RegisterClass } from "../../../../Misc/typeStore.js"; import { NodeRenderGraphBlockConnectionPointTypes } from "../../Types/nodeRenderGraphTypes.js"; import { editableInPropertyPage } from "../../../../Decorators/nodeDecorator.js"; import { FrameGraphGeometryRendererTask } from "../../../Tasks/Rendering/geometryRendererTask.js"; /** * Block that render geometry of objects to a multi render target */ export class NodeRenderGraphGeometryRendererBlock extends NodeRenderGraphBaseObjectRendererBlock { /** * Gets the frame graph task associated with this block */ get task() { return this._frameGraphTask; } /** * Create a new NodeRenderGraphGeometryRendererBlock * @param name defines the block name * @param frameGraph defines the hosting frame graph * @param scene defines the hosting scene * @param doNotChangeAspectRatio True (default) to not change the aspect ratio of the scene in the RTT * @param enableClusteredLights True (default) to enable clustered lights */ constructor(name, frameGraph, scene, doNotChangeAspectRatio = true, enableClusteredLights = true) { super(name, frameGraph, scene); // View depth this.viewDepthFormat = 6; this.viewDepthType = 1; // Normalized view depth this.normalizedViewDepthFormat = 6; this.normalizedViewDepthType = 2; // Screen depth this.screenDepthFormat = 6; this.screenDepthType = 1; // View normal this.viewNormalFormat = 5; this.viewNormalType = 2; // World normal this.worldNormalFormat = 5; this.worldNormalType = 0; // Local position this.localPositionFormat = 5; this.localPositionType = 2; // World Position this.worldPositionFormat = 5; this.worldPositionType = 2; // Albedo this.albedoFormat = 5; this.albedoType = 0; // Reflectivity this.reflectivityFormat = 5; this.reflectivityType = 0; // Velocity this.velocityFormat = 5; this.velocityType = 0; // Linear velocity this.linearVelocityFormat = 5; this.linearVelocityType = 2; this.getInputByName("target").isOptional = true; this.registerOutput("geomViewDepth", NodeRenderGraphBlockConnectionPointTypes.TextureViewDepth); this.registerOutput("geomNormViewDepth", NodeRenderGraphBlockConnectionPointTypes.TextureNormalizedViewDepth); this.registerOutput("geomScreenDepth", NodeRenderGraphBlockConnectionPointTypes.TextureScreenDepth); this.registerOutput("geomViewNormal", NodeRenderGraphBlockConnectionPointTypes.TextureViewNormal); this.registerOutput("geomWorldNormal", NodeRenderGraphBlockConnectionPointTypes.TextureWorldNormal); this.registerOutput("geomLocalPosition", NodeRenderGraphBlockConnectionPointTypes.TextureLocalPosition); this.registerOutput("geomWorldPosition", NodeRenderGraphBlockConnectionPointTypes.TextureWorldPosition); this.registerOutput("geomAlbedo", NodeRenderGraphBlockConnectionPointTypes.TextureAlbedo); this.registerOutput("geomReflectivity", NodeRenderGraphBlockConnectionPointTypes.TextureReflectivity); this.registerOutput("geomVelocity", NodeRenderGraphBlockConnectionPointTypes.TextureVelocity); this.registerOutput("geomLinearVelocity", NodeRenderGraphBlockConnectionPointTypes.TextureLinearVelocity); this._frameGraphTask = new FrameGraphGeometryRendererTask(this.name, frameGraph, scene, { doNotChangeAspectRatio, enableClusteredLights }); } _createFrameGraphObject() { this._frameGraphTask?.dispose(); this._frameGraphTask = new FrameGraphGeometryRendererTask(this.name, this._frameGraph, this._scene, { doNotChangeAspectRatio: this._additionalConstructionParameters[0], enableClusteredLights: this._additionalConstructionParameters[1], }); } _saveState(state) { super._saveState(state); state.disabled = this._frameGraphTask.disabled; state.isMainObjectRenderer = this.isMainObjectRenderer; state.depthTest = this.depthTest; state.depthWrite = this.depthWrite; state.disableShadows = this.disableShadows; state.renderInLinearSpace = this.renderInLinearSpace; state.renderParticles = this.renderParticles; state.renderSprites = this.renderSprites; state.forceLayerMaskCheck = this.forceLayerMaskCheck; state.enableBoundingBoxRendering = this.enableBoundingBoxRendering; state.enableOutlineRendering = this.enableOutlineRendering; state.width = this.width; state.height = this.height; state.sizeInPercentage = this.sizeInPercentage; state.samples = this.samples; state.reverseCulling = this.reverseCulling; state.dontRenderWhenMaterialDepthWriteIsDisabled = this.dontRenderWhenMaterialDepthWriteIsDisabled; state.disableDepthPrePass = this.disableDepthPrePass; } _restoreState(state) { super._restoreState(state); this._frameGraphTask.disabled = state.disabled; this.isMainObjectRenderer = state.isMainObjectRenderer; this.depthTest = state.depthTest; this.depthWrite = state.depthWrite; this.disableShadows = state.disableShadows; this.renderInLinearSpace = state.renderInLinearSpace; this.renderParticles = state.renderParticles; this.renderSprites = state.renderSprites; this.forceLayerMaskCheck = state.forceLayerMaskCheck; this.enableBoundingBoxRendering = state.enableBoundingBoxRendering; this.enableOutlineRendering = state.enableOutlineRendering; this.width = state.width; this.height = state.height; this.sizeInPercentage = state.sizeInPercentage; this.samples = state.samples; this.reverseCulling = state.reverseCulling; this.dontRenderWhenMaterialDepthWriteIsDisabled = state.dontRenderWhenMaterialDepthWriteIsDisabled; this.disableDepthPrePass = state.disableDepthPrePass; } /** Width of the geometry texture */ get width() { return this._frameGraphTask.size.width; } set width(value) { this._frameGraphTask.size.width = value; } /** Height of the geometry texture */ get height() { return this._frameGraphTask.size.height; } set height(value) { this._frameGraphTask.size.height = value; } /** Indicates if the geometry texture width and height are percentages or absolute values */ get sizeInPercentage() { return this._frameGraphTask.sizeIsPercentage; } set sizeInPercentage(value) { this._frameGraphTask.sizeIsPercentage = value; } /** Number of samples of the geometry texture */ get samples() { return this._frameGraphTask.samples; } set samples(value) { this._frameGraphTask.samples = value; } /** Indicates if culling must be reversed */ get reverseCulling() { return this._frameGraphTask.reverseCulling; } set reverseCulling(value) { this._frameGraphTask.reverseCulling = value; } /** Indicates if a mesh shouldn't be rendered when its material has depth write disabled */ get dontRenderWhenMaterialDepthWriteIsDisabled() { return this._frameGraphTask.dontRenderWhenMaterialDepthWriteIsDisabled; } set dontRenderWhenMaterialDepthWriteIsDisabled(value) { this._frameGraphTask.dontRenderWhenMaterialDepthWriteIsDisabled = value; } /** Indicates if depth pre-pass must be disabled */ get disableDepthPrePass() { return this._frameGraphTask.disableDepthPrePass; } set disableDepthPrePass(value) { this._frameGraphTask.disableDepthPrePass = value; } /** * Gets the current class name * @returns the class name */ getClassName() { return "NodeRenderGraphGeometryRendererBlock"; } /** * Gets the geometry view depth component */ get geomViewDepth() { return this._outputs[3]; } /** * Gets the geometry normalized view depth component */ get geomNormViewDepth() { return this._outputs[4]; } /** * Gets the geometry screen depth component */ get geomScreenDepth() { return this._outputs[5]; } /** * Gets the geometry view normal component */ get geomViewNormal() { return this._outputs[6]; } /** * Gets the world geometry normal component */ get geomWorldNormal() { return this._outputs[7]; } /** * Gets the geometry local position component */ get geomLocalPosition() { return this._outputs[8]; } /** * Gets the geometry world position component */ get geomWorldPosition() { return this._outputs[9]; } /** * Gets the geometry albedo component */ get geomAlbedo() { return this._outputs[10]; } /** * Gets the geometry reflectivity component */ get geomReflectivity() { return this._outputs[11]; } /** * Gets the geometry velocity component */ get geomVelocity() { return this._outputs[12]; } /** * Gets the geometry linear velocity component */ get geomLinearVelocity() { return this._outputs[13]; } _buildBlock(state) { super._buildBlock(state); const textureActivation = [ this.geomViewDepth.isConnected, this.geomNormViewDepth.isConnected, this.geomScreenDepth.isConnected, this.geomViewNormal.isConnected, this.geomWorldNormal.isConnected, this.geomLocalPosition.isConnected, this.geomWorldPosition.isConnected, this.geomAlbedo.isConnected, this.geomReflectivity.isConnected, this.geomVelocity.isConnected, this.geomLinearVelocity.isConnected, ]; this.geomViewDepth.value = this._frameGraphTask.geometryViewDepthTexture; this.geomNormViewDepth.value = this._frameGraphTask.geometryNormViewDepthTexture; this.geomScreenDepth.value = this._frameGraphTask.geometryScreenDepthTexture; this.geomViewNormal.value = this._frameGraphTask.geometryViewNormalTexture; this.geomWorldNormal.value = this._frameGraphTask.geometryWorldNormalTexture; this.geomLocalPosition.value = this._frameGraphTask.geometryLocalPositionTexture; this.geomWorldPosition.value = this._frameGraphTask.geometryWorldPositionTexture; this.geomAlbedo.value = this._frameGraphTask.geometryAlbedoTexture; this.geomReflectivity.value = this._frameGraphTask.geometryReflectivityTexture; this.geomVelocity.value = this._frameGraphTask.geometryVelocityTexture; this.geomLinearVelocity.value = this._frameGraphTask.geometryLinearVelocityTexture; this._frameGraphTask.textureDescriptions = []; const textureFormats = [ this.viewDepthFormat, this.normalizedViewDepthFormat, this.screenDepthFormat, this.viewNormalFormat, this.worldNormalFormat, this.localPositionFormat, this.worldPositionFormat, this.albedoFormat, this.reflectivityFormat, this.velocityFormat, this.linearVelocityFormat, ]; const textureTypes = [ this.viewDepthType, this.normalizedViewDepthType, this.screenDepthType, this.viewNormalType, this.worldNormalType, this.localPositionType, this.worldPositionType, this.albedoType, this.reflectivityType, this.velocityType, this.linearVelocityType, ]; const bufferTypes = [ 5, 13, 10, 6, 8, 9, 1, 12, 3, 2, 11, ]; for (let i = 0; i < textureActivation.length; i++) { if (textureActivation[i]) { this._frameGraphTask.textureDescriptions.push({ textureFormat: textureFormats[i], textureType: textureTypes[i], type: bufferTypes[i], }); } } } _dumpPropertiesCode() { const codes = []; codes.push(`${this._codeVariableName}.size = { width: ${this.width}, height: ${this.height} };`); codes.push(`${this._codeVariableName}.sizeInPercentage = ${this.sizeInPercentage};`); codes.push(`${this._codeVariableName}.samples = ${this.samples};`); codes.push(`${this._codeVariableName}.reverseCulling = ${this.reverseCulling};`); codes.push(`${this._codeVariableName}.dontRenderWhenMaterialDepthWriteIsDisabled = ${this.dontRenderWhenMaterialDepthWriteIsDisabled};`); codes.push(`${this._codeVariableName}.disableDepthPrePass = ${this.disableDepthPrePass};`); codes.push(`${this._codeVariableName}.viewDepthFormat = ${this.viewDepthFormat};`); codes.push(`${this._codeVariableName}.viewDepthType = ${this.viewDepthType};`); codes.push(`${this._codeVariableName}.normalizedViewDepthFormat = ${this.normalizedViewDepthFormat};`); codes.push(`${this._codeVariableName}.normalizedViewDepthType = ${this.normalizedViewDepthType};`); codes.push(`${this._codeVariableName}.screenDepthFormat = ${this.screenDepthFormat};`); codes.push(`${this._codeVariableName}.screenDepthType = ${this.screenDepthType};`); codes.push(`${this._codeVariableName}.localPositionFormat = ${this.localPositionFormat};`); codes.push(`${this._codeVariableName}.localPositionType = ${this.localPositionType};`); codes.push(`${this._codeVariableName}.worldPositionFormat = ${this.worldPositionFormat};`); codes.push(`${this._codeVariableName}.worldPositionType = ${this.worldPositionType};`); codes.push(`${this._codeVariableName}.viewNormalFormat = ${this.viewNormalFormat};`); codes.push(`${this._codeVariableName}.viewNormalType = ${this.viewNormalType};`); codes.push(`${this._codeVariableName}.worldNormalFormat = ${this.worldNormalFormat};`); codes.push(`${this._codeVariableName}.worldNormalType = ${this.worldNormalType};`); codes.push(`${this._codeVariableName}.albedoFormat = ${this.albedoFormat};`); codes.push(`${this._codeVariableName}.albedoType = ${this.albedoType};`); codes.push(`${this._codeVariableName}.reflectivityFormat = ${this.reflectivityFormat};`); codes.push(`${this._codeVariableName}.reflectivityType = ${this.reflectivityType};`); codes.push(`${this._codeVariableName}.velocityFormat = ${this.velocityFormat};`); codes.push(`${this._codeVariableName}.velocityType = ${this.velocityType};`); codes.push(`${this._codeVariableName}.linearVelocityFormat = ${this.linearVelocityFormat};`); codes.push(`${this._codeVariableName}.linearVelocityType = ${this.linearVelocityType};`); return super._dumpPropertiesCode() + codes.join("\n"); } serialize() { const serializationObject = super.serialize(); serializationObject.sizeInPercentage = this.sizeInPercentage; serializationObject.width = this.width; serializationObject.height = this.height; serializationObject.samples = this.samples; serializationObject.reverseCulling = this.reverseCulling; serializationObject.dontRenderWhenMaterialDepthWriteIsDisabled = this.dontRenderWhenMaterialDepthWriteIsDisabled; serializationObject.disableDepthPrePass = this.disableDepthPrePass; serializationObject.viewDepthFormat = this.viewDepthFormat; serializationObject.viewDepthType = this.viewDepthType; serializationObject.normalizedViewDepthFormat = this.normalizedViewDepthFormat; serializationObject.normalizedViewDepthType = this.normalizedViewDepthType; serializationObject.screenDepthFormat = this.screenDepthFormat; serializationObject.screenDepthType = this.screenDepthType; serializationObject.localPositionFormat = this.localPositionFormat; serializationObject.localPositionType = this.localPositionType; serializationObject.worldPositionFormat = this.worldPositionFormat; serializationObject.worldPositionType = this.worldPositionType; serializationObject.viewNormalFormat = this.viewNormalFormat; serializationObject.viewNormalType = this.viewNormalType; serializationObject.worldNormalFormat = this.worldNormalFormat; serializationObject.worldNormalType = this.worldNormalType; serializationObject.albedoFormat = this.albedoFormat; serializationObject.albedoType = this.albedoType; serializationObject.reflectivityFormat = this.reflectivityFormat; serializationObject.reflectivityType = this.reflectivityType; serializationObject.velocityFormat = this.velocityFormat; serializationObject.velocityType = this.velocityType; serializationObject.linearVelocityFormat = this.linearVelocityFormat; serializationObject.linearVelocityType = this.linearVelocityType; return serializationObject; } _deserialize(serializationObject) { super._deserialize(serializationObject); this.sizeInPercentage = !!serializationObject.sizeInPercentage; this.width = serializationObject.width ?? 100; this.height = serializationObject.height ?? 100; this.samples = serializationObject.samples; this.reverseCulling = serializationObject.reverseCulling; this.dontRenderWhenMaterialDepthWriteIsDisabled = serializationObject.dontRenderWhenMaterialDepthWriteIsDisabled; this.disableDepthPrePass = serializationObject.disableDepthPrePass ?? true; this.viewDepthFormat = serializationObject.viewDepthFormat; this.viewDepthType = serializationObject.viewDepthType; this.normalizedViewDepthFormat = serializationObject.normalizedViewDepthFormat ?? 6; this.normalizedViewDepthType = serializationObject.normalizedViewDepthType ?? 0; this.screenDepthFormat = serializationObject.screenDepthFormat; this.screenDepthType = serializationObject.screenDepthType; this.localPositionFormat = serializationObject.localPositionFormat; this.localPositionType = serializationObject.localPositionType; this.worldPositionFormat = serializationObject.worldPositionFormat; this.worldPositionType = serializationObject.worldPositionType; this.viewNormalFormat = serializationObject.viewNormalFormat; this.viewNormalType = serializationObject.viewNormalType; this.worldNormalFormat = serializationObject.worldNormalFormat; this.worldNormalType = serializationObject.worldNormalType; this.albedoFormat = serializationObject.albedoFormat; this.albedoType = serializationObject.albedoType; this.reflectivityFormat = serializationObject.reflectivityFormat; this.reflectivityType = serializationObject.reflectivityType; this.velocityFormat = serializationObject.velocityFormat; this.velocityType = serializationObject.velocityType; this.linearVelocityFormat = serializationObject.linearVelocityFormat; this.linearVelocityType = serializationObject.linearVelocityType; } } __decorate([ editableInPropertyPage("Texture width", 2 /* PropertyTypeForEdition.Int */, "GEOMETRY") ], NodeRenderGraphGeometryRendererBlock.prototype, "width", null); __decorate([ editableInPropertyPage("Texture height", 2 /* PropertyTypeForEdition.Int */, "GEOMETRY") ], NodeRenderGraphGeometryRendererBlock.prototype, "height", null); __decorate([ editableInPropertyPage("Size is in percentage", 0 /* PropertyTypeForEdition.Boolean */, "GEOMETRY") ], NodeRenderGraphGeometryRendererBlock.prototype, "sizeInPercentage", null); __decorate([ editableInPropertyPage("Samples", 2 /* PropertyTypeForEdition.Int */, "GEOMETRY", { min: 1, max: 8 }) ], NodeRenderGraphGeometryRendererBlock.prototype, "samples", null); __decorate([ editableInPropertyPage("Reverse culling", 0 /* PropertyTypeForEdition.Boolean */, "GEOMETRY") ], NodeRenderGraphGeometryRendererBlock.prototype, "reverseCulling", null); __decorate([ editableInPropertyPage("Don't render if material depth write is disabled", 0 /* PropertyTypeForEdition.Boolean */, "GEOMETRY") ], NodeRenderGraphGeometryRendererBlock.prototype, "dontRenderWhenMaterialDepthWriteIsDisabled", null); __decorate([ editableInPropertyPage("Disable depth pre-pass", 0 /* PropertyTypeForEdition.Boolean */, "GEOMETRY") ], NodeRenderGraphGeometryRendererBlock.prototype, "disableDepthPrePass", null); __decorate([ editableInPropertyPage("Format", 9 /* PropertyTypeForEdition.TextureFormat */, "OUTPUT - VIEW DEPTH") ], NodeRenderGraphGeometryRendererBlock.prototype, "viewDepthFormat", void 0); __decorate([ editableInPropertyPage("Type", 10 /* PropertyTypeForEdition.TextureType */, "OUTPUT - VIEW DEPTH") ], NodeRenderGraphGeometryRendererBlock.prototype, "viewDepthType", void 0); __decorate([ editableInPropertyPage("Format", 9 /* PropertyTypeForEdition.TextureFormat */, "OUTPUT - NORMALIZED VIEW DEPTH") ], NodeRenderGraphGeometryRendererBlock.prototype, "normalizedViewDepthFormat", void 0); __decorate([ editableInPropertyPage("Type", 10 /* PropertyTypeForEdition.TextureType */, "OUTPUT - NORMALIZED VIEW DEPTH") ], NodeRenderGraphGeometryRendererBlock.prototype, "normalizedViewDepthType", void 0); __decorate([ editableInPropertyPage("Format", 9 /* PropertyTypeForEdition.TextureFormat */, "OUTPUT - SCREEN DEPTH") ], NodeRenderGraphGeometryRendererBlock.prototype, "screenDepthFormat", void 0); __decorate([ editableInPropertyPage("Type", 10 /* PropertyTypeForEdition.TextureType */, "OUTPUT - SCREEN DEPTH") ], NodeRenderGraphGeometryRendererBlock.prototype, "screenDepthType", void 0); __decorate([ editableInPropertyPage("Format", 9 /* PropertyTypeForEdition.TextureFormat */, "OUTPUT - VIEW NORMAL") ], NodeRenderGraphGeometryRendererBlock.prototype, "viewNormalFormat", void 0); __decorate([ editableInPropertyPage("Type", 10 /* PropertyTypeForEdition.TextureType */, "OUTPUT - VIEW NORMAL") ], NodeRenderGraphGeometryRendererBlock.prototype, "viewNormalType", void 0); __decorate([ editableInPropertyPage("Format", 9 /* PropertyTypeForEdition.TextureFormat */, "OUTPUT - WORLD NORMAL") ], NodeRenderGraphGeometryRendererBlock.prototype, "worldNormalFormat", void 0); __decorate([ editableInPropertyPage("Type", 10 /* PropertyTypeForEdition.TextureType */, "OUTPUT - WORLD NORMAL") ], NodeRenderGraphGeometryRendererBlock.prototype, "worldNormalType", void 0); __decorate([ editableInPropertyPage("Format", 9 /* PropertyTypeForEdition.TextureFormat */, "OUTPUT - LOCAL POSITION") ], NodeRenderGraphGeometryRendererBlock.prototype, "localPositionFormat", void 0); __decorate([ editableInPropertyPage("Type", 10 /* PropertyTypeForEdition.TextureType */, "OUTPUT - LOCAL POSITION") ], NodeRenderGraphGeometryRendererBlock.prototype, "localPositionType", void 0); __decorate([ editableInPropertyPage("Format", 9 /* PropertyTypeForEdition.TextureFormat */, "OUTPUT - WORLD POSITION") ], NodeRenderGraphGeometryRendererBlock.prototype, "worldPositionFormat", void 0); __decorate([ editableInPropertyPage("Type", 10 /* PropertyTypeForEdition.TextureType */, "OUTPUT - WORLD POSITION") ], NodeRenderGraphGeometryRendererBlock.prototype, "worldPositionType", void 0); __decorate([ editableInPropertyPage("Format", 9 /* PropertyTypeForEdition.TextureFormat */, "OUTPUT - ALBEDO") ], NodeRenderGraphGeometryRendererBlock.prototype, "albedoFormat", void 0); __decorate([ editableInPropertyPage("Type", 10 /* PropertyTypeForEdition.TextureType */, "OUTPUT - ALBEDO") ], NodeRenderGraphGeometryRendererBlock.prototype, "albedoType", void 0); __decorate([ editableInPropertyPage("Format", 9 /* PropertyTypeForEdition.TextureFormat */, "OUTPUT - REFLECTIVITY") ], NodeRenderGraphGeometryRendererBlock.prototype, "reflectivityFormat", void 0); __decorate([ editableInPropertyPage("Type", 10 /* PropertyTypeForEdition.TextureType */, "OUTPUT - REFLECTIVITY") ], NodeRenderGraphGeometryRendererBlock.prototype, "reflectivityType", void 0); __decorate([ editableInPropertyPage("Format", 9 /* PropertyTypeForEdition.TextureFormat */, "OUTPUT - VELOCITY") ], NodeRenderGraphGeometryRendererBlock.prototype, "velocityFormat", void 0); __decorate([ editableInPropertyPage("Type", 10 /* PropertyTypeForEdition.TextureType */, "OUTPUT - VELOCITY") ], NodeRenderGraphGeometryRendererBlock.prototype, "velocityType", void 0); __decorate([ editableInPropertyPage("Format", 9 /* PropertyTypeForEdition.TextureFormat */, "OUTPUT - LINEAR VELOCITY") ], NodeRenderGraphGeometryRendererBlock.prototype, "linearVelocityFormat", void 0); __decorate([ editableInPropertyPage("Type", 10 /* PropertyTypeForEdition.TextureType */, "OUTPUT - LINEAR VELOCITY") ], NodeRenderGraphGeometryRendererBlock.prototype, "linearVelocityType", void 0); RegisterClass("BABYLON.NodeRenderGraphGeometryRendererBlock", NodeRenderGraphGeometryRendererBlock); //# sourceMappingURL=geometryRendererBlock.js.map