Advertisement
Guest User

Untitled

a guest
Nov 10th, 2020
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #version 450
  2.  
  3. layout(push_constant) uniform Push
  4. {
  5.     float g_gamma_in;
  6.     float g_signal_type;
  7.     float g_gamma_type;
  8.     float g_crtgamut;
  9.     float g_space_out;
  10.     float g_hue_degrees;
  11.     float g_I_SHIFT;
  12.     float g_Q_SHIFT;
  13.     float g_I_MUL;
  14.     float g_Q_MUL;
  15.     float g_lum_fix;
  16.     float g_vignette;
  17.     float g_vstr;
  18.     float g_vpower;
  19.     float g_sat;
  20.     float g_vibr;
  21.     float g_lum;
  22.     float g_cntrst;
  23.     float g_mid;
  24.     float g_lift;
  25.     float blr;
  26.     float blg;
  27.     float blb;
  28.     float wlr;
  29.     float wlg;
  30.     float wlb;
  31.     float rg;
  32.     float rb;
  33.     float gr;
  34.     float gb;
  35.     float br;
  36.     float bg;
  37. } params;
  38.  
  39. layout(std140, set = 0, binding = 0) uniform UBO
  40. {
  41.     mat4 MVP;
  42.     vec4 SourceSize;
  43.     vec4 OriginalSize;
  44.     vec4 OutputSize;
  45.     uint FrameCount;
  46.     float wp_temperature;
  47.     float g_gamma_out;
  48.     float g_satr;
  49.     float g_satg;
  50.     float g_satb;
  51.     float LUT_Size1;
  52.     float LUT1_toggle;
  53.     float LUT_Size2;
  54.     float LUT2_toggle;
  55. } global;
  56.  
  57. /*
  58.    Grade
  59.    > Ubershader grouping some monolithic color related shaders:
  60.     ::color-mangler (hunterk), ntsc color tuning knobs (Doriphor), white_point (hunterk, Dogway), RA Reshade LUT.
  61.    > and the addition of:
  62.     ::analogue color emulation, phosphor gamut, color space + TRC support, vibrance, HUE vs SAT, vignette (shared by Syh), black level, rolled gain and sigmoidal contrast.
  63.  
  64.    Author: Dogway
  65.    License: Public domain
  66.  
  67.    **Thanks to those that helped me out keep motivated by continuous feedback and bug reports:
  68.    **Syh, Nesguy, hunterk, and the libretro forum members.
  69.  
  70.  
  71.     ######################################...PRESETS...#######################################
  72.     ##########################################################################################
  73.     ###                                                                                    ###
  74.     ###    PAL                                                                             ###
  75.     ###        Phosphor: EBU (#3)            (or an EBU T3213 based CRT phosphor gamut)    ###
  76.     ###        WP: D65 (6489K)               (in practice more like ~7500K)                ###
  77.     ###        TRC: 2.8 SMPTE-C Gamma                                                      ###
  78.     ###        Saturation: -0.02                                                           ###
  79.     ###                                                                                    ###
  80.     ###    NTSC-U                                                                          ###
  81.     ###        Phosphor: P22/SMPTE-C (#1 #-1)(or a SMPTE-C based CRT phosphor gamut)       ###
  82.     ###        WP: D65 (6504K)               (in practice more like ~7500K)                ###
  83.     ###        TRC: 2.22 SMPTE-C Gamma       (in practice more like 2.35-2.55)             ###
  84.     ###                                                                                    ###
  85.     ###    NTSC-J (Default)                                                                ###
  86.     ###        Phosphor: NTSC-J (#2)         (or a NTSC-J based CRT phosphor gamut)        ###
  87.     ###        WP: 9300K+27MPCD (8942K)      (CCT from x:0.281 y:0.311)                    ###
  88.     ###        TRC: 2.22 SMPTE-C Gamma       (in practice more like 2.35-2.55)             ###
  89.     ###                                                                                    ###
  90.     ###    *Despite the standard of 2.22, a more faithful approximation to CRT...          ###
  91.     ###     ...is to use a gamma (SMPTE-C type) with a value of 2.35-2.55.                 ###
  92.     ###                                                                                    ###
  93.     ###                                                                                    ###
  94.     ##########################################################################################
  95.     ##########################################################################################
  96. */
  97.  
  98.  
  99. #pragma parameter g_gamma_in     "Signal Gamma"                                            2.50 1.80 3.0 0.05
  100. #pragma parameter g_gamma_out    "CRT Gamma"                                               2.50 1.80 3.0 0.05
  101. #pragma parameter g_signal_type  "Signal Type (0:RGB 1:Composite)"                         1.0 0.0 1.0 1.0
  102. #pragma parameter g_gamma_type   "Signal Gamma Type (0:sRGB 1:SMPTE-C)"                    1.0 0.0 1.0 1.0
  103. #pragma parameter g_crtgamut     "Phosphor (1:NTSC-U 2:NTSC-J 3:PAL)"                      2.0 -4.0 3.0 1.0
  104. #pragma parameter g_space_out    "Diplay Color Space (-1:709 0:sRGB 1:DCI 2:2020 3:Adobe)" 0.0 -1.0 3.0 1.0
  105.  
  106. #pragma parameter g_hue_degrees  "Hue"                  0.0 -360.0 360.0 1.0
  107. #pragma parameter g_I_SHIFT      "I/U Shift"            0.0 -0.2 0.2 0.01
  108. #pragma parameter g_Q_SHIFT      "Q/V Shift"            0.0 -0.2 0.2 0.01
  109. #pragma parameter g_I_MUL        "I/U Multiplier"       1.0  0.0 2.0 0.01
  110. #pragma parameter g_Q_MUL        "Q/V Multiplier"       1.0  0.0 2.0 0.01
  111. #pragma parameter g_lum_fix      "Sega Luma Fix"        0.0  0.0 1.0 1.0
  112. #pragma parameter g_vignette     "Vignette Toggle"      1.0  0.0 1.0 1.0
  113. #pragma parameter g_vstr         "Vignette Strength"    40.0 0.0 50.0 1.0
  114. #pragma parameter g_vpower       "Vignette Power"       0.20 0.0 0.5 0.01
  115. #pragma parameter g_lum          "Brightness"           0.0 -0.5 1.0 0.01
  116. #pragma parameter g_cntrst       "Contrast"             0.0 -1.0 1.0 0.05
  117. #pragma parameter g_mid          "Contrast Pivot"       0.5  0.0 1.0 0.01
  118. #pragma parameter wp_temperature "White Point"          6504.0 5004.0 12004.0 100.0
  119. #pragma parameter g_sat          "Saturation"           0.0 -1.0 2.0 0.01
  120. #pragma parameter g_vibr         "Dullness/Vibrance"    0.0 -1.0 1.0 0.05
  121. #pragma parameter g_satr         "Hue vs Sat Red"       0.0 -1.0 1.0 0.01
  122. #pragma parameter g_satg         "Hue vs Sat Green"     0.0 -1.0 1.0 0.01
  123. #pragma parameter g_satb         "Hue vs Sat Blue"      0.0 -1.0 1.0 0.01
  124. #pragma parameter g_lift         "Black Level"          0.0 -0.5 0.5 0.01
  125. #pragma parameter blr            "Black-Red Tint"       0.0  0.0 1.0 0.01
  126. #pragma parameter blg            "Black-Green Tint"     0.0  0.0 1.0 0.01
  127. #pragma parameter blb            "Black-Blue Tint"      0.0  0.0 1.0 0.01
  128. #pragma parameter wlr            "White-Red Tint"       1.0  0.0 2.0 0.01
  129. #pragma parameter wlg            "White-Green Tint"     1.0  0.0 2.0 0.01
  130. #pragma parameter wlb            "White-Blue Tint"      1.0  0.0 2.0 0.01
  131. #pragma parameter rg             "Red-Green Tint"       0.0 -1.0 1.0 0.005
  132. #pragma parameter rb             "Red-Blue Tint"        0.0 -1.0 1.0 0.005
  133. #pragma parameter gr             "Green-Red Tint"       0.0 -1.0 1.0 0.005
  134. #pragma parameter gb             "Green-Blue Tint"      0.0 -1.0 1.0 0.005
  135. #pragma parameter br             "Blue-Red Tint"        0.0 -1.0 1.0 0.005
  136. #pragma parameter bg             "Blue-Green Tint"      0.0 -1.0 1.0 0.005
  137. #pragma parameter LUT_Size1      "LUT Size 1"           16.0 8.0 64.0 16.0
  138. #pragma parameter LUT1_toggle    "LUT 1 Toggle"         0.0  0.0 1.0 1.0
  139. #pragma parameter LUT_Size2      "LUT Size 2"           64.0 0.0 64.0 16.0
  140. #pragma parameter LUT2_toggle    "LUT 2 Toggle"         0.0  0.0 1.0 1.0
  141.  
  142. #define M_PI            3.1415926535897932384626433832795
  143. #define gamma_in        params.g_gamma_in
  144. #define gamma_out       global.g_gamma_out
  145. #define signal          params.g_signal_type
  146. #define gamma_type      params.g_gamma_type
  147. #define crtgamut        params.g_crtgamut
  148. #define SPC             params.g_space_out
  149. #define hue_degrees     params.g_hue_degrees
  150. #define I_SHIFT         params.g_I_SHIFT
  151. #define Q_SHIFT         params.g_Q_SHIFT
  152. #define I_MUL           params.g_I_MUL
  153. #define Q_MUL           params.g_Q_MUL
  154. #define lum_fix         params.g_lum_fix
  155. #define vignette        params.g_vignette
  156. #define vstr            params.g_vstr
  157. #define vpower          params.g_vpower
  158. #define g_sat           params.g_sat
  159. #define vibr            params.g_vibr
  160. #define satr            global.g_satr
  161. #define satg            global.g_satg
  162. #define satb            global.g_satb
  163. #define lum             params.g_lum
  164. #define cntrst          params.g_cntrst
  165. #define mid             params.g_mid
  166. #define lift            params.g_lift
  167. #define blr             params.blr
  168. #define blg             params.blg
  169. #define blb             params.blb
  170. #define wlr             params.wlr
  171. #define wlg             params.wlg
  172. #define wlb             params.wlb
  173. #define rg              params.rg
  174. #define rb              params.rb
  175. #define gr              params.gr
  176. #define gb              params.gb
  177. #define br              params.br
  178. #define bg              params.bg
  179.  
  180. #pragma stage vertex
  181. layout(location = 0) in vec4 Position;
  182. layout(location = 1) in vec2 TexCoord;
  183. layout(location = 0) out vec2 vTexCoord;
  184.  
  185. void main()
  186. {
  187.     gl_Position = global.MVP * Position;
  188.     vTexCoord = TexCoord;
  189. }
  190.  
  191. #pragma stage fragment
  192. layout(location = 0) in vec2 vTexCoord;
  193. layout(location = 0) out vec4 FragColor;
  194. layout(set = 0, binding = 2) uniform sampler2D Source;
  195. layout(set = 0, binding = 3) uniform sampler2D SamplerLUT1;
  196. layout(set = 0, binding = 4) uniform sampler2D SamplerLUT2;
  197.  
  198.  
  199. ///////////////////////// Color Space Transformations //////////////////////////
  200.  
  201.  
  202.  
  203. vec3 XYZ_to_RGB(vec3 XYZ, float CSPC){
  204.  
  205.     // to sRGB
  206.     const mat3x3 sRGB = mat3x3(
  207.     3.24081254005432130, -0.969243049621582000,  0.055638398975133896,
  208.    -1.53730857372283940,  1.875966310501098600, -0.204007431864738460,
  209.    -0.49858659505844116,  0.041555050760507584,  1.057129383087158200);
  210.  
  211.     // to DCI-P3 -D65-
  212.     const mat3x3 DCIP3 = mat3x3(
  213.      2.49339652061462400, -0.82948720455169680,  0.035850685089826584,
  214.     -0.93134605884552000,  1.76266026496887200, -0.076182708144187930,
  215.     -0.40269458293914795,  0.023624641820788383, 0.957014024257659900);
  216.  
  217.     // to Rec.2020
  218.     const mat3x3 rec2020 = mat3x3(
  219.      1.71660947799682620, -0.66668272018432620,  0.017642205581068993,
  220.     -0.35566213726997375,  1.61647748947143550, -0.042776308953762054,
  221.     -0.25336012244224550,  0.01576850563287735,  0.942228555679321300);
  222.  
  223.     // from AdobeRGB
  224.     const mat3x3 Adobe = mat3x3(
  225.      2.0415899753570557, -0.96924000978469850,  0.013439999893307686,
  226.     -0.5650100111961365,  1.87597000598907470, -0.118359997868537900,
  227.     -0.3447299897670746,  0.04156000167131424,  1.015169978141784700);
  228.  
  229.    return (CSPC == 3.0) ? Adobe * XYZ : (CSPC == 2.0) ? rec2020 * XYZ : (CSPC == 1.0) ? DCIP3 * XYZ : sRGB * XYZ;
  230. }
  231.  
  232. vec3 RGB_to_XYZ(vec3 RGB, float CSPC){
  233.  
  234.     // from sRGB
  235.     const mat3x3 sRGB = mat3x3(
  236.     0.41241079568862915, 0.21264933049678802, 0.019331756979227066,
  237.     0.35758456587791443, 0.71516913175582890, 0.119194857776165010,
  238.     0.18045382201671600, 0.07218152284622192, 0.950390160083770800);
  239.  
  240.     // from DCI-P3 -D65-
  241.     const mat3x3 DCIP3 = mat3x3(
  242.     0.48659050464630127, 0.22898375988006592, 0.00000000000000000,
  243.     0.26566821336746216, 0.69173991680145260, 0.04511347413063049,
  244.     0.19819043576717377, 0.07927616685628891, 1.04380297660827640);
  245.  
  246.     // from Rec.2020
  247.     const mat3x3 rec2020 = mat3x3(
  248.     0.63697350025177000, 0.24840137362480164, 0.00000000000000000,
  249.     0.15294560790061950, 0.67799961566925050, 0.04253686964511871,
  250.     0.11785808950662613, 0.03913172334432602, 1.06084382534027100);
  251.  
  252.     // from AdobeRGB
  253.     const mat3x3 Adobe = mat3x3(
  254.     0.57666999101638790, 0.2973400056362152, 0.02703000046312809,
  255.     0.18556000292301178, 0.6273599863052368, 0.07068999856710434,
  256.     0.18822999298572540, 0.0752900019288063, 0.9913399815559387);
  257.  
  258.    return (CSPC == 3.0) ? Adobe * RGB : (CSPC == 2.0) ? rec2020 * RGB : (CSPC == 1.0) ? DCIP3 * RGB : sRGB * RGB;
  259. }
  260.  
  261.  
  262. vec3 XYZtoYxy(vec3 XYZ){
  263.  
  264.     float XYZrgb = XYZ.r+XYZ.g+XYZ.b;
  265.     float Yxyg = (XYZrgb <= 0.0) ? 0.3805 : XYZ.r / XYZrgb;
  266.     float Yxyb = (XYZrgb <= 0.0) ? 0.3769 : XYZ.g / XYZrgb;
  267.     return vec3(XYZ.g, Yxyg, Yxyb);
  268. }
  269.  
  270. vec3 YxytoXYZ(vec3 Yxy){
  271.  
  272.     float Xs = Yxy.r * (Yxy.g/Yxy.b);
  273.     float Xsz = (Yxy.r <= 0.0) ? 0.0 : 1.0;
  274.     vec3 XYZ = vec3(Xsz,Xsz,Xsz) * vec3(Xs, Yxy.r, (Xs/Yxy.g)-Xs-Yxy.r);
  275.     return XYZ;
  276. }
  277.  
  278. ///////////////////////// White Point Mapping /////////////////////////
  279. //
  280. //
  281. // PAL: D65      NTSC-U: D65      NTSC-J: CCT NTSC-J NTSC-FCC: C
  282. // PAL: 6489K    NTSC-U: 6504K    NTSC-J: 8942K      NTSC-FCC: 6780K
  283. // 0.313 0.329   0.3127 0.3290    0.281 0.311        0.310, 0.316
  284.  
  285. vec3 wp_adjust(float temperature){
  286.  
  287.     float temp3 = pow(10.,3.) / temperature;
  288.     float temp6 = pow(10.,6.) / pow(temperature, 2.);
  289.     float temp9 = pow(10.,9.) / pow(temperature, 3.);
  290.  
  291.     vec3 wp = vec3(1.);
  292.  
  293.     wp.x = (temperature <= 7000.) ? 0.244063 + 0.09911 * temp3 + 2.9678 * temp6 - 4.6070 * temp9 : \
  294.                                     0.237040 + 0.24748 * temp3 + 1.9018 * temp6 - 2.0064 * temp9 ;
  295.  
  296.     wp.y = -3.000 * pow(wp.x,2.) + 2.870 * wp.x - 0.275;
  297.     wp.z = 1. - wp.x - wp.y;
  298.  
  299.     return wp.xyz;
  300. }
  301.  
  302. ////////////////////////////////////////////////////////////////////////////////
  303.  
  304.  
  305. // Monitor Curve Functions: https://github.com/ampas/aces-dev
  306. //----------------------------------------------------------------------
  307.  
  308.  
  309. float moncurve_f( float color, float gamma, float offs)
  310. {
  311.     // Forward monitor curve
  312.     color = clamp(color, 0.0, 1.0);
  313.     float fs = (( gamma - 1.0) / offs) * pow( offs * gamma / ( ( gamma - 1.0) * ( 1.0 + offs)), gamma);
  314.     float xb = offs / ( gamma - 1.0);
  315.  
  316.     color = ( color > xb) ? pow( ( color + offs) / ( 1.0 + offs), gamma) : color * fs;
  317.     return color;
  318. }
  319.  
  320.  
  321. vec3 moncurve_f_f3( vec3 color, float gamma, float offs)
  322. {
  323.     color.r = moncurve_f( color.r, gamma, offs);
  324.     color.g = moncurve_f( color.g, gamma, offs);
  325.     color.b = moncurve_f( color.b, gamma, offs);
  326.     return color.rgb;
  327. }
  328.  
  329.  
  330. float moncurve_r( float color, float gamma, float offs)
  331. {
  332.     // Reverse monitor curve
  333.     color = clamp(color, 0.0, 1.0);
  334.     float yb = pow( offs * gamma / ( ( gamma - 1.0) * ( 1.0 + offs)), gamma);
  335.     float rs = pow( ( gamma - 1.0) / offs, gamma - 1.0) * pow( ( 1.0 + offs) / gamma, gamma);
  336.  
  337.     color = ( color > yb) ? ( 1.0 + offs) * pow( color, 1.0 / gamma) - offs : color * rs;
  338.     return color;
  339. }
  340.  
  341.  
  342. vec3 moncurve_r_f3( vec3 color, float gamma, float offs)
  343. {
  344.     color.r = moncurve_r( color.r, gamma, offs);
  345.     color.g = moncurve_r( color.g, gamma, offs);
  346.     color.b = moncurve_r( color.b, gamma, offs);
  347.     return color.rgb;
  348. }
  349.  
  350.  
  351. //-------------------------- Luma Functions ----------------------------
  352.  
  353.  
  354. //  Performs better in gamma encoded space
  355. float contrast_sigmoid(float color, float cont, float pivot){
  356.  
  357.     cont = pow(cont + 1., 3.);
  358.  
  359.     float knee = 1. / (1. + exp(cont * pivot));
  360.     float shldr = 1. / (1. + exp(cont * (pivot - 1.)));
  361.  
  362.     color = (1. / (1. + exp(cont * (pivot - color))) - knee) / (shldr - knee);
  363.  
  364.     return color;
  365. }
  366.  
  367.  
  368. //  Performs better in gamma encoded space
  369. float contrast_sigmoid_inv(float color, float cont, float pivot){
  370.  
  371.     cont = pow(cont - 1., 3.);
  372.  
  373.     float knee = 1. / (1. + exp (cont * pivot));
  374.     float shldr = 1. / (1. + exp (cont * (pivot - 1.)));
  375.  
  376.     color = pivot - log(1. / (color * (shldr - knee) + knee) - 1.) / cont;
  377.  
  378.     return color;
  379. }
  380.  
  381.  
  382. float rolled_gain(float color, float gain){
  383.  
  384.     float gx = abs(gain) + 0.001;
  385.     float anch = (gain > 0.0) ? 0.5 / (gx / 2.0) : 0.5 / gx;
  386.     color = (gain > 0.0) ? color * ((color - anch) / (1 - anch)) : color * ((1 - anch) / (color - anch)) * (1 - gain);
  387.  
  388.     return color;
  389. }
  390.  
  391.  
  392. vec4 rolled_gain_v4(vec4 color, float gain){
  393.  
  394.     color.r = rolled_gain(color.r, gain);
  395.     color.g = rolled_gain(color.g, gain);
  396.     color.b = rolled_gain(color.b, gain);
  397.  
  398.     return vec4(color.rgb, 1.0);
  399. }
  400.  
  401.  
  402. float SatMask(float color_r, float color_g, float color_b)
  403. {
  404.     float max_rgb = max(color_r, max(color_g, color_b));
  405.     float min_rgb = min(color_r, min(color_g, color_b));
  406.     float msk = clamp((max_rgb - min_rgb) / (max_rgb + min_rgb), 0.0, 1.0);
  407.     return msk;
  408. }
  409.  
  410.  
  411. //  This shouldn't be necessary but it seems some undefined values can
  412. //  creep in and each GPU vendor handles that differently. This keeps
  413. //  all values within a safe range
  414. vec3 mixfix(vec3 a, vec3 b, float c)
  415. {
  416.     return (a.z < 1.0) ? mix(a, b, c) : a;
  417. }
  418.  
  419.  
  420. vec4 mixfix_v4(vec4 a, vec4 b, float c)
  421. {
  422.     return (a.z < 1.0) ? mix(a, b, c) : a;
  423. }
  424.  
  425.  
  426. //---------------------- Range Expansion/Compression -------------------
  427.  
  428.  
  429. //  to Studio Swing/Broadcast Safe/SMPTE legal/Limited Range
  430. vec3 PCtoTV(vec3 col, float luma_swing, float Umax, float Vmax, float max_swing, bool rgb_in)
  431. {
  432.    col *= 255.;
  433.    Umax = (max_swing == 1.0) ? Umax * 224. : Umax * 239.;
  434.    Vmax = (max_swing == 1.0) ? Vmax * 224. : Vmax * 239.;
  435.  
  436.    col.x = (luma_swing == 1.0) ? ((col.x * 219.) / 255.) + 16. : col.x;
  437.    col.y = (rgb_in == true) ? ((col.y * 219.) / 255.) + 16. : (((col.y - 128.) * (Umax * 2.)) / 255.) + Umax;
  438.    col.z = (rgb_in == true) ? ((col.z * 219.) / 255.) + 16. : (((col.z - 128.) * (Vmax * 2.)) / 255.) + Vmax;
  439.    return col.xyz / 255.;
  440. }
  441.  
  442.  
  443. //  to Full Swing/Full Range
  444. vec3 TVtoPC(vec3 col, float luma_swing, float Umax, float Vmax, float max_swing, bool rgb_in)
  445. {
  446.    col *= 255.;
  447.    Umax = (max_swing == 1.0) ? Umax * 224. : Umax * 239.;
  448.    Vmax = (max_swing == 1.0) ? Vmax * 224. : Vmax * 239.;
  449.  
  450.    float colx = (luma_swing == 1.0) ? ((col.x - 16.) / 219.) * 255. : col.x;
  451.    float coly = (rgb_in == true) ? ((col.y - 16.) / 219.) * 255. : (((col.y - Umax) / (Umax * 2.)) * 255.) + 128.;
  452.    float colz = (rgb_in == true) ? ((col.z - 16.) / 219.) * 255. : (((col.z - Vmax) / (Vmax * 2.)) * 255.) + 128.;
  453.    return vec3(colx,coly,colz) / 255.;
  454. }
  455.  
  456.  
  457. //*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/
  458.  
  459.  
  460. //--------------------- ITU-R BT.470/601 (M) (1953) --------------------
  461.  
  462.  
  463. //  FCC (Sanctioned) YIQ matrix
  464. vec3 RGB_FCC(vec3 col)
  465.  {
  466.     const mat3 conv_mat = mat3(
  467.     0.299996928307425,  0.590001575542717,  0.110001496149858,
  468.     0.599002392519453, -0.277301256521204, -0.321701135998249,
  469.     0.213001700342824, -0.525101205289350,  0.312099504946526);
  470.  
  471.     return col.rgb * conv_mat;
  472.  }
  473.  
  474. //  FCC (Sanctioned) YIQ matrix (inverse)
  475. vec3 FCC_RGB(vec3 col)
  476.  {
  477.     const mat3 conv_mat = mat3(
  478.     1.0000000,  0.946882217090069,  0.623556581986143,
  479.     1.0000000, -0.274787646298978, -0.635691079187380,
  480.     1.0000000, -1.108545034642030,  1.709006928406470);
  481.  
  482.     return col.rgb * conv_mat;
  483.  }
  484.  
  485.  
  486. //--------------------- SMPTE RP 145 (C), 170M (1987) ------------------
  487.  
  488.  
  489. vec3 RGB_YIQ(vec3 col)
  490.  {
  491.     const mat3 conv_mat = mat3(
  492.     0.2990,  0.5870,  0.1140,
  493.     0.5959, -0.2746, -0.3213,
  494.     0.2115, -0.5227,  0.3112);
  495.  
  496.     return col.rgb * conv_mat;
  497.  }
  498.  
  499. vec3 YIQ_RGB(vec3 col)
  500.  {
  501.     const mat3 conv_mat = mat3(
  502.     1.0000000,  0.956,  0.619,
  503.     1.0000000, -0.272, -0.647,
  504.     1.0000000, -1.106,  1.703);
  505.  
  506.     return col.rgb * conv_mat;
  507.  }
  508.  
  509. //----------------------- ITU-R BT.470/601 (B/G) -----------------------
  510.  
  511.  
  512. vec3 r601_YUV(vec3 RGB)
  513.  {
  514.     const mat3 conv_mat = mat3(
  515.     0.299000,  0.587000,  0.114000,
  516.    -0.147407, -0.289391,  0.436798,
  517.     0.614777, -0.514799, -0.099978);
  518.  
  519.     return RGB.rgb * conv_mat;
  520.  }
  521.  
  522. vec3 YUV_r601(vec3 RGB)
  523.  {
  524.     const mat3 conv_mat = mat3(
  525.     1.0000000,  0.00000000000000000,  1.14025080204010000,
  526.     1.0000000, -0.39393067359924316, -0.58080917596817020,
  527.     1.0000000,  2.02839756011962900, -0.00000029356581166);
  528.  
  529.     return RGB.rgb * conv_mat;
  530.  }
  531.  
  532. //  Custom - not Standard
  533. vec3 YUV_r709(vec3 YUV)
  534.  {
  535.     const mat3 conv_mat = mat3(
  536.     1.0000000,  0.0000000000000000,  1.14025092124938960,
  537.     1.0000000, -0.2047683298587799, -0.33895039558410645,
  538.     1.0000001,  2.0283975601196290,  0.00000024094399364);
  539.  
  540.     return YUV.rgb * conv_mat;
  541.  }
  542.  
  543. //  Custom - not Standard
  544. vec3 r709_YUV(vec3 RGB)
  545.  {
  546.     const mat3 conv_mat = mat3(
  547.     0.2126000,  0.715200,   0.0722000,
  548.    -0.1048118, -0.3525936,  0.4574054,
  549.     0.6905498, -0.6272304, -0.0633194);
  550.  
  551.     return RGB.rgb * conv_mat;
  552.  }
  553.  
  554.  
  555. //------------------------- SMPTE-240M Y’PbPr --------------------------
  556.  
  557.  
  558. //  Umax 0.886
  559. //  Vmax 0.700
  560. //  RGB to YPbPr -full to limited range- with Rec.601 primaries
  561. vec3 r601_YCC(vec3 RGB)
  562.  {
  563.     const mat3 conv_mat = mat3(
  564.     0.299,                   0.587,                   0.114,
  565.    -0.16873589164785553047, -0.33126410835214446953,  0.500,
  566.     0.500,                  -0.41868758915834522111, -0.08131241084165477889);
  567.  
  568.     return RGB.rgb * conv_mat;
  569.  }
  570.  
  571. //  YPbPr to RGB  -limited to full range- with Rec.601 primaries
  572. vec3 YCC_r601(vec3 YUV)
  573.  {
  574.     const mat3 conv_mat = mat3(
  575.     1.0000000,  0.000,                   1.402,
  576.     1.0000000, -0.34413628620102214651, -0.71413628620102214651,
  577.     1.0000000,  1.772,                   0.000);
  578.  
  579.     return YUV.rgb * conv_mat;
  580.  }
  581.  
  582. //  Umax 0.53890924768269023496443198965294
  583. //  Vmax 0.63500127000254000508001016002032
  584. //  RGB to YPbPr -full range in-gamut- with Rec.709 primaries
  585. vec3 r709_YCC(vec3 RGB)
  586.  {
  587.     const mat3 conv_mat = mat3(
  588.     0.2126,                  0.7152,                  0.0722,
  589.    -0.11457210605733994395, -0.38542789394266005605,  0.5000,
  590.     0.5000,                 -0.45415290830581661163, -0.04584709169418338837);
  591.  
  592.     return RGB.rgb * conv_mat;
  593.  }
  594.  
  595. //  YPbPr to RGB -full range in-gamut- with Rec.709 primaries
  596. vec3 YCC_r709(vec3 YUV)
  597.  {
  598.     const mat3 conv_mat = mat3(
  599.     1.0000000,  0.00000000000000000000,  1.5748,
  600.     1.0000000, -0.18732427293064876957, -0.46812427293064876957,
  601.     1.0000000,  1.8556,                  0.00000000000000000000);
  602.  
  603.     return YUV.rgb * conv_mat;
  604.  }
  605.  
  606.  
  607. //------------------------- IPT --------------------------
  608.  
  609.  
  610. const mat3 LMS =
  611. mat3(
  612.  0.4002, 0.7076, -0.0808,
  613. -0.2263, 1.1653,  0.0457,
  614.  0.0,       0.0,  0.9182);
  615.  
  616. const mat3 IPT =
  617. mat3(
  618.  0.4000,  0.4000, 0.2000,
  619.  4.4550, -4.8510, 0.3960,
  620.  0.8056, 0.3572, -1.1628);
  621.  
  622.  
  623.  
  624. //*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/
  625.  
  626.  
  627.  
  628. const mat3 C_D65_Brad =
  629. mat3(
  630.  1.0062731504440308000, 0.0028941007331013680, -0.0070838485844433310,
  631.  0.0036507491022348404, 0.9992200732231140000, -0.0023814644664525986,
  632. -0.0013438384048640728, 0.0022154981270432472,  0.9643852710723877000);
  633.  
  634. const mat3 D93_D65_Brad =
  635. mat3(
  636.  1.074299335479736300, 0.03572637960314751, -0.042645290493965150,
  637.  0.050180613994598390, 0.97543668746948240, -0.015837108716368675,
  638. -0.006000521592795849, 0.00851820595562458,  0.827671706676483200);
  639.  
  640. const mat3 PAL_D65_Brad =
  641. mat3(
  642.  0.99919301271438600000, -0.00044559128582477570, 0.00027090078219771385,
  643. -0.00065565120894461870,  1.00049483776092530000, 0.00011852011084556580,
  644.  1.3149343430995941e-05,  3.4691765904426575e-06, 1.00069344043731700000);
  645.  
  646.  
  647. //----------------------------------------------------------------------
  648.  
  649.  
  650. // ITU-R BT.470/601 (M) (proof of concept, actually never used)
  651. // SMPTE 170M-1999
  652. // NTSC-FCC 1953 Standard Phosphor (use with temperature C: 6780K)
  653. const mat3 NTSC_FCC_transform =
  654. mat3(
  655.  0.60699284076690670, 0.2989666163921356, 0.00000000000000000,
  656.  0.17344850301742554, 0.5864211320877075, 0.06607561558485031,
  657.  0.20057128369808197, 0.1146121546626091, 1.11746847629547120);
  658.  
  659. // ITU-R BT.470/601 (M)
  660. // Conrac 7211N19 CRT Phosphor
  661. const mat3 Conrac_transform =
  662. mat3(
  663.  0.55842006206512450, 0.28580552339553833, 0.03517606481909752,
  664.  0.20613566040992737, 0.63714659214019780, 0.09369802474975586,
  665.  0.18589359521865845, 0.07704800367355347, 0.96004259586334230);
  666.  
  667. // NTSC-J (use with D93 white point)
  668. // Sony Trinitron KV-20M20
  669. const mat3 Sony20_20_transform =
  670. mat3(
  671.  0.33989441394805910, 0.18490256369113922, 0.019034087657928467,
  672.  0.33497872948646545, 0.71182984113693240, 0.149544075131416320,
  673.  0.22866378724575043, 0.10326752066612244, 1.143318891525268600);
  674.  
  675. // SMPTE-C - Measured Average Phosphor (1979-1994)
  676. const mat3 P22_transform =
  677. mat3(
  678.  0.4665636420249939, 0.25661000609397890, 0.005832045804709196,
  679.  0.3039233088493347, 0.66820019483566280, 0.105618737637996670,
  680.  0.1799621731042862, 0.07518967241048813, 0.977465748786926300);
  681.  
  682. // SMPTE RP 145-1994 (SMPTE-C), 170M-1999
  683. // SMPTE-C - Standard Phosphor
  684. const mat3 SMPTE_transform =
  685. mat3(
  686.  0.39354196190834045, 0.21238772571086884, 0.01874009333550930,
  687.  0.36525884270668030, 0.70106136798858640, 0.11193416267633438,
  688.  0.19164848327636720, 0.08655092865228653, 0.95824241638183590);
  689.  
  690. // SMPTE RP 145-1994 (SMPTE-C), 170M-1999
  691. // NTSC-J - Standard Phosphor (use with D93 white point)
  692. const mat3 NTSC_J_transform =
  693. mat3(
  694.  0.39603787660598755, 0.22429330646991730, 0.02050681784749031,
  695.  0.31201449036598206, 0.67417418956756590, 0.12814880907535553,
  696.  0.24496731162071228, 0.10153251141309738, 1.26512730121612550);
  697.  
  698. // ITU-R BT.470/601 (B/G)
  699. // EBU Tech.3213 PAL - Standard Phosphor for Studio Monitors
  700. const mat3 EBU_transform =
  701. mat3(
  702.  0.43194326758384705, 0.22272075712680817, 0.020247340202331543,
  703.  0.34123489260673523, 0.70600330829620360, 0.129433929920196530,
  704.  0.17818950116634370, 0.07127580046653748, 0.938464701175689700);
  705.  
  706.  
  707. //*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/
  708.  
  709.  
  710.  
  711.  
  712.  
  713. void main()
  714. {
  715.  
  716. // Retro Sega Systems: Genesis, 32x, CD and Saturn 2D had color palettes designed in TV levels to save on transformations.
  717.     float lum_exp = (lum_fix ==  1.0) ? (255./239.) : 1.;
  718.  
  719.     vec3 src = texture(Source, vTexCoord.xy).rgb;
  720.     vec3 col = src;
  721.  
  722. // make a YUV * NTSC Phosphor option too and a FCC * NTSC phosphor
  723.     col = (crtgamut ==  3.0) ? r601_YUV(col*lum_exp)   : \
  724.           (crtgamut ==  2.0) ?  RGB_YIQ(col*lum_exp)   : \
  725.           (crtgamut == -3.0) ?  RGB_FCC(col*lum_exp)   : \
  726.           (crtgamut == -4.0) ?  RGB_FCC(col*lum_exp)   : \
  727.                                 RGB_YIQ(col*lum_exp)   ;
  728.  
  729.  
  730. // Clipping Logic / Gamut Limiting
  731.     vec2 UVmax = (crtgamut ==  3.0) ? vec2(0.436798,          0.614777)         : \
  732.                  (crtgamut == -4.0) ? vec2(0.599002392519453, 0.52510120528935) : \
  733.                  (crtgamut == -3.0) ? vec2(0.599002392519453, 0.52510120528935) : \
  734.                                       vec2(0.5959,            0.5227)           ;
  735.  
  736.     col = clamp(col.xyz, vec3(0.0, -UVmax.x, -UVmax.y), vec3(1.0, UVmax.x, UVmax.y));
  737.  
  738.  
  739.     col = (crtgamut ==  3.0) ?        col                                       : \
  740.           (crtgamut ==  2.0) ?        col                                       : \
  741.           (crtgamut == -3.0) ? PCtoTV(col, 1.0, UVmax.x, UVmax.y, 1.0, false)   : \
  742.           (crtgamut == -4.0) ? PCtoTV(col, 1.0, UVmax.x, UVmax.y, 1.0, false)   : \
  743.                                PCtoTV(col, 1.0, UVmax.x, UVmax.y, 1.0, false)   ;
  744.  
  745.  
  746. // YIQ/YUV Analogue Color Controls (HUE + Color Shift + Color Burst)
  747.     float hue_radians = hue_degrees * (M_PI / 180.0);
  748.     float hue = atan(col.z, col.y) + hue_radians;
  749.     float chroma = sqrt(col.z * col.z + col.y * col.y);
  750.     col = vec3(col.x, chroma * cos(hue), chroma * sin(hue));
  751.  
  752.     col.y = (mod((col.y + 1.0) + I_SHIFT, 2.0) - 1.0) * I_MUL;
  753.     col.z = (mod((col.z + 1.0) + Q_SHIFT, 2.0) - 1.0) * Q_MUL;
  754.  
  755.  
  756. // Back to RGB
  757.     col = (crtgamut ==  3.0) ?        col                                       : \
  758.           (crtgamut ==  2.0) ?        col                                       : \
  759.           (crtgamut == -3.0) ? TVtoPC(col, 1.0, UVmax.x, UVmax.y, 1.0, false)   : \
  760.           (crtgamut == -4.0) ? TVtoPC(col, 1.0, UVmax.x, UVmax.y, 1.0, false)   : \
  761.                                TVtoPC(col, 1.0, UVmax.x, UVmax.y, 1.0, false)   ;
  762.  
  763.     col = (crtgamut ==  3.0) ?     YUV_r601(col)    : \
  764.           (crtgamut ==  2.0) ?      YIQ_RGB(col)    : \
  765.           (crtgamut == -3.0) ?      FCC_RGB(col)    : \
  766.           (crtgamut == -4.0) ?      FCC_RGB(col)    : \
  767.                                     YIQ_RGB(col)    ;
  768.  
  769. // Gamut Limiting
  770.     col = r601_YCC(clamp(col, 0.0, 1.0));
  771.     col = (signal == 0.0) ? src : YCC_r601(clamp(col, vec3(0.0, -.886,-.700), vec3(1.0, .886,.700)));
  772.  
  773.  
  774. //_   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _
  775. // \_/ \_/ \_/ \_/ \_/ \_/ \_/ \_/ \_/ \_/ \_/ \_/ \_/ \_/ \_/ \_/ \_/ \_/ \_/ \
  776.  
  777.  
  778. // Look LUT - (in sRGB space)
  779.     float red =   (col.r * (global.LUT_Size1 - 1.0) + 0.4999) / (global.LUT_Size1 * global.LUT_Size1);
  780.     float green = (col.g * (global.LUT_Size1 - 1.0) + 0.4999) /  global.LUT_Size1;
  781.     float blue1 = (floor(col.b * (global.LUT_Size1 - 1.0)) / global.LUT_Size1) + red;
  782.     float blue2 =  (ceil(col.b * (global.LUT_Size1 - 1.0)) / global.LUT_Size1) + red;
  783.     float mixer = clamp(max((col.b - blue1) / (blue2 - blue1), 0.0), 0.0, 32.0);
  784.     vec3 color1 = texture(SamplerLUT1, vec2(blue1, green)).rgb;
  785.     vec3 color2 = texture(SamplerLUT1, vec2(blue2, green)).rgb;
  786.     vec3 vcolor = (global.LUT1_toggle == 0.0) ? col : mixfix(color1, color2, mixer);
  787.  
  788.  
  789. // OETF - Opto-Electronic Transfer Function
  790.     vcolor = pow(vcolor, vec3(1./(gamma_in/gamma_out)));
  791.  
  792. // OETF - Opto-Electronic Transfer Function
  793.     vcolor = (SPC == 3.0) ?     clamp(pow(vcolor,                     vec3(563./256.)),     0., 1.) : \
  794.              (SPC == 2.0) ? moncurve_f_f3(vcolor,                          2.20 + 0.022222, 0.0993) : \
  795.              (SPC == 1.0) ?     clamp(pow(vcolor,                     vec3(2.20 + 0.40)),   0., 1.) : \
  796.              (SPC == 0.0) ? moncurve_f_f3(vcolor,                          2.20 + 0.20,     0.0550) : \
  797.                             clamp(pow(pow(vcolor, vec3(1./1.019264)), vec3(2.20 + 0.20)),   0., 1.) ;
  798.  
  799.  
  800.     vcolor = RGB_to_XYZ(vcolor, 0.);
  801.  
  802.  
  803. // Sigmoidal Contrast
  804.     vec3 Yxy = XYZtoYxy(vcolor);
  805.     float toGamma = clamp(moncurve_r(Yxy.r, 2.40, 0.055), 0.0, 1.0);
  806.     toGamma = (Yxy.r > 0.5) ? contrast_sigmoid_inv(toGamma, 2.3, 0.5) : toGamma;
  807.     float sigmoid = (cntrst > 0.0) ? contrast_sigmoid(toGamma, cntrst, mid) : contrast_sigmoid_inv(toGamma, cntrst, mid);
  808.     vec3 contrast = vec3(moncurve_f(sigmoid, 2.40, 0.055), Yxy.g, Yxy.b);
  809.     vec3 XYZsrgb = clamp(XYZ_to_RGB(YxytoXYZ(contrast), SPC), 0.0, 1.0);
  810.     contrast = (cntrst == 0.0) ? XYZ_to_RGB(vcolor, SPC) : XYZsrgb;
  811.  
  812.  
  813. // Vignetting & Black Level
  814.     vec2 vpos = vTexCoord*(global.OriginalSize.xy/global.SourceSize.xy);
  815.  
  816.     vpos *= 1.0 - vpos.xy;
  817.     float vig = vpos.x * vpos.y * vstr;
  818.     vig = min(pow(vig, vpower), 1.0);
  819.     contrast *= (vignette == 1.0) ? vig : 1.0;
  820.  
  821.     contrast += (lift / 20.0) * (1.0 - contrast);
  822.  
  823.  
  824. // RGB Related Transforms
  825.     vec4 screen = vec4(max(contrast, 0.0), 1.0);
  826.     float sat = g_sat + 1.0;
  827.  
  828.                    //  r    g    b  alpha ; alpha does nothing for our purposes
  829.     mat4 color = mat4(wlr, rg,  rb,   0.0,              //red tint
  830.                       gr,  wlg, gb,   0.0,              //green tint
  831.                       br,  bg,  wlb,  0.0,              //blue tint
  832.                       blr/20., blg/20., blb/20., 0.0);  //black tint
  833.  
  834.  
  835.     vec3 coeff = (SPC ==  3.0) ? vec3(0.29734000563621520, 0.62735998630523680,  0.07529000192880630) : \
  836.                  (SPC ==  2.0) ? vec3(0.24840137362480164, 0.67799961566925050,  0.03913172334432602) : \
  837.                  (SPC ==  1.0) ? vec3(0.22898375988006592, 0.69173991680145260,  0.07927616685628891) : \
  838.                                  vec3(0.21264933049678802, 0.71516913175582890,  0.07218152284622192) ;
  839.  
  840.     mat3 adjust = mat3((1.0 - sat) * coeff.x + sat, (1.0 - sat) * coeff.x,       (1.0 - sat) * coeff.x,
  841.                        (1.0 - sat) * coeff.y,       (1.0 - sat) * coeff.y + sat, (1.0 - sat) * coeff.y,
  842.                        (1.0 - sat) * coeff.z,       (1.0 - sat) * coeff.z,       (1.0 - sat) * coeff.z + sat);
  843.  
  844.  
  845.     screen = clamp(rolled_gain_v4(screen, clamp(lum, -0.49,0.99)), 0.0, 1.0);
  846.     screen = color * screen;
  847.  
  848. //  HUE vs SAT
  849.     vec3 src_h = RGB_to_XYZ(screen.rgb, SPC) * LMS;
  850.     src_h.x = src_h.x >= 0.0 ? pow(src_h.x, 0.43) : -pow(-src_h.x, 0.43);
  851.     src_h.y = src_h.y >= 0.0 ? pow(src_h.y, 0.43) : -pow(-src_h.y, 0.43);
  852.     src_h.z = src_h.z >= 0.0 ? pow(src_h.z, 0.43) : -pow(-src_h.z, 0.43);
  853.  
  854.     src_h.xyz *= IPT;
  855.  
  856.     float hue_at = atan(src_h.z, src_h.y);
  857.     chroma = sqrt(src_h.z * src_h.z + src_h.y * src_h.y);
  858.  
  859.     float hue_radians_r = -40.0 * (M_PI / 180.0);
  860.     float hue_r = clamp(chroma * cos(hue_at + hue_radians_r) * 2., 0.0, 1.0);
  861.  
  862.     float hue_radians_g = 230.0 * (M_PI / 180.0);
  863.     float hue_g = clamp(chroma * cos(hue_at + hue_radians_g) * 2., 0.0, 1.0);
  864.  
  865.     float hue_radians_b = 100.0 * (M_PI / 180.0);
  866.     float hue_b = clamp(chroma * cos(hue_at + hue_radians_b) * 2., 0.0, 1.0);
  867.  
  868.     float msk = dot(vec3(hue_r, hue_g, hue_b), vec3(satr, satg, satb)*(-1.));
  869.     src_h = mixfix(screen.rgb, vec3(dot(coeff, screen.rgb)), msk);
  870.  
  871.     float sat_msk = (vibr < 0.0) ? clamp(1.0 - abs(SatMask(src_h.x, src_h.y, src_h.z) - 1.0) * abs(vibr), 0.0, 1.0) : \
  872.                                    clamp(1.0 -    (SatMask(src_h.x, src_h.y, src_h.z) * vibr),            0.0, 1.0) ;
  873.  
  874.     src_h = mixfix(src_h, clamp(adjust * src_h, 0.0, 1.0), sat_msk);
  875.  
  876.  
  877. // CRT Phosphor Gamut
  878.     mat3 m_in;
  879.  
  880.     if (crtgamut == -4.0) { m_in = NTSC_FCC_transform;          } else
  881.     if (crtgamut == -3.0) { m_in = Conrac_transform;            } else
  882.     if (crtgamut == -2.0) { m_in = Sony20_20_transform;         } else
  883.     if (crtgamut == -1.0) { m_in = SMPTE_transform;             } else
  884.     if (crtgamut ==  1.0) { m_in = P22_transform;               } else
  885.     if (crtgamut ==  2.0) { m_in = NTSC_J_transform;            } else
  886.     if (crtgamut ==  3.0) { m_in = EBU_transform;               }
  887.  
  888.     vec3 gamut = (crtgamut == -4.0) ? (m_in*src_h)*C_D65_Brad    : \
  889.                  (crtgamut == -3.0) ? (m_in*src_h)*C_D65_Brad    : \
  890.                  (crtgamut == -2.0) ? (m_in*src_h)*D93_D65_Brad  : \
  891.                  (crtgamut ==  2.0) ? (m_in*src_h)*D93_D65_Brad  : \
  892.                  (crtgamut ==  3.0) ? (m_in*src_h)*PAL_D65_Brad  : \
  893.                                        m_in*src_h;
  894.  
  895. // White Point Mapping
  896.     vec3 wp       = wp_adjust(global.wp_temperature - 1000.);
  897.     vec3 base     = (crtgamut == 0.0) ? RGB_to_XYZ(src_h, SPC)      : gamut;
  898.          base     = XYZtoYxy(base);
  899.     vec3 adjusted = (crtgamut == 0.0) ? RGB_to_XYZ(src_h, SPC) * wp : gamut * wp;
  900.          adjusted = XYZtoYxy(adjusted);
  901.          adjusted = clamp(XYZ_to_RGB(YxytoXYZ(vec3(base.x , adjusted.y , adjusted.z)), SPC), 0.0, 1.0);
  902.  
  903.  
  904. // EOTF - Electro-Optical Transfer Function (Rec.709 does a Dim to Dark Surround adaptation)
  905.     vec3 TRC = (SPC == 3.0) ?     clamp(pow(adjusted,                  vec3(1./(563./256.))),    0., 1.) : \
  906.                (SPC == 2.0) ? moncurve_r_f3(adjusted,                           2.20 + 0.022222, 0.0993) : \
  907.                (SPC == 1.0) ?     clamp(pow(adjusted,                  vec3(1./(2.20 + 0.40))),  0., 1.) : \
  908.                (SPC == 0.0) ? moncurve_r_f3(adjusted,                           2.20 + 0.20,     0.0550) : \
  909.                               clamp(pow(pow(adjusted, vec3(1.019264)), vec3(1./(2.20 + 0.20))),  0., 1.) ;
  910.  
  911.  
  912. // Technical LUT - (in SPC space)
  913.     float red_2 =   (TRC.r * (global.LUT_Size2 - 1.0) + 0.4999) / (global.LUT_Size2 * global.LUT_Size2);
  914.     float green_2 = (TRC.g * (global.LUT_Size2 - 1.0) + 0.4999) / global.LUT_Size2;
  915.     float blue1_2 = (floor(TRC.b * (global.LUT_Size2 - 1.0)) / global.LUT_Size2) + red_2;
  916.     float blue2_2 =  (ceil(TRC.b * (global.LUT_Size2 - 1.0)) / global.LUT_Size2) + red_2;
  917.     float mixer_2 = clamp(max((TRC.b - blue1_2) / (blue2_2 - blue1_2), 0.0), 0.0, 32.0);
  918.     vec3 color1_2 = texture(SamplerLUT2, vec2(blue1_2, green_2)).rgb;
  919.     vec3 color2_2 = texture(SamplerLUT2, vec2(blue2_2, green_2)).rgb;
  920.     vec3 LUT2_output = mixfix(color1_2, color2_2, mixer_2);
  921.  
  922.     LUT2_output = (global.LUT2_toggle == 0.0) ? TRC : LUT2_output;
  923.  
  924.  
  925.     FragColor = vec4(LUT2_output, 1.0);
  926. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement