Created
October 9, 2018 14:29
-
-
Save AtomicBlom/b21fd40c2c538b1c2b5ab0eed1fae8d6 to your computer and use it in GitHub Desktop.
Pixelate effect for OBS Study (obs-shaderfilter plugin)
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
//----------------------------------------------------------------------------------------- | |
// Shader constant register mappings (scalars - float, double, Point, Color, Point3D, etc.) | |
//----------------------------------------------------------------------------------------- | |
uniform float horizontal_pixel_counts; | |
uniform float vertical_pixel_counts; | |
uniform float speed; | |
//-------------------------------------------------------------------------------------- | |
// Sampler Inputs (Brushes, including ImplicitInput) | |
//-------------------------------------------------------------------------------------- | |
//-------------------------------------------------------------------------------------- | |
// Pixel Shader | |
//-------------------------------------------------------------------------------------- | |
//float4 main(float2 uv : TEXCOORD) : COLOR | |
float4 mainImage(VertData v_in) : TARGET | |
{ | |
float2 brickCounts = { horizontal_pixel_counts, vertical_pixel_counts }; | |
float2 brickSize = 1.0 / brickCounts; | |
// Offset every other row of bricks | |
float2 offsetuv = v_in.uv; | |
float t = elapsed_time * speed; | |
float time_offset = sin(t); | |
float2 brickNum = floor(offsetuv / brickSize); | |
float2 centerOfBrickA = (brickNum + (0.5 + time_offset) / 2.5) * brickSize + brickSize / 2; | |
float2 centerOfBrickB = (brickNum + (0.5 + time_offset) / 2.5) * brickSize + brickSize / 2; | |
float4 colorA = image.Sample(textureSampler, centerOfBrickA); | |
float4 colorB = image.Sample(textureSampler, centerOfBrickA); | |
return float4( | |
lerp(colorA.r, colorB.r, time_offset), | |
lerp(colorA.g, colorB.g, time_offset), | |
lerp(colorA.b, colorB.b, time_offset), | |
lerp(colorA.a, colorB.a, time_offset) | |
); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment