Skip to content

Commit

Permalink
Feature/digital glitch (#31)
Browse files Browse the repository at this point in the history
* Adds digital glitch effect
  • Loading branch information
FiniteSingularity authored May 25, 2024
1 parent a9993e1 commit f7ba2ac
Show file tree
Hide file tree
Showing 9 changed files with 644 additions and 5 deletions.
4 changes: 3 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ else()
cmake_minimum_required(VERSION 3.18)
endif()

project(obs-retro-effects VERSION 0.0.9)
project(obs-retro-effects VERSION 0.0.10)
set(PROJECT_FULL_NAME "Retro Effects")

# Set new UUIDs when you start to create a new plugin.
Expand Down Expand Up @@ -44,6 +44,8 @@ target_sources(${PROJECT_NAME} PRIVATE
src/filters/crt.h
src/filters/codec.c
src/filters/codec.h
src/filters/digital-glitch.c
src/filters/digital-glitch.h
src/filters/dither.c
src/filters/dither.h
src/filters/frame-skip.c
Expand Down
2 changes: 1 addition & 1 deletion buildspec.json
Original file line number Diff line number Diff line change
Expand Up @@ -79,5 +79,5 @@
}
},
"name": "obs-retro-effects",
"version": "0.0.9"
"version": "0.0.10"
}
17 changes: 16 additions & 1 deletion data/locale/en-US.ini
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,6 @@ RetroEffects.VHS.Jitter.MinPeriod="Min Period"
RetroEffects.VHS.Jitter.MaxPeriod="Max Period"
RetroEffects.VHS.Jitter.MinInterval="Min Interval"
RetroEffects.VHS.Jitter.MaxInterval="Max Interval"

RetroEffects.Bloom="Bloom"
RetroEffects.Bloom.Intensity="Intensity"
RetroEffects.Bloom.Size="Size"
Expand All @@ -154,3 +153,19 @@ RetroEffects.Scanlines.Profile.Square="Square"
RetroEffects.Scanlines.Profile.SawTooth="Saw-Tooth"
RetroEffects.Scanlines.Profile.SmoothStep="Smooth Step"
RetroEffects.Scanlines.Profile.Triangular="Triangular"
RetroEffects.DigitalGlitch="Digital Glitch"
RetroEffects.DigitalGlitch.Amount="Amount"
RetroEffects.DigitalGlitch.Displacement="Displacement"
RetroEffects.DigitalGlitch.MaxDisplacement="Max Displacement"
RetroEffects.DigitalGlitch.MinBlockWidth="Min Block Width"
RetroEffects.DigitalGlitch.MaxBlockWidth="Max Block Width"
RetroEffects.DigitalGlitch.MinBlockHeight="Min Block Height"
RetroEffects.DigitalGlitch.MaxBlockHeight="Max Block Height"
RetroEffects.DigitalGlitch.MinBlockInterval="Min Interval"
RetroEffects.DigitalGlitch.MaxBlockInterval="Max Interval"
RetroEffects.DigitalGlitch.RGBDrift="Color Drift"
RetroEffects.DigitalGlitch.MaxRGBDrift="Max Drift Distance"
RetroEffects.DigitalGlitch.MinRGBHeight="Min Height"
RetroEffects.DigitalGlitch.MaxRGBHeight="Max Height"
RetroEffects.DigitalGlitch.MinRGBInterval="Min Interval"
RetroEffects.DigitalGlitch.MaxRGBInterval="Max Interval"
71 changes: 71 additions & 0 deletions data/shaders/digital-glitch.effect
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
uniform float4x4 ViewProj;
uniform texture2d image;
uniform texture2d vert_grid;
uniform texture2d horiz_grid;
uniform texture2d rgb_drift_grid;
uniform float2 uv_size;
uniform float time;
uniform float max_disp;
uniform float max_rgb_drift;
uniform float amount;

#include "noise-functions.effect"

sampler_state textureSampler{
Filter = Linear;
AddressU = Clamp;
AddressV = Clamp;
MinLOD = 0;
MaxLOD = 0;
};

float digitalNoise(float2 loc)
{
// Get a noise value in [-1, 1]
float n1 = 2.0 * vert_grid.Sample(textureSampler, float2(0.0, loc.y)).r - 1.0;
float n2 = 2.0 * horiz_grid.Sample(textureSampler, float2(loc.x, 0.0)).r -1.0;
n1 = abs(n1) > amount ? 0.0 : n1;
n2 = abs(n2) > amount ? 0.0 : n2;
return n1 * n2;
}

float rgb_drift(float2 loc)
{
float n = 2.0 * rgb_drift_grid.Sample(textureSampler, float2(0.0, loc.y)).r - 1.0;
return abs(n) > amount ? 0.0 : n;

}

struct VertData
{
float4 pos : POSITION;
float2 uv : TEXCOORD0;
};

VertData mainTransform(VertData v_in)
{
v_in.pos = mul(float4(v_in.pos.xyz, 1.0), ViewProj);
return v_in;
}

float4 mainImage(VertData v_in) : TARGET
{
float2 coord = v_in.uv * uv_size;
//float amount = 0.2 + 0.3 * pow(sin(time * 1.2), 5.0);
float block_disp = digitalNoise(v_in.uv) * max_disp;
float rgb_disp = rgb_drift(v_in.uv) * max_rgb_drift;
float4 col_r = image.Sample(textureSampler, float2(coord.x + block_disp + rgb_disp, coord.y) / uv_size);
float4 col_g = image.Sample(textureSampler, float2(coord.x + block_disp, coord.y)/uv_size);
float4 col_b = image.Sample(textureSampler, float2(coord.x + block_disp - rgb_disp, coord.y) / uv_size);
float alpha = 0.334 * col_r.a + 0.333 * col_g.a + 0.333 * col_b.a;
return float4(col_r.r, col_g.g, col_b.b, alpha);
}

technique Draw
{
pass
{
vertex_shader = mainTransform(v_in);
pixel_shader = mainImage(v_in);
}
}
Loading

0 comments on commit f7ba2ac

Please sign in to comment.