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.

80 lines 2.9 kB
import { NodeMaterialBlock } from "../../nodeMaterialBlock.js"; import { NodeMaterialBlockConnectionPointTypes } from "../../Enums/nodeMaterialBlockConnectionPointTypes.js"; import { NodeMaterialBlockTargets } from "../../Enums/nodeMaterialBlockTargets.js"; import { RegisterClass } from "../../../../Misc/typeStore.js"; /** * Block used to get the screen sizes */ export class ScreenSizeBlock extends NodeMaterialBlock { /** * Name of the variable in the shader that holds the screen size */ get associatedVariableName() { return this._varName; } /** * Creates a new ScreenSizeBlock * @param name defines the block name */ constructor(name) { super(name, NodeMaterialBlockTargets.Fragment); this.registerOutput("xy", NodeMaterialBlockConnectionPointTypes.Vector2, NodeMaterialBlockTargets.Fragment); this.registerOutput("x", NodeMaterialBlockConnectionPointTypes.Float, NodeMaterialBlockTargets.Fragment); this.registerOutput("y", NodeMaterialBlockConnectionPointTypes.Float, NodeMaterialBlockTargets.Fragment); } /** * Gets the current class name * @returns the class name */ getClassName() { return "ScreenSizeBlock"; } /** * Gets the xy component */ get xy() { return this._outputs[0]; } /** * Gets the x component */ get x() { return this._outputs[1]; } /** * Gets the y component */ get y() { return this._outputs[2]; } bind(effect) { const engine = this._scene.getEngine(); effect.setFloat2(this._varName, engine.getRenderWidth(), engine.getRenderHeight()); } // eslint-disable-next-line @typescript-eslint/naming-convention writeOutputs(state, varName) { let code = ""; for (const output of this._outputs) { if (output.hasEndpoints) { code += `${state._declareOutput(output)} = ${varName}.${output.name};\n`; } } return code; } _buildBlock(state) { super._buildBlock(state); this._scene = state.sharedData.scene; if (state.target === NodeMaterialBlockTargets.Vertex) { state.sharedData.raiseBuildError("ScreenSizeBlock must only be used in a fragment shader"); return this; } state.sharedData.bindableBlocks.push(this); this._varName = state._getFreeVariableName("screenSize"); state._emitUniformFromString(this._varName, NodeMaterialBlockConnectionPointTypes.Vector2); const prefix = state.shaderLanguage === 1 /* ShaderLanguage.WGSL */ ? "uniforms." : ""; state.compilationString += this.writeOutputs(state, prefix + this._varName); return this; } } RegisterClass("BABYLON.ScreenSizeBlock", ScreenSizeBlock); //# sourceMappingURL=screenSizeBlock.js.map