@openhps/core
Version:
Open Hybrid Positioning System - Core component
114 lines (104 loc) • 3.65 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.renderOutput = exports.default = void 0;
var _TempNode = _interopRequireDefault(require("../core/TempNode.js"));
var _TSLCore = require("../tsl/TSLCore.js");
var _constants = require("../../constants.js");
var _ColorManagement = require("../../math/ColorManagement.js");
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
/**
* Normally, tone mapping and color conversion happens automatically
* before outputting pixel too the default (screen) framebuffer. In certain
* post processing setups this happens to late because certain effects
* require e.g. sRGB input. For such scenarios, `RenderOutputNode` can be used
* to apply tone mapping and color space conversion at an arbitrary point
* in the effect chain.
*
* When applying tone mapping and color space conversion manually with this node,
* you have to set {@link PostProcessing#outputColorTransform} to `false`.
*
* ```js
* const postProcessing = new PostProcessing( renderer );
* postProcessing.outputColorTransform = false;
*
* const scenePass = pass( scene, camera );
* const outputPass = renderOutput( scenePass );
*
* postProcessing.outputNode = outputPass;
* ```
*
* @augments TempNode
*/
class RenderOutputNode extends _TempNode.default {
static get type() {
return 'RenderOutputNode';
}
/**
* Constructs a new render output node.
*
* @param {Node} colorNode - The color node to process.
* @param {?number} toneMapping - The tone mapping type.
* @param {?string} outputColorSpace - The output color space.
*/
constructor(colorNode, toneMapping, outputColorSpace) {
super('vec4');
/**
* The color node to process.
*
* @type {Node}
*/
this.colorNode = colorNode;
/**
* The tone mapping type.
*
* @type {?number}
*/
this.toneMapping = toneMapping;
/**
* The output color space.
*
* @type {?string}
*/
this.outputColorSpace = outputColorSpace;
/**
* This flag can be used for type testing.
*
* @type {boolean}
* @readonly
* @default true
*/
this.isRenderOutputNode = true;
}
setup({
context
}) {
let outputNode = this.colorNode || context.color;
// tone mapping
const toneMapping = (this.toneMapping !== null ? this.toneMapping : context.toneMapping) || _constants.NoToneMapping;
const outputColorSpace = (this.outputColorSpace !== null ? this.outputColorSpace : context.outputColorSpace) || _constants.NoColorSpace;
if (toneMapping !== _constants.NoToneMapping) {
outputNode = outputNode.toneMapping(toneMapping);
}
// working to output color space
if (outputColorSpace !== _constants.NoColorSpace && outputColorSpace !== _ColorManagement.ColorManagement.workingColorSpace) {
outputNode = outputNode.workingToColorSpace(outputColorSpace);
}
return outputNode;
}
}
var _default = exports.default = RenderOutputNode;
/**
* TSL function for creating a posterize node.
*
* @tsl
* @function
* @param {Node} color - The color node to process.
* @param {?number} [toneMapping=null] - The tone mapping type.
* @param {?string} [outputColorSpace=null] - The output color space.
* @returns {RenderOutputNode}
*/
const renderOutput = (color, toneMapping = null, outputColorSpace = null) => (0, _TSLCore.nodeObject)(new RenderOutputNode((0, _TSLCore.nodeObject)(color), toneMapping, outputColorSpace));
exports.renderOutput = renderOutput;
(0, _TSLCore.addMethodChaining)('renderOutput', renderOutput);