Last active
February 16, 2022 05:22
-
-
Save Palakis/e3e7988a61177faa4726d5588919d368 to your computer and use it in GitHub Desktop.
StreamFX - Glitch shader filter (based on airtight's glitch shader)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// https://www.shadertoy.com/view/MtXBDs | |
// partially converted using Xaymar's shadertoy StreamFX template | |
#define vec2 float2 | |
#define vec3 float3 | |
#define vec4 float4 | |
#define ivec2 int2 | |
#define ivec3 int3 | |
#define ivec4 int4 | |
#define mat2 float2x2 | |
#define mat3 float3x3 | |
#define mat4 float4x4 | |
#define fract frac | |
#define mix lerp | |
#define iTime Time.x | |
#define iResolution ViewSize | |
uniform float4x4 ViewProj< | |
bool automatic = true; | |
>; | |
uniform float4 Time< | |
bool automatic = true; | |
>; | |
uniform float4 ViewSize< | |
bool automatic = true; | |
>; | |
uniform texture2d InputA< | |
bool automatic = true; | |
>; | |
//inputs | |
uniform float AMT< | |
string name = "Amount"; | |
string field_type = "slider"; | |
float minimum = 0.0; | |
float maximum = 1.0; | |
float step = 0.01; | |
> = 0.2; //0 - 1 glitch amount | |
uniform float SPEED< | |
string name = "Speed"; | |
string field_type = "slider"; | |
float minimum = 0.0; | |
float maximum = 1.0; | |
float step = 0.01; | |
> = 0.6; //0 - 1 speed | |
sampler_state textureSampler { | |
Filter = Point; | |
AddressU = Clamp; | |
AddressV = Clamp; | |
}; | |
/*ps start*/ | |
//2D (returns 0 - 1) | |
float random2d(vec2 n) { | |
return fract(sin(dot(n, vec2(12.9898, 4.1414))) * 43758.5453); | |
} | |
float randomRange (in vec2 seed, in float min, in float max) { | |
return min + random2d(seed) * (max - min); | |
} | |
// return 1 if v inside 1d range | |
float insideRange(float v, float bottom, float top) { | |
return step(bottom, v) - step(top, v); | |
} | |
void mainImage( out vec4 fragColor, in vec2 fragCoord ) | |
{ | |
float time = floor(iTime * SPEED * 60.0); | |
vec2 uv = fragCoord.xy / iResolution.xy; | |
//copy orig | |
vec3 outCol = InputA.Sample(textureSampler, uv).xyz; | |
//randomly offset slices horizontally | |
float maxOffset = AMT/2.0; | |
for (float i = 0.0; i < 10.0 * AMT; i += 1.0) { | |
float sliceY = random2d(vec2(time , 2345.0 + float(i))); | |
float sliceH = random2d(vec2(time , 9035.0 + float(i))) * 0.25; | |
float hOffset = randomRange(vec2(time , 9625.0 + float(i)), -maxOffset, maxOffset); | |
vec2 uvOff = uv; | |
uvOff.x += hOffset; | |
if (insideRange(uv.y, sliceY, fract(sliceY+sliceH)) == 1.0 ){ | |
outCol = InputA.Sample(textureSampler, uvOff).xyz; | |
} | |
} | |
//do slight offset on one entire channel | |
float maxColOffset = AMT/6.0; | |
float rnd = random2d(vec2(time , 9545.0)); | |
vec2 colOffset = vec2(randomRange(vec2(time , 9545.0),-maxColOffset,maxColOffset), | |
randomRange(vec2(time , 7205.0),-maxColOffset,maxColOffset)); | |
if (rnd < 0.33){ | |
outCol.x = InputA.Sample(textureSampler, uv + colOffset).x; | |
}else if (rnd < 0.66){ | |
outCol.y = InputA.Sample(textureSampler, uv + colOffset).y; | |
} else{ | |
outCol.z = InputA.Sample(textureSampler, uv + colOffset).z; | |
} | |
fragColor = vec4(outCol,1.0); | |
} | |
/*ps end*/ | |
struct VertFragData { | |
float4 pos : POSITION; | |
float2 uv : TEXCOORD0; | |
}; | |
VertFragData VSDefault(VertFragData vtx) { | |
vtx.pos = mul(float4(vtx.pos.xyz, 1.0), ViewProj); | |
return vtx; | |
} | |
float4 PSDefault(VertFragData vtx) : TARGET { | |
float4 col = float4(1., 1., 1., 1.); | |
mainImage(col, vtx.uv * ViewSize.xy); | |
return col; | |
} | |
technique Draw | |
{ | |
pass | |
{ | |
vertex_shader = VSDefault(vtx); | |
pixel_shader = PSDefault(vtx); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment