#line 1 "unknown"

#line 1 "D:\Games\The Elder Scrolls V Skyrim VR\reshade-shaders\Shaders\Glitch.fx"
#line 1 "D:\Games\The Elder Scrolls V Skyrim VR\reshade-shaders\Shaders\ReShade.fxh"
#line 50
namespace ReShade
{
#line 61
static const float AspectRatio = 1608 * (1.0 / 960);
static const float2 PixelSize = float2((1.0 / 1608), (1.0 / 960));
static const float2 ScreenSize = float2(1608, 960);
#line 67
texture BackBufferTex : COLOR;
texture DepthBufferTex : DEPTH;
#line 70
sampler BackBuffer { Texture = BackBufferTex; };
sampler DepthBuffer { Texture = DepthBufferTex; };
#line 74
float GetLinearizedDepth(float2 texcoord)
{
#line 79
texcoord.x /=  1;
texcoord.y /=  1;
#line 84
texcoord.x -=  0 / 2.000000001;
#line 89
texcoord.y +=  0 / 2.000000001;
#line 91
float depth = tex2Dlod(DepthBuffer, float4(texcoord, 0, 0)).x *  1;
#line 100
const float N = 1.0;
depth /= 1000.0 - depth * (1000.0 - N);
#line 103
return depth;
}
}
#line 108
void PostProcessVS(in uint id : SV_VertexID, out float4 position : SV_Position, out float2 texcoord : TEXCOORD)
{
texcoord.x = (id == 2) ? 2.0 : 0.0;
texcoord.y = (id == 1) ? 2.0 : 0.0;
position = float4(texcoord * float2(2.0, -2.0) + float2(-1.0, 1.0), 0.0, 1.0);
}
#line 1 "D:\Games\The Elder Scrolls V Skyrim VR\reshade-shaders\Shaders\Glitch.fx"
#line 6
uniform float  Timer < source = "timer"; >;
#line 1 "D:\Games\The Elder Scrolls V Skyrim VR\reshade-shaders\Shaders\ReShadeUI.fxh"
#line 8 "D:\Games\The Elder Scrolls V Skyrim VR\reshade-shaders\Shaders\Glitch.fx"
#line 10
uniform float Amount <      ui_type = "slider"; 
ui_min = 0.0;
ui_max = 10.0;
ui_tooltip = "Glitch Amount [Glitch B]";
> = 1.0;
#line 16
uniform bool bUseUV <       ui_type = "combo";
ui_tooltip = "Use UV for Glitch [Glitch B]";
> = false;
#line 20
float fmod(float a, float b) {
float c = frac(abs(a / b)) * abs(b);
return a < 0 ? -c : c;
}
float2 fmod(float2 a, float2 b) {
float2 c = frac(abs(a / b)) * abs(b);
return a < 0 ? -c : c;
}
#line 29
float3 rgb2hsv(float3 c)
{
float4 K = float4(0.0, -1.0 / 3.0, 2.0 / 3.0, -1.0);
float4 p = lerp(float4(c.bg, K.wz), float4(c.gb, K.xy), step(c.b, c.g));
float4 q = lerp(float4(p.xyw, c.r), float4(c.r, p.yzx), step(p.x, c.r));
#line 35
float d = q.x - min(q.w, q.y);
float e = 1.0e-10;
return float3(abs(q.z + (q.w - q.y) / (6.0 * d + e)), d / (q.x + e), q.x);
}
#line 40
float3 hsv2rgb(float3 c)
{
float4 K = float4(1.0, 2.0 / 3.0, 1.0 / 3.0, 3.0);
float3 p = abs(frac(c.xxx + K.xyz) * 6.0 - K.www);
return c.z * lerp(K.xxx, clamp(p - K.xxx, 0.0, 1.0), c.y);
}
#line 47
float3 posterize(float3 color, float steps)
{
return floor(color * steps) / steps;
}
#line 52
float quantize(float n, float steps)
{
return floor(n * steps) / steps;
}
#line 57
float4 downsample(sampler2D samp, float2 uv, float pixelSize)
{
return tex2D(samp, uv - fmod(uv, float2(pixelSize,pixelSize) /  float2(1608, 960)));
}
#line 62
float rand(float n)
{
return frac(sin(n) * 43758.5453123);
}
#line 67
float noise(float p)
{
float fl = floor(p);
float fc = frac(p);
return lerp(rand(fl), rand(fl + 1.0), fc);
}
#line 74
float rand(float2 n)
{
return frac(sin(dot(n, float2(12.9898, 4.1414))) * 43758.5453);
}
#line 79
float noise(float2 p)
{
float2 ip = floor(p);
float2 u = frac(p);
u = u * u * (3.0 - 2.0 * u);
#line 85
float res = lerp(
lerp(rand(ip), rand(ip + float2(1.0, 0.0)), u.x),
lerp(rand(ip + float2(0.0,1.0)), rand(ip + float2(1.0,1.0)), u.x), u.y);
return res * res;
}
#line 91
float3 edge(sampler2D samp, float2 uv, float sampleSize)
{
float dx = sampleSize * (1.0 / 1608);
float dy = sampleSize * (1.0 / 960);
return (
lerp(downsample(samp, uv - float2(dx, 0.0), sampleSize), downsample(samp, uv + float2(dx, 0.0), sampleSize), fmod(uv.x, dx) / dx) +
lerp(downsample(samp, uv - float2(0.0, dy), sampleSize), downsample(samp, uv + float2(0.0, dy), sampleSize), fmod(uv.y, dy) / dy)
).rgb / 2.0 - tex2D(samp, uv).rgb;
}
#line 101
float3 distort(sampler2D samp, float2 uv, float edgeSize)
{
float2 pixel =  float2((1.0 / 1608), (1.0 / 960));
float3 field = rgb2hsv(edge(samp, uv, edgeSize));
float2 distort = pixel * sin((field.rb) *  3.14159265 * 2.0);
float shiftx = noise(float2(quantize(uv.y + 31.5, 960 /  16.0) * Timer*0.001, frac(Timer*0.001) * 300.0));
float shifty = noise(float2(quantize(uv.x + 11.5, 1608 /  16.0) * Timer*0.001, frac(Timer*0.001) * 100.0));
float3 rgb = tex2D(samp, uv + (distort + (pixel - pixel / 2.0) * float2(shiftx, shifty) * (50.0 + 100.0 * Amount)) * Amount).rgb;
float3 hsv = rgb2hsv(rgb);
hsv.y = fmod(hsv.y + shifty * pow(Amount, 5.0) * 0.25, 1.0);
return posterize(hsv2rgb(hsv), floor(lerp(256.0, pow(1.0 - hsv.z - 0.5, 2.0) * 64.0 * shiftx + 4.0, 1.0 - pow(1.0 - Amount, 5.0))));
}
#line 114
float4 PS_Glitch ( float4 pos : SV_Position, float2 fragCoord : TEXCOORD) : SV_Target
{
float4 fragColor;
float wow;
float Amount;
#line 120
float2 texcoord = fragCoord *  float2(1608, 960); 
float2 uv = texcoord.xy /  float2(1608, 960);
if (bUseUV) {
Amount = uv.x; 
}
wow = clamp(fmod(noise(Timer*0.001 + uv.y), 1.0), 0.0, 1.0) * 2.0 - 1.0;
float3 finalColor;
finalColor += distort(ReShade::BackBuffer, uv, 8.0);
return float4(finalColor, 1.0);
}
#line 131
technique GlitchB {
pass GlitchB {
VertexShader=PostProcessVS;
PixelShader=PS_Glitch;
}
}

