(function (global, factory) { if (typeof define === "function" && define.amd) { define(["exports", "three", "../core/TempNode.js", "../inputs/FloatNode.js", "../core/FunctionNode.js", "../core/ExpressionNode.js"], factory); } else if (typeof exports !== "undefined") { factory(exports, require("three"), require("../core/TempNode.js"), require("../inputs/FloatNode.js"), require("../core/FunctionNode.js"), require("../core/ExpressionNode.js")); } else { var mod = { exports: {} }; factory(mod.exports, global.three, global.TempNode, global.FloatNode, global.FunctionNode, global.ExpressionNode); global.ColorSpaceNode = mod.exports; } })(typeof globalThis !== "undefined" ? globalThis : typeof self !== "undefined" ? self : this, function (_exports, _three, _TempNode2, _FloatNode, _FunctionNode, _ExpressionNode) { "use strict"; Object.defineProperty(_exports, "__esModule", { value: true }); _exports.ColorSpaceNode = void 0; function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; } function _get() { if (typeof Reflect !== "undefined" && Reflect.get) { _get = Reflect.get; } else { _get = function _get(target, property, receiver) { var base = _superPropBase(target, property); if (!base) return; var desc = Object.getOwnPropertyDescriptor(base, property); if (desc.get) { return desc.get.call(arguments.length < 3 ? target : receiver); } return desc.value; }; } return _get.apply(this, arguments); } function _superPropBase(object, property) { while (!Object.prototype.hasOwnProperty.call(object, property)) { object = _getPrototypeOf(object); if (object === null) break; } return object; } function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } Object.defineProperty(subClass, "prototype", { value: Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }), writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); } function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); } function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; } function _possibleConstructorReturn(self, call) { if (call && (typeof call === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); } function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; } function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } } function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); } var ColorSpaceNode = /*#__PURE__*/function (_TempNode) { _inherits(ColorSpaceNode, _TempNode); var _super = _createSuper(ColorSpaceNode); function ColorSpaceNode(input, method) { var _this; _classCallCheck(this, ColorSpaceNode); _this = _super.call(this, 'v4'); _this.input = input; _this.method = method || ColorSpaceNode.LINEAR_TO_LINEAR; return _this; } _createClass(ColorSpaceNode, [{ key: "generate", value: function generate(builder, output) { var input = this.input.build(builder, 'v4'); var outputType = this.getType(builder); var methodNode = ColorSpaceNode.Nodes[this.method]; var method = builder.include(methodNode); if (method === ColorSpaceNode.LINEAR_TO_LINEAR) { return builder.format(input, outputType, output); } else { if (methodNode.inputs.length === 2) { var factor = this.factor.build(builder, 'f'); return builder.format(method + '( ' + input + ', ' + factor + ' )', outputType, output); } else { return builder.format(method + '( ' + input + ' )', outputType, output); } } } }, { key: "fromEncoding", value: function fromEncoding(encoding) { var components = ColorSpaceNode.getEncodingComponents(encoding); this.method = 'LinearTo' + components[0]; this.factor = components[1]; } }, { key: "fromDecoding", value: function fromDecoding(encoding) { var components = ColorSpaceNode.getEncodingComponents(encoding); this.method = components[0] + 'ToLinear'; this.factor = components[1]; } }, { key: "copy", value: function copy(source) { _get(_getPrototypeOf(ColorSpaceNode.prototype), "copy", this).call(this, source); this.input = source.input; this.method = source.method; return this; } }, { key: "toJSON", value: function toJSON(meta) { var data = this.getJSONNode(meta); if (!data) { data = this.createJSONNode(meta); data.input = this.input.toJSON(meta).uuid; data.method = this.method; } return data; } }]); return ColorSpaceNode; }(_TempNode2.TempNode); _exports.ColorSpaceNode = ColorSpaceNode; ColorSpaceNode.Nodes = function () { // For a discussion of what this is, please read this: http://lousodrome.net/blog/light/2013/05/26/gamma-correct-and-hdr-rendering-in-a-32-bits-buffer/ var LinearToLinear = new _FunctionNode.FunctionNode( /* glsl */ "\n\t\tvec4 LinearToLinear( in vec4 value ) {\n\n\t\t\treturn value;\n\n\t\t}"); var GammaToLinear = new _FunctionNode.FunctionNode( /* glsl */ "\n\t\tvec4 GammaToLinear( in vec4 value, in float gammaFactor ) {\n\n\t\t\treturn vec4( pow( value.xyz, vec3( gammaFactor ) ), value.w );\n\n\t\t}"); var LinearToGamma = new _FunctionNode.FunctionNode( /* glsl */ "\n\t\tvec4 LinearToGamma( in vec4 value, in float gammaFactor ) {\n\n\t\t\treturn vec4( pow( value.xyz, vec3( 1.0 / gammaFactor ) ), value.w );\n\n\t\t}"); var sRGBToLinear = new _FunctionNode.FunctionNode( /* glsl */ "\n\t\tvec4 sRGBToLinear( in vec4 value ) {\n\n\t\t\treturn vec4( mix( pow( value.rgb * 0.9478672986 + vec3( 0.0521327014 ), vec3( 2.4 ) ), value.rgb * 0.0773993808, vec3( lessThanEqual( value.rgb, vec3( 0.04045 ) ) ) ), value.w );\n\n\t\t}"); var LinearTosRGB = new _FunctionNode.FunctionNode( /* glsl */ "\n\t\tvec4 LinearTosRGB( in vec4 value ) {\n\n\t\t\treturn vec4( mix( pow( value.rgb, vec3( 0.41666 ) ) * 1.055 - vec3( 0.055 ), value.rgb * 12.92, vec3( lessThanEqual( value.rgb, vec3( 0.0031308 ) ) ) ), value.w );\n\n\t\t}"); var RGBEToLinear = new _FunctionNode.FunctionNode( /* glsl */ "\n\t\tvec4 RGBEToLinear( in vec4 value ) {\n\n\t\t\treturn vec4( value.rgb * exp2( value.a * 255.0 - 128.0 ), 1.0 );\n\n\t\t}"); var LinearToRGBE = new _FunctionNode.FunctionNode( /* glsl */ "\n\t\tvec4 LinearToRGBE( in vec4 value ) {\n\n\t\t\tfloat maxComponent = max( max( value.r, value.g ), value.b );\n\t\t\tfloat fExp = clamp( ceil( log2( maxComponent ) ), -128.0, 127.0 );\n\t\t\treturn vec4( value.rgb / exp2( fExp ), ( fExp + 128.0 ) / 255.0 );\n\n\t\t}"); // reference: http://iwasbeingirony.blogspot.ca/2010/06/difference-between-rgbm-and-rgbd.html var RGBMToLinear = new _FunctionNode.FunctionNode( /* glsl */ "\n\t\tvec3 RGBMToLinear( in vec4 value, in float maxRange ) {\n\n\t\t\treturn vec4( value.xyz * value.w * maxRange, 1.0 );\n\n\t\t}"); var LinearToRGBM = new _FunctionNode.FunctionNode( /* glsl */ "\n\t\tvec3 LinearToRGBM( in vec4 value, in float maxRange ) {\n\n\t\t\tfloat maxRGB = max( value.x, max( value.g, value.b ) );\n\t\t\tfloat M = clamp( maxRGB / maxRange, 0.0, 1.0 );\n\t\t\tM = ceil( M * 255.0 ) / 255.0;\n\t\t\treturn vec4( value.rgb / ( M * maxRange ), M );\n\n\t\t}"); // reference: http://iwasbeingirony.blogspot.ca/2010/06/difference-between-rgbm-and-rgbd.html var RGBDToLinear = new _FunctionNode.FunctionNode( /* glsl */ "\n\t\tvec3 RGBDToLinear( in vec4 value, in float maxRange ) {\n\n\t\t\treturn vec4( value.rgb * ( ( maxRange / 255.0 ) / value.a ), 1.0 );\n\n\t\t}"); var LinearToRGBD = new _FunctionNode.FunctionNode( /* glsl */ "\n\t\tvec3 LinearToRGBD( in vec4 value, in float maxRange ) {\n\n\t\t\tfloat maxRGB = max( value.x, max( value.g, value.b ) );\n\t\t\tfloat D = max( maxRange / maxRGB, 1.0 );\n\t\t\tD = clamp( floor( D ) / 255.0, 0.0, 1.0 );\n\t\t\treturn vec4( value.rgb * ( D * ( 255.0 / maxRange ) ), D );\n\n\t\t}"); return { LinearToLinear: LinearToLinear, GammaToLinear: GammaToLinear, LinearToGamma: LinearToGamma, sRGBToLinear: sRGBToLinear, LinearTosRGB: LinearTosRGB, RGBEToLinear: RGBEToLinear, LinearToRGBE: LinearToRGBE, RGBMToLinear: RGBMToLinear, LinearToRGBM: LinearToRGBM, RGBDToLinear: RGBDToLinear, LinearToRGBD: LinearToRGBD }; }(); ColorSpaceNode.LINEAR_TO_LINEAR = 'LinearToLinear'; ColorSpaceNode.GAMMA_TO_LINEAR = 'GammaToLinear'; ColorSpaceNode.LINEAR_TO_GAMMA = 'LinearToGamma'; ColorSpaceNode.SRGB_TO_LINEAR = 'sRGBToLinear'; ColorSpaceNode.LINEAR_TO_SRGB = 'LinearTosRGB'; ColorSpaceNode.RGBE_TO_LINEAR = 'RGBEToLinear'; ColorSpaceNode.LINEAR_TO_RGBE = 'LinearToRGBE'; ColorSpaceNode.RGBM_TO_LINEAR = 'RGBMToLinear'; ColorSpaceNode.LINEAR_TO_RGBM = 'LinearToRGBM'; ColorSpaceNode.RGBD_TO_LINEAR = 'RGBDToLinear'; ColorSpaceNode.LINEAR_TO_RGBD = 'LinearToRGBD'; ColorSpaceNode.getEncodingComponents = function (encoding) { switch (encoding) { case _three.LinearEncoding: return ['Linear']; case _three.sRGBEncoding: return ['sRGB']; case _three.RGBEEncoding: return ['RGBE']; case _three.RGBM7Encoding: return ['RGBM', new _FloatNode.FloatNode(7.0).setReadonly(true)]; case _three.RGBM16Encoding: return ['RGBM', new _FloatNode.FloatNode(16.0).setReadonly(true)]; case _three.RGBDEncoding: return ['RGBD', new _FloatNode.FloatNode(256.0).setReadonly(true)]; case _three.GammaEncoding: return ['Gamma', new _ExpressionNode.ExpressionNode('float( GAMMA_FACTOR )', 'f')]; } }; ColorSpaceNode.prototype.nodeType = 'ColorSpace'; ColorSpaceNode.prototype.hashProperties = ['method']; });