Guest User

AmbientLightDither2020

a guest
Apr 17th, 2020
782
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /**
  2.  * Copyright (C) 2015 Ganossa (mediehawk@gmail.com)
  3.  *
  4.  * Permission is hereby granted, free of charge, to any person obtaining a copy of
  5.  * this software and associated documentation files (the "Software"), to deal in
  6.  * the Software with restriction, including without limitation the rights to
  7.  * use and/or sell copies of the Software, and to permit persons to whom the Software
  8.  * is furnished to do so, subject to the following conditions:
  9.  *
  10.  * The above copyright notice and the permission notices (this and below) shall
  11.  * be included in all copies or substantial portions of the Software.
  12.  *
  13.  * Permission needs to be specifically granted by the author of the software to any
  14.  * person obtaining a copy of this software and associated documentation files
  15.  * (the "Software"), to deal in the Software without restriction, including without
  16.  * limitation the rights to copy, modify, merge, publish, distribute, and/or
  17.  * sublicense the Software, and subject to the following conditions:
  18.  *
  19.  * The above copyright notice and the permission notices (this and above) shall
  20.  * be included in all copies or substantial portions of the Software.
  21.  *
  22.  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  23.  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  24.  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  25.  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  26.  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  27.  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  28.  * SOFTWARE.
  29.  */
  30.  
  31. /**
  32.  * This version of AmbientLight.fx has been modified to allow the "dither" effect
  33.  * to be toggled on and off.
  34.  */
  35. #include "ReShadeUI.fxh"
  36.  
  37. uniform bool alDebug <
  38.     ui_tooltip = "Activates debug mode of AL, upper bar shows detected light, lower bar shows adaptation";
  39. > = false;
  40. uniform float alInt < __UNIFORM_SLIDER_FLOAT1
  41.     ui_min = 0.0; ui_max = 20.0;
  42.     ui_tooltip = "Base intensity of AL";
  43. > = 10.15;
  44. uniform float alThreshold < __UNIFORM_SLIDER_FLOAT1
  45.     ui_min = 0.0; ui_max = 100.0;
  46.     ui_tooltip = "Reduces intensity for not bright light";
  47. > = 15.00;
  48. uniform bool AL_Dither <
  49.     ui_tooltip = "Applies dither - may cause diagonal stripes";
  50. > = true;
  51.  
  52. uniform bool AL_Adaptation <
  53.     ui_tooltip = "Activates adaptation algorithm";
  54. > = true;
  55. uniform float alAdapt < __UNIFORM_SLIDER_FLOAT1
  56.     ui_min = 0.0; ui_max = 4.0;
  57.     ui_tooltip = "Intensity of AL correction for bright light";
  58. > = 0.70;
  59. uniform float alAdaptBaseMult < __UNIFORM_SLIDER_FLOAT1
  60.     ui_min = 0.0; ui_max = 4.0;
  61.     ui_tooltip = "Multiplier for adaption applied to the original image";
  62. > = 1.00;
  63. uniform int alAdaptBaseBlackLvL < __UNIFORM_SLIDER_INT1
  64.     ui_min = 0; ui_max = 4;
  65.     ui_tooltip = "Distinction level of black and white (lower => less distinct)";
  66. > = 2;
  67.  
  68. uniform bool AL_Dirt <
  69. > = true;
  70. uniform bool AL_DirtTex <
  71.     ui_tooltip = "Defines if dirt texture is used as overlay";
  72. > = false;
  73. uniform bool AL_Vibrance <
  74.     ui_tooltip = "Vibrance of dirt effect";
  75. > = false;
  76. uniform int AL_Adaptive <
  77.     ui_type = "combo";
  78.     ui_min = 0; ui_max = 2;
  79.     ui_items = "Warm\0Cold\0Light Dependent\0";
  80. > = 0;
  81. uniform float alDirtInt < __UNIFORM_SLIDER_FLOAT1
  82.     ui_min = 0.0; ui_max = 2.0;
  83.     ui_tooltip = "Intensity of dirt effect";
  84. > = 1.0;
  85. uniform float alDirtOVInt < __UNIFORM_SLIDER_FLOAT1
  86.     ui_min = 0.0; ui_max = 2.0;
  87.     ui_tooltip = "Intensity of colored dirt effect";
  88. > = 1.0;
  89. uniform bool AL_Lens <
  90.     ui_tooltip = "Lens effect based on AL";
  91. > = false;
  92. uniform float alLensThresh < __UNIFORM_SLIDER_FLOAT1
  93.     ui_min = 0.0; ui_max = 1.0;
  94.     ui_tooltip = "Reduces intensity of lens effect for not bright light";
  95. > = 0.5;
  96. uniform float alLensInt < __UNIFORM_SLIDER_FLOAT1
  97.     ui_min = 0.0; ui_max = 10.0;
  98.     ui_tooltip = "Intensity of lens effect";
  99. > = 2.0;
  100.  
  101. #include "ReShade.fxh"
  102.  
  103. uniform float2 AL_t < source = "pingpong"; min = 0.0f; max = 6.28f; step = float2(0.1f, 0.2f); >;
  104.  
  105. #define GEMFX_PIXEL_SIZE float2(1.0f / (BUFFER_WIDTH / 16.0f), 1.0f / (BUFFER_HEIGHT / 16.0f))
  106.  
  107. texture alInTex  { Width = BUFFER_WIDTH / 16; Height = BUFFER_HEIGHT / 16; Format = RGBA32F; };
  108. texture alOutTex { Width = BUFFER_WIDTH / 16; Height = BUFFER_HEIGHT / 16; Format = RGBA32F; };
  109. texture detectIntTex { Width = 32; Height = 32; Format = RGBA8; };
  110. sampler detectIntColor { Texture = detectIntTex; };
  111. texture detectLowTex { Width = 1; Height = 1; Format = RGBA8; };
  112. sampler detectLowColor { Texture = detectLowTex; };
  113.  
  114. texture dirtTex    < source = "Dirt.png";    > { Width = 1920; Height = 1080; MipLevels = 1; Format = RGBA8; };
  115. texture dirtOVRTex < source = "DirtOVR.png"; > { Width = 1920; Height = 1080; MipLevels = 1; Format = RGBA8; };
  116. texture dirtOVBTex < source = "DirtOVB.png"; > { Width = 1920; Height = 1080; MipLevels = 1; Format = RGBA8; };
  117. texture lensDBTex  < source = "LensDB.png";  > { Width = 1920; Height = 1080; MipLevels = 1; Format = RGBA8; };
  118. texture lensDB2Tex < source = "LensDB2.png"; > { Width = 1920; Height = 1080; MipLevels = 1; Format = RGBA8; };
  119. texture lensDOVTex < source = "LensDOV.png"; > { Width = 1920; Height = 1080; MipLevels = 1; Format = RGBA8; };
  120. texture lensDUVTex < source = "LensDUV.png"; > { Width = 1920; Height = 1080; MipLevels = 1; Format = RGBA8; };
  121.  
  122. sampler alInColor { Texture = alInTex; };
  123. sampler alOutColor { Texture = alOutTex; };
  124. sampler dirtSampler { Texture = dirtTex; };
  125. sampler dirtOVRSampler { Texture = dirtOVRTex; };
  126. sampler dirtOVBSampler { Texture = dirtOVBTex; };
  127. sampler lensDBSampler { Texture = lensDBTex; };
  128. sampler lensDB2Sampler { Texture = lensDB2Tex; };
  129. sampler lensDOVSampler { Texture = lensDOVTex; };
  130. sampler lensDUVSampler { Texture = lensDUVTex; };
  131.  
  132. void PS_AL_DetectInt(float4 vpos : SV_Position, float2 texcoord : TEXCOORD, out float4 detectInt : SV_Target0)
  133. {
  134.     detectInt = tex2D(ReShade::BackBuffer, texcoord);
  135. }
  136. void PS_AL_DetectLow(float4 vpos : SV_Position, float2 texcoord : TEXCOORD, out float4 detectLow : SV_Target0)
  137. {
  138.     detectLow = 0;
  139.  
  140.     if (texcoord.x != 0.5 && texcoord.y != 0.5)
  141.         discard;
  142.  
  143.     [loop]
  144.     for (float i = 0.0; i <= 1; i += 0.03125)
  145.     {
  146.         [unroll]
  147.         for (float j = 0.0; j <= 1; j += 0.03125)
  148.         {
  149.             detectLow.xyz += tex2D(detectIntColor, float2(i, j)).xyz;
  150.         }
  151.     }
  152.  
  153.     detectLow.xyz /= 32 * 32;
  154. }
  155. void PS_AL_DetectHigh(float4 vpos : SV_Position, float2 texcoord : TEXCOORD, out float4 x : SV_Target)
  156. {
  157.     x = tex2D(ReShade::BackBuffer, texcoord);
  158.     x = float4(x.rgb * pow(abs(max(x.r, max(x.g, x.b))), 2.0), 1.0f);
  159.  
  160.     float base = (x.r + x.g + x.b); base /= 3;
  161.    
  162.     float nR = (x.r * 2) - base;
  163.     float nG = (x.g * 2) - base;
  164.     float nB = (x.b * 2) - base;
  165.  
  166.     [flatten]
  167.     if (nR < 0)
  168.     {
  169.         nG += nR / 2;
  170.         nB += nR / 2;
  171.         nR = 0;
  172.     }
  173.     [flatten]
  174.     if (nG < 0)
  175.     {
  176.         nB += nG / 2;
  177.         [flatten] if (nR > -nG / 2) nR += nG / 2; else nR = 0;
  178.         nG = 0;
  179.     }
  180.     [flatten]
  181.     if (nB < 0)
  182.     {
  183.         [flatten] if (nR > -nB / 2) nR += nB / 2; else nR = 0;
  184.         [flatten] if (nG > -nB / 2) nG += nB / 2; else nG = 0;
  185.         nB = 0;
  186.     }
  187.  
  188.     [flatten]
  189.     if (nR > 1)
  190.     {
  191.         nG += (nR - 1) / 2;
  192.         nB += (nR - 1) / 2;
  193.         nR = 1;
  194.     }
  195.     [flatten]
  196.     if (nG > 1)
  197.     {
  198.         nB += (nG - 1) / 2;
  199.         [flatten] if (nR + (nG - 1) < 1) nR += (nG - 1) / 2; else nR = 1;
  200.         nG = 1;
  201.     }
  202.     [flatten]
  203.     if (nB > 1)
  204.     {
  205.         [flatten] if (nR + (nB - 1) < 1) nR += (nB - 1) / 2; else nR = 1;
  206.         [flatten] if (nG + (nB - 1) < 1) nG += (nB - 1) / 2; else nG = 1;
  207.         nB = 1;
  208.     }
  209.  
  210.     x.r = nR; x.g = nG; x.b = nB;
  211. }
  212.  
  213. void PS_AL_HGB(float4 vpos : SV_Position, float2 texcoord : TEXCOORD, out float4 hgb : SV_Target)
  214. {
  215.     const float sampleOffsets[5] = { 0.0, 2.4347826, 4.3478260, 6.2608695, 8.1739130 };
  216.     const float sampleWeights[5] = { 0.16818994, 0.27276957, 0.111690125, 0.024067905, 0.0021112196 };
  217.  
  218.     hgb = tex2D(alInColor, texcoord) * sampleWeights[0];
  219.     hgb = float4(max(hgb.rgb - alThreshold, 0.0), hgb.a);
  220.     float stepMult = 1.08 + (AL_t.x / 100) * 0.02;
  221.  
  222.     [flatten]
  223.     if ((texcoord.x + sampleOffsets[1] * GEMFX_PIXEL_SIZE.x) < 1.05)
  224.         hgb += tex2D(alInColor, texcoord + float2(sampleOffsets[1] * GEMFX_PIXEL_SIZE.x, 0.0)) * sampleWeights[1] * stepMult;
  225.     [flatten]
  226.     if ((texcoord.x - sampleOffsets[1] * GEMFX_PIXEL_SIZE.x) > -0.05)
  227.         hgb += tex2D(alInColor, texcoord - float2(sampleOffsets[1] * GEMFX_PIXEL_SIZE.x, 0.0)) * sampleWeights[1] * stepMult;
  228.  
  229.     [flatten]
  230.     if ((texcoord.x + sampleOffsets[2] * GEMFX_PIXEL_SIZE.x) < 1.05)
  231.         hgb += tex2D(alInColor, texcoord + float2(sampleOffsets[2] * GEMFX_PIXEL_SIZE.x, 0.0)) * sampleWeights[2] * stepMult;
  232.     [flatten]
  233.     if ((texcoord.x - sampleOffsets[2] * GEMFX_PIXEL_SIZE.x) > -0.05)
  234.         hgb += tex2D(alInColor, texcoord - float2(sampleOffsets[2] * GEMFX_PIXEL_SIZE.x, 0.0)) * sampleWeights[2] * stepMult;
  235.  
  236.     [flatten]
  237.     if ((texcoord.x + sampleOffsets[3] * GEMFX_PIXEL_SIZE.x) < 1.05)
  238.         hgb += tex2D(alInColor, texcoord + float2(sampleOffsets[3] * GEMFX_PIXEL_SIZE.x, 0.0)) * sampleWeights[3] * stepMult;
  239.     [flatten]
  240.     if ((texcoord.x - sampleOffsets[3] * GEMFX_PIXEL_SIZE.x) > -0.05)
  241.         hgb += tex2D(alInColor, texcoord - float2(sampleOffsets[3] * GEMFX_PIXEL_SIZE.x, 0.0)) * sampleWeights[3] * stepMult;
  242.  
  243.     [flatten]
  244.     if ((texcoord.x + sampleOffsets[4] * GEMFX_PIXEL_SIZE.x) < 1.05)
  245.         hgb += tex2D(alInColor, texcoord + float2(sampleOffsets[4] * GEMFX_PIXEL_SIZE.x, 0.0)) * sampleWeights[4] * stepMult;
  246.     [flatten]
  247.     if ((texcoord.x - sampleOffsets[4] * GEMFX_PIXEL_SIZE.x) > -0.05)
  248.         hgb += tex2D(alInColor, texcoord - float2(sampleOffsets[4] * GEMFX_PIXEL_SIZE.x, 0.0)) * sampleWeights[4] * stepMult;
  249. }
  250. void PS_AL_VGB(float4 vpos : SV_Position, float2 texcoord : TEXCOORD, out float4 vgb : SV_Target)
  251. {
  252.     const float sampleOffsets[5] = { 0.0, 2.4347826, 4.3478260, 6.2608695, 8.1739130 };
  253.     const float sampleWeights[5] = { 0.16818994, 0.27276957, 0.111690125, 0.024067905, 0.0021112196 };
  254.  
  255.     vgb = tex2D(alOutColor, texcoord) * sampleWeights[0];
  256.     vgb = float4(max(vgb.rgb - alThreshold, 0.0), vgb.a);
  257.     float stepMult = 1.08 + (AL_t.x / 100) * 0.02;
  258.    
  259.     [flatten]
  260.     if ((texcoord.y + sampleOffsets[1] * GEMFX_PIXEL_SIZE.y) < 1.05)
  261.         vgb += tex2D(alOutColor, texcoord + float2(0.0, sampleOffsets[1] * GEMFX_PIXEL_SIZE.y)) * sampleWeights[1] * stepMult;
  262.     [flatten]
  263.     if ((texcoord.y - sampleOffsets[1] * GEMFX_PIXEL_SIZE.y) > -0.05)
  264.         vgb += tex2D(alOutColor, texcoord - float2(0.0, sampleOffsets[1] * GEMFX_PIXEL_SIZE.y)) * sampleWeights[1] * stepMult;
  265.    
  266.     [flatten]
  267.     if ((texcoord.y + sampleOffsets[2] * GEMFX_PIXEL_SIZE.y) < 1.05)
  268.         vgb += tex2D(alOutColor, texcoord + float2(0.0, sampleOffsets[2] * GEMFX_PIXEL_SIZE.y)) * sampleWeights[2] * stepMult;
  269.     [flatten]
  270.     if ((texcoord.y - sampleOffsets[2] * GEMFX_PIXEL_SIZE.y) > -0.05)
  271.         vgb += tex2D(alOutColor, texcoord - float2(0.0, sampleOffsets[2] * GEMFX_PIXEL_SIZE.y)) * sampleWeights[2] * stepMult;
  272.  
  273.     [flatten]
  274.     if ((texcoord.y + sampleOffsets[3] * GEMFX_PIXEL_SIZE.y) < 1.05)
  275.         vgb += tex2D(alOutColor, texcoord + float2(0.0, sampleOffsets[3] * GEMFX_PIXEL_SIZE.y)) * sampleWeights[3] * stepMult;
  276.     [flatten]
  277.     if ((texcoord.y - sampleOffsets[3] * GEMFX_PIXEL_SIZE.y) > -0.05)
  278.         vgb += tex2D(alOutColor, texcoord - float2(0.0, sampleOffsets[3] * GEMFX_PIXEL_SIZE.y)) * sampleWeights[3] * stepMult;
  279.  
  280.     [flatten]
  281.     if ((texcoord.y + sampleOffsets[4] * GEMFX_PIXEL_SIZE.y) < 1.05)
  282.         vgb += tex2D(alOutColor, texcoord + float2(0.0, sampleOffsets[4] * GEMFX_PIXEL_SIZE.y)) * sampleWeights[4] * stepMult;
  283.     [flatten]
  284.     if ((texcoord.y - sampleOffsets[4] * GEMFX_PIXEL_SIZE.y) > -0.05)
  285.         vgb += tex2D(alOutColor, texcoord - float2(0.0, sampleOffsets[4] * GEMFX_PIXEL_SIZE.y)) * sampleWeights[4] * stepMult;
  286. }
  287.  
  288. float4 PS_AL_Magic(float4 vpos : SV_Position, float2 texcoord : TEXCOORD) : SV_Target
  289. {
  290.     float4 base = tex2D(ReShade::BackBuffer, texcoord);
  291.     float4 high = tex2D(alInColor, texcoord);
  292.     float adapt = 0;
  293.  
  294. #if __RENDERER__ < 0xa000 && !__RESHADE_PERFORMANCE_MODE__
  295.     [flatten]
  296. #endif
  297.     if (AL_Adaptation)
  298.     {
  299.         //DetectLow
  300.         float4 detectLow = tex2D(detectLowColor, 0.5) / 4.215;
  301.         float low = sqrt(0.241 * detectLow.r * detectLow.r + 0.691 * detectLow.g * detectLow.g + 0.068 * detectLow.b * detectLow.b);
  302.         //.DetectLow
  303.  
  304.         low = pow(low * 1.25f, 2);
  305.         adapt = low * (low + 1.0f) * alAdapt * alInt * 5.0f;
  306.  
  307.         if (alDebug)
  308.         {
  309.             float mod = (texcoord.x * 1000.0f) % 1.001f;
  310.             //mod = abs(mod - texcoord.x / 4.0f);
  311.  
  312.             if (texcoord.y < 0.01f && (texcoord.x < low * 10f && mod < 0.3f))
  313.                 return float4(1f, 0.5f, 0.3f, 0f);
  314.  
  315.             if (texcoord.y > 0.01f && texcoord.y < 0.02f && (texcoord.x < adapt / (alInt * 1.5) && mod < 0.3f))
  316.                 return float4(0.2f, 1f, 0.5f, 0f);
  317.         }
  318.     }
  319.  
  320.     high = min(0.0325f, high) * 1.15f;
  321.     float4 highOrig = high;
  322.  
  323.     float2 flipcoord = 1.0f - texcoord;
  324.     float4 highFlipOrig = tex2D(alInColor, flipcoord);
  325.     highFlipOrig = min(0.03f, highFlipOrig) * 1.15f;
  326.  
  327.     float4 highFlip = highFlipOrig;
  328.     float4 highLensSrc = high;
  329.  
  330. #if __RENDERER__ < 0xa000 && !__RESHADE_PERFORMANCE_MODE__
  331.     [flatten]
  332. #endif
  333.     if (AL_Dirt)
  334.     {
  335.         float4 dirt = tex2D(dirtSampler, texcoord);
  336.         float4 dirtOVR = tex2D(dirtOVRSampler, texcoord);
  337.         float4 dirtOVB = tex2D(dirtOVBSampler, texcoord);
  338.  
  339.         float maxhigh = max(high.r, max(high.g, high.b));
  340.         float threshDiff = maxhigh - 3.2f;
  341.  
  342.         [flatten]
  343.         if (threshDiff > 0)
  344.         {
  345.             high.r = (high.r / maxhigh) * 3.2f;
  346.             high.g = (high.g / maxhigh) * 3.2f;
  347.             high.b = (high.b / maxhigh) * 3.2f;
  348.         }
  349.  
  350.         float4 highDirt = AL_DirtTex ? highOrig * dirt * alDirtInt : highOrig * high * alDirtInt;
  351.  
  352.         if (AL_Vibrance)
  353.         {
  354.             highDirt *= 1.0f + 0.5f * sin(AL_t.x);
  355.         }
  356.  
  357.         float highMix = highOrig.r + highOrig.g + highOrig.b;
  358.         float red = highOrig.r / highMix;
  359.         float green = highOrig.g / highMix;
  360.         float blue = highOrig.b / highMix;
  361.         highOrig = highOrig + highDirt;
  362.  
  363.         if (AL_Adaptive == 2)
  364.         {
  365.             high = high + high * dirtOVR * alDirtOVInt * green;
  366.             high = high + highDirt;
  367.             high = high + highOrig * dirtOVB * alDirtOVInt * blue;
  368.             high = high + highOrig * dirtOVR * alDirtOVInt* red;
  369.         }
  370.         else if (AL_Adaptive == 1)
  371.         {
  372.             high = high + highDirt;
  373.             high = high + highOrig * dirtOVB * alDirtOVInt;
  374.         }
  375.         else
  376.         {
  377.             high = high + highDirt;
  378.             high = high + highOrig * dirtOVR * alDirtOVInt;
  379.         }
  380.  
  381.         highLensSrc = high * 85f * pow(1.25f - (abs(texcoord.x - 0.5f) + abs(texcoord.y - 0.5f)), 2);
  382.     }
  383.  
  384.     float origBright = max(highLensSrc.r, max(highLensSrc.g, highLensSrc.b));
  385.     float maxOrig = max((1.8f * alLensThresh) - pow(origBright * (0.5f - abs(texcoord.x - 0.5f)), 4), 0.0f);
  386.     float smartWeight = maxOrig * max(abs(flipcoord.x - 0.5f), 0.3f * abs(flipcoord.y - 0.5f)) * (2.2 - 1.2 * (abs(flipcoord.x - 0.5f))) * alLensInt;
  387.     smartWeight = min(0.85f, max(0, AL_Adaptation ? smartWeight - adapt : smartWeight));
  388.  
  389. #if __RENDERER__ < 0xa000 && !__RESHADE_PERFORMANCE_MODE__
  390.     [flatten]
  391. #endif
  392.     if (AL_Lens)
  393.     {
  394.         float4 lensDB = tex2D(lensDBSampler, texcoord);
  395.         float4 lensDB2 = tex2D(lensDB2Sampler, texcoord);
  396.         float4 lensDOV = tex2D(lensDOVSampler, texcoord);
  397.         float4 lensDUV = tex2D(lensDUVSampler, texcoord);
  398.  
  399.         float4 highLens = highFlip * lensDB * 0.7f * smartWeight;
  400.         high += highLens;
  401.  
  402.         highLens = highFlipOrig * lensDUV * 1.15f * smartWeight;
  403.         highFlipOrig += highLens;
  404.         high += highLens;
  405.  
  406.         highLens = highFlipOrig * lensDB2 * 0.7f * smartWeight;
  407.         highFlipOrig += highLens;
  408.         high += highLens;
  409.  
  410.         highLens = highFlipOrig * lensDOV * 1.15f * smartWeight / 2f + highFlipOrig * smartWeight / 2f;
  411.         highFlipOrig += highLens;
  412.         high += highLens;
  413.     }
  414.  
  415.     float dither = 0.15 * (1.0 / (pow(2, 10.0) - 1.0));
  416.     dither = lerp(2.0 * dither, -2.0 * dither, frac(dot(texcoord, BUFFER_SCREEN_SIZE * float2(1.0 / 16.0, 10.0 / 36.0)) + 0.25));
  417.  
  418.     if (all(base.xyz == 1.0))
  419.     {
  420.         return 1.0;
  421.     }
  422.  
  423. #if __RENDERER__ < 0xa000 && !__RESHADE_PERFORMANCE_MODE__
  424.     [flatten]
  425. #endif
  426.  
  427.     if (AL_Adaptation && AL_Dither)
  428.     {
  429.         base.xyz *= max(0.0f, (1.0f - adapt * 0.75f * alAdaptBaseMult * pow(abs(1.0f - (base.x + base.y + base.z) / 3), alAdaptBaseBlackLvL)));
  430.         float4 highSampleMix = (1.0 - ((1.0 - base) * (1.0 - high * 1.0))) + dither;
  431.         float4 baseSample = lerp(base, highSampleMix, max(0.0f, alInt - adapt));
  432.         float baseSampleMix = baseSample.r + baseSample.g + baseSample.b;
  433.         return baseSampleMix > 0.008 ? baseSample : lerp(base, highSampleMix, max(0.0f, (alInt - adapt) * 0.85f) * baseSampleMix);
  434.     }
  435.   else if (AL_Adaptation)
  436.     {
  437.         base.xyz *= max(0.0f, (1.0f - adapt * 0.75f * alAdaptBaseMult * pow(abs(1.0f - (base.x + base.y + base.z) / 3), alAdaptBaseBlackLvL)));
  438.         float4 highSampleMix = (1.0 - ((1.0 - base) * (1.0 - high * 1.0)));
  439.         float4 baseSample = lerp(base, highSampleMix, max(0.0f, alInt - adapt));
  440.         float baseSampleMix = baseSample.r + baseSample.g + baseSample.b;
  441.         return baseSampleMix > 0.008 ? baseSample : lerp(base, highSampleMix, max(0.0f, (alInt - adapt) * 0.85f) * baseSampleMix);
  442.     }
  443.     else if (AL_Dither)
  444.     {
  445.         float4 highSampleMix = (1.0 - ((1.0 - base) * (1.0 - high * 1.0))) + dither + adapt;
  446.         float4 baseSample = lerp(base, highSampleMix, alInt);
  447.         float baseSampleMix = baseSample.r + baseSample.g + baseSample.b;
  448.         return baseSampleMix > 0.008 ? baseSample : lerp(base, highSampleMix, max(0.0f, alInt * 0.85f) * baseSampleMix);
  449.     }
  450.     else
  451.   {
  452.     float4 highSampleMix = (1.0 - ((1.0 - base) * (1.0 - high * 1.0))) + adapt;
  453.     float4 baseSample = lerp(base, highSampleMix, alInt);
  454.     float baseSampleMix = baseSample.r + baseSample.g + baseSample.b;
  455.     return baseSampleMix > 0.008 ? baseSample : lerp(base, highSampleMix, max(0.0f, alInt * 0.85f) * baseSampleMix);
  456.   }
  457. }
  458.  
  459. technique AmbientLight
  460. {
  461.     pass AL_DetectInt
  462.     {
  463.         VertexShader = PostProcessVS;
  464.         PixelShader = PS_AL_DetectInt;
  465.         RenderTarget = detectIntTex;
  466.     }
  467.     pass AL_DetectLow
  468.     {
  469.         VertexShader = PostProcessVS;
  470.         PixelShader = PS_AL_DetectLow;
  471.         RenderTarget = detectLowTex;
  472.     }
  473.     pass AL_DetectHigh
  474.     {
  475.         VertexShader = PostProcessVS;
  476.         PixelShader = PS_AL_DetectHigh;
  477.         RenderTarget = alInTex;
  478.     }
  479.  
  480. #define PASS_AL_H(i) \
  481.     pass AL_H##i \
  482.     { \
  483.         VertexShader = PostProcessVS; \
  484.         PixelShader = PS_AL_HGB; \
  485.         RenderTarget = alOutTex; \
  486.     }
  487. #define PASS_AL_V(i) \
  488.     pass AL_V##i \
  489.     { \
  490.         VertexShader = PostProcessVS; \
  491.         PixelShader = PS_AL_VGB; \
  492.         RenderTarget = alInTex; \
  493.     }
  494.  
  495.     PASS_AL_H(1)
  496.     PASS_AL_V(1)
  497.     PASS_AL_H(2)
  498.     PASS_AL_V(2)
  499.     PASS_AL_H(3)
  500.     PASS_AL_V(3)
  501.     PASS_AL_H(4)
  502.     PASS_AL_V(4)
  503.     PASS_AL_H(5)
  504.     PASS_AL_V(5)
  505.     PASS_AL_H(6)
  506.     PASS_AL_V(6)
  507.     PASS_AL_H(7)
  508.     PASS_AL_V(7)
  509.     PASS_AL_H(8)
  510.     PASS_AL_V(8)
  511.     PASS_AL_H(9)
  512.     PASS_AL_V(9)
  513.     PASS_AL_H(10)
  514.     PASS_AL_V(10)
  515.     PASS_AL_H(11)
  516.     PASS_AL_V(11)
  517.     PASS_AL_H(12)
  518.     PASS_AL_V(12)
  519.  
  520.     pass AL_Magic
  521.     {
  522.         VertexShader = PostProcessVS;
  523.         PixelShader = PS_AL_Magic;
  524.     }
  525. }
RAW Paste Data