@openhps/core
Version:
Open Hybrid Positioning System - Core component
102 lines (95 loc) • 3.31 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.toneMappingExposure = exports.toneMapping = exports.default = void 0;
var _TempNode = _interopRequireDefault(require("../core/TempNode.js"));
var _TSLCore = require("../tsl/TSLCore.js");
var _RendererReferenceNode = require("../accessors/RendererReferenceNode.js");
var _constants = require("../../constants.js");
var _NodeUtils = require("../core/NodeUtils.js");
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
/**
* This node represents a tone mapping operation.
*
* @augments TempNode
*/
class ToneMappingNode extends _TempNode.default {
static get type() {
return 'ToneMappingNode';
}
/**
* Constructs a new tone mapping node.
*
* @param {number} toneMapping - The tone mapping type.
* @param {Node} exposureNode - The tone mapping exposure.
* @param {Node} [colorNode=null] - The color node to process.
*/
constructor(toneMapping, exposureNode = toneMappingExposure, colorNode = null) {
super('vec3');
/**
* The tone mapping type.
*
* @type {number}
*/
this.toneMapping = toneMapping;
/**
* The tone mapping exposure.
*
* @type {Node}
* @default null
*/
this.exposureNode = exposureNode;
/**
* Represents the color to process.
*
* @type {?Node}
* @default null
*/
this.colorNode = colorNode;
}
/**
* Overwrites the default `customCacheKey()` implementation by including the tone
* mapping type into the cache key.
*
* @return {number} The hash.
*/
customCacheKey() {
return (0, _NodeUtils.hash)(this.toneMapping);
}
setup(builder) {
const colorNode = this.colorNode || builder.context.color;
const toneMapping = this.toneMapping;
if (toneMapping === _constants.NoToneMapping) return colorNode;
let outputNode = null;
const toneMappingFn = builder.renderer.library.getToneMappingFunction(toneMapping);
if (toneMappingFn !== null) {
outputNode = (0, _TSLCore.vec4)(toneMappingFn(colorNode.rgb, this.exposureNode), colorNode.a);
} else {
console.error('ToneMappingNode: Unsupported Tone Mapping configuration.', toneMapping);
outputNode = colorNode;
}
return outputNode;
}
}
var _default = exports.default = ToneMappingNode;
/**
* TSL function for creating a tone mapping node.
*
* @tsl
* @function
* @param {number} mapping - The tone mapping type.
* @param {Node<float> | number} exposure - The tone mapping exposure.
* @param {Node<vec3> | Color} color - The color node to process.
* @returns {ToneMappingNode<vec3>}
*/
const toneMapping = (mapping, exposure, color) => (0, _TSLCore.nodeObject)(new ToneMappingNode(mapping, (0, _TSLCore.nodeObject)(exposure), (0, _TSLCore.nodeObject)(color)));
/**
* TSL object that represents the global tone mapping exposure of the renderer.
*
* @tsl
* @type {RendererReferenceNode<vec3>}
*/
exports.toneMapping = toneMapping;
const toneMappingExposure = exports.toneMappingExposure = /*@__PURE__*/(0, _RendererReferenceNode.rendererReference)('toneMappingExposure', 'float');
(0, _TSLCore.addMethodChaining)('toneMapping', (color, mapping, exposure) => toneMapping(mapping, exposure, color));