@openhps/core
Version:
Open Hybrid Positioning System - Core component
80 lines (74 loc) • 2.38 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
var _AnalyticLightNode = _interopRequireDefault(require("./AnalyticLightNode.js"));
var _UniformNode = require("../core/UniformNode.js");
var _MathNode = require("../math/MathNode.js");
var _Normal = require("../accessors/Normal.js");
var _Lights = require("../accessors/Lights.js");
var _UniformGroupNode = require("../core/UniformGroupNode.js");
var _Color = require("../../math/Color.js");
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
/**
* Module for representing hemisphere lights as nodes.
*
* @augments AnalyticLightNode
*/
class HemisphereLightNode extends _AnalyticLightNode.default {
static get type() {
return 'HemisphereLightNode';
}
/**
* Constructs a new hemisphere light node.
*
* @param {?HemisphereLight} [light=null] - The hemisphere light source.
*/
constructor(light = null) {
super(light);
/**
* Uniform node representing the light's position.
*
* @type {UniformNode<vec3>}
*/
this.lightPositionNode = (0, _Lights.lightPosition)(light);
/**
* A node representing the light's direction.
*
* @type {Node<vec3>}
*/
this.lightDirectionNode = this.lightPositionNode.normalize();
/**
* Uniform node representing the light's ground color.
*
* @type {UniformNode<vec3>}
*/
this.groundColorNode = (0, _UniformNode.uniform)(new _Color.Color()).setGroup(_UniformGroupNode.renderGroup);
}
/**
* Overwritten to updated hemisphere light specific uniforms.
*
* @param {NodeFrame} frame - A reference to the current node frame.
*/
update(frame) {
const {
light
} = this;
super.update(frame);
this.lightPositionNode.object3d = light;
this.groundColorNode.value.copy(light.groundColor).multiplyScalar(light.intensity);
}
setup(builder) {
const {
colorNode,
groundColorNode,
lightDirectionNode
} = this;
const dotNL = _Normal.normalView.dot(lightDirectionNode);
const hemiDiffuseWeight = dotNL.mul(0.5).add(0.5);
const irradiance = (0, _MathNode.mix)(groundColorNode, colorNode, hemiDiffuseWeight);
builder.context.irradiance.addAssign(irradiance);
}
}
var _default = exports.default = HemisphereLightNode;