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.

104 lines 4.28 kB
import { __decorate } from "../../../tslib.es6.js"; import { RegisterClass } from "../../../Misc/typeStore.js"; import { NodeMaterialBlock } from "../nodeMaterialBlock.js"; import { NodeMaterialBlockConnectionPointTypes } from "../Enums/nodeMaterialBlockConnectionPointTypes.js"; import { NodeMaterialBlockTargets } from "../Enums/nodeMaterialBlockTargets.js"; import { editableInPropertyPage } from "../../../Decorators/nodeDecorator.js"; /** * Block used to render intermediate debug values * Please note that the node needs to be active to be generated in the shader * Only one DebugBlock should be active at a time */ export class NodeMaterialDebugBlock extends NodeMaterialBlock { /** * Gets or sets a boolean indicating that the block is active */ get isActive() { return this._isActive && this.debug.isConnected; } set isActive(value) { if (this._isActive === value) { return; } this._isActive = value; } /** * Creates a new NodeMaterialDebugBlock * @param name defines the block name */ constructor(name) { super(name, NodeMaterialBlockTargets.Fragment, true, true); this._isActive = false; /** Gets or sets a boolean indicating if we want to render alpha when using a rgba input*/ this.renderAlpha = false; this.registerInput("debug", NodeMaterialBlockConnectionPointTypes.AutoDetect, true); this.debug.excludedConnectionPointTypes.push(NodeMaterialBlockConnectionPointTypes.Matrix); } /** @internal */ get _isFinalOutputAndActive() { return this.isActive; } /** @internal */ get _hasPrecedence() { return true; } /** * Gets the rgba input component */ get debug() { return this._inputs[0]; } /** * Gets the current class name * @returns the class name */ getClassName() { return "NodeMaterialDebugBlock"; } _buildBlock(state) { super._buildBlock(state); if (!this._isActive) { return this; } let outputString = "gl_FragColor"; if (state.shaderLanguage === 1 /* ShaderLanguage.WGSL */) { outputString = "fragmentOutputs.color"; } const debug = this.debug; if (!debug.connectedPoint) { return this; } if (debug.connectedPoint.type === NodeMaterialBlockConnectionPointTypes.Float) { state.compilationString += `${outputString} = vec4${state.fSuffix}(${debug.associatedVariableName}, ${debug.associatedVariableName}, ${debug.associatedVariableName}, 1.0);\n`; } else if (debug.connectedPoint.type === NodeMaterialBlockConnectionPointTypes.Vector2) { state.compilationString += `${outputString} = vec4${state.fSuffix}(${debug.associatedVariableName}, 0., 1.0);\n`; } else if (debug.connectedPoint.type === NodeMaterialBlockConnectionPointTypes.Color3 || debug.connectedPoint.type === NodeMaterialBlockConnectionPointTypes.Vector3) { state.compilationString += `${outputString} = vec4${state.fSuffix}(${debug.associatedVariableName}, 1.0);\n`; } else if (this.renderAlpha) { state.compilationString += `${outputString} =${debug.associatedVariableName};\n`; } else { state.compilationString += `${outputString} = vec4${state.fSuffix}(${debug.associatedVariableName}.rgb, 1.0);\n`; } return this; } serialize() { const serializationObject = super.serialize(); serializationObject.isActive = this._isActive; serializationObject.renderAlpha = this.renderAlpha; return serializationObject; } _deserialize(serializationObject, scene, rootUrl) { super._deserialize(serializationObject, scene, rootUrl); this.isActive = serializationObject.isActive; this.renderAlpha = serializationObject.renderAlpha; } } __decorate([ editableInPropertyPage("Render Alpha", 0 /* PropertyTypeForEdition.Boolean */, undefined) ], NodeMaterialDebugBlock.prototype, "renderAlpha", void 0); RegisterClass("BABYLON.NodeMaterialDebugBlock", NodeMaterialDebugBlock); //# sourceMappingURL=debugBlock.js.map