(function (global, factory) { if (typeof define === "function" && define.amd) { define(["exports", "../core/Node.js", "../ShaderNode.js", "three"], factory); } else if (typeof exports !== "undefined") { factory(exports, require("../core/Node.js"), require("../ShaderNode.js"), require("three")); } else { var mod = { exports: {} }; factory(mod.exports, global.Node, global.ShaderNode, global.three); global.ColorSpaceNode = mod.exports; } })(typeof globalThis !== "undefined" ? globalThis : typeof self !== "undefined" ? self : this, function (_exports, _Node, _ShaderNode, _three) { "use strict"; Object.defineProperty(_exports, "__esModule", { value: true }); _exports.sRGBToLinear = _exports.default = _exports.LinearToLinear = void 0; _Node = _interopRequireDefault(_Node); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } 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 _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); } function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } var LinearToLinear = new _ShaderNode.ShaderNode(function (inputs) { return inputs.value; }); _exports.LinearToLinear = LinearToLinear; var sRGBToLinear = new _ShaderNode.ShaderNode(function (inputs) { var value = inputs.value; var rgb = value.rgb; var a = (0, _ShaderNode.pow)((0, _ShaderNode.add)((0, _ShaderNode.mul)(rgb, 0.9478672986), (0, _ShaderNode.vec3)(0.0521327014)), (0, _ShaderNode.vec3)(2.4)); var b = (0, _ShaderNode.mul)(rgb, 0.0773993808); var factor = (0, _ShaderNode.vec3)((0, _ShaderNode.lessThanEqual)(rgb, (0, _ShaderNode.vec3)(0.04045))); var rgbResult = (0, _ShaderNode.mix)(a, b, factor); return (0, _ShaderNode.join)(rgbResult.r, rgbResult.g, rgbResult.b, value.a); }); _exports.sRGBToLinear = sRGBToLinear; var EncodingLib = { LinearToLinear: LinearToLinear, sRGBToLinear: sRGBToLinear }; function getEncodingComponents(encoding) { switch (encoding) { case _three.LinearEncoding: return ['Linear']; case _three.sRGBEncoding: return ['sRGB']; /* case RGBEEncoding: return [ 'RGBE' ]; case RGBM7Encoding: return [ 'RGBM', new FloatNode( 7.0 ).setConst( true ) ]; case RGBM16Encoding: return [ 'RGBM', new FloatNode( 16.0 ).setConst( true ) ]; case RGBDEncoding: return [ 'RGBD', new FloatNode( 256.0 ).setConst( true ) ]; case GammaEncoding: return [ 'Gamma', new CodeNode( 'float( GAMMA_FACTOR )' ) ]; */ } } var ColorSpaceNode = /*#__PURE__*/function (_TempNode) { _inherits(ColorSpaceNode, _TempNode); var _super = _createSuper(ColorSpaceNode); /* static GAMMA_TO_LINEAR = 'GammaToLinear'; static LINEAR_TO_GAMMA = 'LinearToGamma'; static RGBE_TO_LINEAR = 'RGBEToLinear'; static LINEAR_TO_RGBE = 'LinearToRGBE'; static RGBM_TO_LINEAR = 'RGBMToLinear'; static LINEAR_TO_RGBM = 'LinearToRGBM'; static RGBD_TO_LINEAR = 'RGBDToLinear'; static LINEAR_TO_RGBD = 'LinearToRGBD'; */ function ColorSpaceNode(method, node) { var _this; _classCallCheck(this, ColorSpaceNode); _this = _super.call(this, 'vec4'); _this.method = method; _this.node = node; _this.factor = null; return _this; } _createClass(ColorSpaceNode, [{ key: "fromEncoding", value: function fromEncoding(encoding) { var components = getEncodingComponents(encoding); this.method = 'LinearTo' + components[0]; this.factor = components[1]; return this; } }, { key: "fromDecoding", value: function fromDecoding(encoding) { var components = getEncodingComponents(encoding); this.method = components[0] + 'ToLinear'; this.factor = components[1]; return this; } }, { key: "generate", value: function generate(builder) { var type = this.getNodeType(builder); var method = this.method; var node = this.node; if (method !== ColorSpaceNode.LINEAR_TO_LINEAR) { var encodingFunctionNode = EncodingLib[method]; var factor = this.factor; return encodingFunctionNode({ value: node, factor: factor }).build(builder, type); } else { return node.build(builder, type); } } }]); return ColorSpaceNode; }(_Node.default); _defineProperty(ColorSpaceNode, "LINEAR_TO_LINEAR", 'LinearToLinear'); _defineProperty(ColorSpaceNode, "SRGB_TO_LINEAR", 'sRGBToLinear'); _defineProperty(ColorSpaceNode, "LINEAR_TO_SRGB", 'LinearTosRGB'); var _default = ColorSpaceNode; _exports.default = _default; });