UNPKG

@openhps/core

Version:

Open Hybrid Positioning System - Core component

115 lines (107 loc) 3.51 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.default = void 0; var _AnalyticLightNode = _interopRequireDefault(require("./AnalyticLightNode.js")); var _TextureNode = require("../accessors/TextureNode.js"); var _UniformNode = require("../core/UniformNode.js"); var _Lights = require("../accessors/Lights.js"); var _UniformGroupNode = require("../core/UniformGroupNode.js"); var _Matrix = require("../../math/Matrix4.js"); var _Vector = require("../../math/Vector3.js"); var _constants = require("../core/constants.js"); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } const _matrix41 = /*@__PURE__*/new _Matrix.Matrix4(); const _matrix42 = /*@__PURE__*/new _Matrix.Matrix4(); let _ltcLib = null; /** * Module for representing rect area lights as nodes. * * @augments AnalyticLightNode */ class RectAreaLightNode extends _AnalyticLightNode.default { static get type() { return 'RectAreaLightNode'; } /** * Constructs a new rect area light node. * * @param {?RectAreaLight} [light=null] - The rect area light source. */ constructor(light = null) { super(light); /** * Uniform node representing the half height of the are light. * * @type {UniformNode<vec3>} */ this.halfHeight = (0, _UniformNode.uniform)(new _Vector.Vector3()).setGroup(_UniformGroupNode.renderGroup); /** * Uniform node representing the half width of the are light. * * @type {UniformNode<vec3>} */ this.halfWidth = (0, _UniformNode.uniform)(new _Vector.Vector3()).setGroup(_UniformGroupNode.renderGroup); /** * The `updateType` is set to `NodeUpdateType.RENDER` since the light * relies on `viewMatrix` which might vary per render call. * * @type {string} * @default 'render' */ this.updateType = _constants.NodeUpdateType.RENDER; } /** * Overwritten to updated rect area light specific uniforms. * * @param {NodeFrame} frame - A reference to the current node frame. */ update(frame) { super.update(frame); const { light } = this; const viewMatrix = frame.camera.matrixWorldInverse; _matrix42.identity(); _matrix41.copy(light.matrixWorld); _matrix41.premultiply(viewMatrix); _matrix42.extractRotation(_matrix41); this.halfWidth.value.set(light.width * 0.5, 0.0, 0.0); this.halfHeight.value.set(0.0, light.height * 0.5, 0.0); this.halfWidth.value.applyMatrix4(_matrix42); this.halfHeight.value.applyMatrix4(_matrix42); } setupDirectRectArea(builder) { let ltc_1, ltc_2; if (builder.isAvailable('float32Filterable')) { ltc_1 = (0, _TextureNode.texture)(_ltcLib.LTC_FLOAT_1); ltc_2 = (0, _TextureNode.texture)(_ltcLib.LTC_FLOAT_2); } else { ltc_1 = (0, _TextureNode.texture)(_ltcLib.LTC_HALF_1); ltc_2 = (0, _TextureNode.texture)(_ltcLib.LTC_HALF_2); } const { colorNode, light } = this; const lightPosition = (0, _Lights.lightViewPosition)(light); return { lightColor: colorNode, lightPosition, halfWidth: this.halfWidth, halfHeight: this.halfHeight, ltc_1, ltc_2 }; } /** * Used to configure the internal BRDF approximation texture data. * * @param {RectAreaLightTexturesLib} ltc - The BRDF approximation texture data. */ static setLTC(ltc) { _ltcLib = ltc; } } var _default = exports.default = RectAreaLightNode;