UNPKG

@openhps/core

Version:

Open Hybrid Positioning System - Core component

105 lines (99 loc) 3.31 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.lightingContext = exports.default = void 0; var _ContextNode = _interopRequireDefault(require("../core/ContextNode.js")); var _TSLBase = require("../tsl/TSLBase.js"); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } /** * `LightingContextNode` represents an extension of the {@link ContextNode} module * by adding lighting specific context data. It represents the runtime context of * {@link LightsNode}. * * @augments ContextNode */ class LightingContextNode extends _ContextNode.default { static get type() { return 'LightingContextNode'; } /** * Constructs a new lighting context node. * * @param {LightsNode} lightsNode - The lights node. * @param {?LightingModel} [lightingModel=null] - The current lighting model. * @param {?Node<vec3>} [backdropNode=null] - A backdrop node. * @param {?Node<float>} [backdropAlphaNode=null] - A backdrop alpha node. */ constructor(lightsNode, lightingModel = null, backdropNode = null, backdropAlphaNode = null) { super(lightsNode); /** * The current lighting model. * * @type {?LightingModel} * @default null */ this.lightingModel = lightingModel; /** * A backdrop node. * * @type {?Node<vec3>} * @default null */ this.backdropNode = backdropNode; /** * A backdrop alpha node. * * @type {?Node<float>} * @default null */ this.backdropAlphaNode = backdropAlphaNode; this._value = null; } /** * Returns a lighting context object. * * @return {{ * radiance: Node<vec3>, * irradiance: Node<vec3>, * iblIrradiance: Node<vec3>, * ambientOcclusion: Node<float>, * reflectedLight: {directDiffuse: Node<vec3>, directSpecular: Node<vec3>, indirectDiffuse: Node<vec3>, indirectSpecular: Node<vec3>}, * backdrop: Node<vec3>, * backdropAlpha: Node<float> * }} The lighting context object. */ getContext() { const { backdropNode, backdropAlphaNode } = this; const directDiffuse = (0, _TSLBase.vec3)().toVar('directDiffuse'), directSpecular = (0, _TSLBase.vec3)().toVar('directSpecular'), indirectDiffuse = (0, _TSLBase.vec3)().toVar('indirectDiffuse'), indirectSpecular = (0, _TSLBase.vec3)().toVar('indirectSpecular'); const reflectedLight = { directDiffuse, directSpecular, indirectDiffuse, indirectSpecular }; const context = { radiance: (0, _TSLBase.vec3)().toVar('radiance'), irradiance: (0, _TSLBase.vec3)().toVar('irradiance'), iblIrradiance: (0, _TSLBase.vec3)().toVar('iblIrradiance'), ambientOcclusion: (0, _TSLBase.float)(1).toVar('ambientOcclusion'), reflectedLight, backdrop: backdropNode, backdropAlpha: backdropAlphaNode }; return context; } setup(builder) { this.value = this._value || (this._value = this.getContext()); this.value.lightingModel = this.lightingModel || builder.context.lightingModel; return super.setup(builder); } } var _default = exports.default = LightingContextNode; const lightingContext = exports.lightingContext = /*@__PURE__*/(0, _TSLBase.nodeProxy)(LightingContextNode);