Advertisement
Guest User

Untitled

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