UNPKG

@openhps/core

Version:

Open Hybrid Positioning System - Core component

98 lines (91 loc) 2.6 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.directPointLight = exports.default = void 0; var _AnalyticLightNode = _interopRequireDefault(require("./AnalyticLightNode.js")); var _LightUtils = require("./LightUtils.js"); var _UniformNode = require("../core/UniformNode.js"); var _UniformGroupNode = require("../core/UniformGroupNode.js"); var _PointShadowNode = require("./PointShadowNode.js"); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } const directPointLight = ({ color, lightVector, cutoffDistance, decayExponent }) => { const lightDirection = lightVector.normalize(); const lightDistance = lightVector.length(); const attenuation = (0, _LightUtils.getDistanceAttenuation)({ lightDistance, cutoffDistance, decayExponent }); const lightColor = color.mul(attenuation); return { lightDirection, lightColor }; }; /** * Module for representing point lights as nodes. * * @augments AnalyticLightNode */ exports.directPointLight = directPointLight; class PointLightNode extends _AnalyticLightNode.default { static get type() { return 'PointLightNode'; } /** * Constructs a new point light node. * * @param {?PointLight} [light=null] - The point light source. */ constructor(light = null) { super(light); /** * Uniform node representing the cutoff distance. * * @type {UniformNode<float>} */ this.cutoffDistanceNode = (0, _UniformNode.uniform)(0).setGroup(_UniformGroupNode.renderGroup); /** * Uniform node representing the decay exponent. * * @type {UniformNode<float>} */ this.decayExponentNode = (0, _UniformNode.uniform)(2).setGroup(_UniformGroupNode.renderGroup); } /** * Overwritten to updated point light specific uniforms. * * @param {NodeFrame} frame - A reference to the current node frame. */ update(frame) { const { light } = this; super.update(frame); this.cutoffDistanceNode.value = light.distance; this.decayExponentNode.value = light.decay; } /** * Overwritten to setup point light specific shadow. * * @return {PointShadowNode} */ setupShadowNode() { return (0, _PointShadowNode.pointShadow)(this.light); } setupDirect(builder) { return directPointLight({ color: this.colorNode, lightVector: this.getLightVector(builder), cutoffDistance: this.cutoffDistanceNode, decayExponent: this.decayExponentNode }); } } var _default = exports.default = PointLightNode;