duckstation

duckstation, but archived from the revision just before upstream changed it to a proprietary software project, this version is the libre one
git clone https://git.neptards.moe/u3shit/duckstation.git
Log | Files | Refs | README | LICENSE

multi-LUT.fx (2273B)


      1 #include "ReShade.fxh"
      2 
      3 
      4 //    Multi-LUT Shader
      5 
      6 //    A simple shader that can load 2 LUTs.
      7 //    Can turn LUT off too.
      8 
      9 
     10 
     11 uniform int LUT_selector <
     12     ui_type = "combo";
     13     ui_items = "Off\0Grade-RGB\0Grade-Composite\0";
     14     ui_label = "LUT selector";
     15     ui_tooltip = "Off: nothing. Grade-RGB: rgb trinitron colors. Grade-Composite: composite trinitron colors.";
     16 > = 1;
     17 
     18 
     19 texture tLUT1<source="../Textures/multi-LUT/grade-rgb.png";>{Width=1024;Height=32;};
     20 sampler SamplerLUT1{Texture=tLUT1;};
     21 
     22 texture tLUT2<source="../Textures/multi-LUT/grade-composite.png";>{Width=1024;Height=32;};
     23 sampler SamplerLUT2{Texture=tLUT2;};
     24 
     25 // This shouldn't be necessary but it seems some undefined values can
     26 // creep in and each GPU vendor handles that differently. This keeps
     27 // all values within a safe range
     28 float4 mixfix(float4 a, float4 b, float c)
     29 {
     30     return (a.z < 1.0) ? lerp(a, b, c) : a;
     31 }
     32 
     33 float4 multiLUT(float4 vpos: SV_Position, float2 vTexCoord : TEXCOORD0) : SV_Target
     34 {
     35     float4 imgColor = tex2D(ReShade::BackBuffer, vTexCoord.xy);
     36 
     37     if (LUT_selector > 0)
     38     {
     39         //float LUT_Size = lerp(textureSize(SamplerLUT1, 0).y, textureSize(SamplerLUT2, 0).y, LUT_selector_param - 1.0);
     40         float LUT_Size = 32.0;
     41         float4 color1, color2 = float4(0.,0.,0.,0.);
     42         float red, green, blue1, blue2, mixer = 0.0;
     43     
     44         red = ( imgColor.r * (LUT_Size - 1.0) + 0.4999 ) / (LUT_Size * LUT_Size);
     45         green = ( imgColor.g * (LUT_Size - 1.0) + 0.4999 ) / LUT_Size;
     46         blue1 = (floor( imgColor.b  * (LUT_Size - 1.0) ) / LUT_Size) + red;
     47         blue2 = (ceil( imgColor.b  * (LUT_Size - 1.0) ) / LUT_Size) + red;
     48         mixer = clamp(max((imgColor.b - blue1) / (blue2 - blue1), 0.0), 0.0, 32.0);
     49     
     50         if(LUT_selector == 1)
     51         {
     52     	    color1 = tex2D(SamplerLUT1, float2( blue1, green ));
     53             color2 = tex2D(SamplerLUT1, float2( blue2, green )); 
     54         }
     55         else
     56         {
     57     	    color1 = tex2D(SamplerLUT2, float2( blue1, green ));
     58     	    color2 = tex2D(SamplerLUT2, float2( blue2, green ));
     59         }
     60         imgColor = mixfix(color1, color2, mixer);
     61     }
     62 
     63     return imgColor;
     64 }
     65 
     66 
     67 
     68 technique multiLUT
     69 {
     70     pass PS_multiLUT
     71     {
     72     	VertexShader = PostProcessVS;
     73     	PixelShader  = multiLUT;
     74     }
     75 }