Skip to content

Commit c23449a

Browse files
Features- Dithering and CRT Filters (#6)
* Adds CRT and Dithering filters.
1 parent 8a5bf53 commit c23449a

31 files changed

+3125
-50
lines changed

CMakeLists.txt

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ else()
99
cmake_minimum_required(VERSION 3.18)
1010
endif()
1111

12-
project(obs-retro-effects VERSION 0.0.3)
12+
project(obs-retro-effects VERSION 0.0.4)
1313
set(PROJECT_FULL_NAME "Retro Effects")
1414

1515
# Set new UUIDs when you start to create a new plugin.
@@ -28,8 +28,16 @@ target_sources(${PROJECT_NAME} PRIVATE
2828
src/obs-retro-effects.h
2929
src/obs-utils.c
3030
src/obs-utils.h
31+
src/blur/blur.c
32+
src/blur/blur.h
33+
src/blur/gaussian-kernel.c
34+
src/blur/gaussian-kernel.h
3135
src/filters/chromatic-aberration.c
3236
src/filters/chromatic-aberration.h
37+
src/filters/crt.c
38+
src/filters/crt.h
39+
src/filters/dither.c
40+
src/filters/dither.h
3341
src/filters/frame-skip.c
3442
src/filters/frame-skip.h
3543
src/filters/interlace.c

buildspec.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,5 +79,5 @@
7979
}
8080
},
8181
"name": "obs-retro-effects",
82-
"version": "0.0.3"
82+
"version": "0.0.4"
8383
}

data/images/crt-phosphers-light.png

145 Bytes
Loading

data/images/crt-phosphers.png

140 Bytes
Loading

data/locale/en-US.ini

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ RetroEffects.Posterize.Color2="Color 2"
88
RetroEffects.Posterize.Technique="Color Handling"
99
RetroEffects.Posterize.Passthrough="Passthrough Colors"
1010
RetroEffects.Posterize.ColorMap="Map Colors"
11+
RetroEffects.Posterize.SourceColorMap="Source Map Colors"
12+
RetroEffects.Posterize.MapSource="Source"
13+
RetroEffects.Posterize.MapSource.None="None"
1114
RetroEffects.FrameSkip.NumFrames="Frames To Skip"
1215
RetroEffects.ChromaticAberration="Chromatic Aberration"
1316
RetroEffects.CA.Type="Type"
@@ -19,3 +22,30 @@ RetroEffects.CA.GreenOffset="Green Offset"
1922
RetroEffects.CA.GreenOffsetAngle="Green Offset Angle"
2023
RetroEffects.CA.BlueOffset="Blue Offset"
2124
RetroEffects.CA.BlueOffsetAngle="Blue Offset Angle"
25+
RetroEffects.Dither="Dither"
26+
RetroEffects.Dither.Size="Dither Size"
27+
RetroEffects.Dither.Contrast="Contrast Adjustment"
28+
RetroEffects.Dither.Gamma="Gamma Adjustment"
29+
RetroEffects.Dither.OffsetX="Offset X"
30+
RetroEffects.Dither.OffsetY="Offset Y"
31+
RetroEffects.Dither.ColorSteps="Colors Per Channel"
32+
RetroEffects.Dither.Monochromatic="Monochromatic?"
33+
RetroEffects.Dither.Type="Dither Type"
34+
RetroEffects.Dither.Ordered="Ordered"
35+
RetroEffects.Dither.Unordered="Unordered"
36+
RetroEffects.Dither.BayerSize="Bayer Matrix Size"
37+
RetroEffects.CRT="CRT"
38+
RetroEffects.CRT.PhosphorBloom="Phosphor Bloom"
39+
RetroEffects.CRT.BloomSize="Bloom Size"
40+
RetroEffects.CRT.BloomThreshold="Threshold"
41+
RetroEffects.CRT.BloomIntensity="Intensity"
42+
RetroEffects.CRT.PhosphorMask="Phosphor Mask"
43+
RetroEffects.CRT.PhosphorLayout="Phosphor Layout"
44+
RetroEffects.CRT.PhoshporMaskIntensity="Intesity"
45+
RetroEffects.CRT.CornerRadius="Corner Radius"
46+
RetroEffects.CRT.BarrelDistortion="Barrel Distortion"
47+
RetroEffects.CRT.Vignette="Vignette Amount"
48+
RetroEffects.CRT.Geometry="CRT Geometry"
49+
RetroEffects.CRT.ColorCorrection="Color Correction"
50+
RetroEffects.CRT.BlackLevel="Black Level"
51+
RetroEffects.CRT.WhiteLevel="White Level"

data/shaders/chromatic-aberration.effect

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ float4 mainImage(VertData v_in) : TARGET
4040
float4 mainImageLens(VertData v_in) : TARGET
4141
{
4242
float2 coord = v_in.uv * uv_size;
43-
float dist = abs((coord - uv_size * 0.5) * scale);
43+
float2 dist = abs((coord - uv_size * 0.5) * scale);
4444

4545
float2 diff = dist * normalize(v_in.uv - float2(0.5, 0.5));
4646

data/shaders/crt-composite.effect

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
uniform float4x4 ViewProj;
2+
uniform texture2d image;
3+
uniform texture2d blur_image;
4+
uniform float brightness;
5+
uniform float black_level;
6+
uniform float white_level;
7+
uniform float dist;
8+
9+
#define EPS 1.e-8
10+
11+
sampler_state textureSampler{
12+
Filter = Linear;
13+
AddressU = Clamp;
14+
AddressV = Clamp;
15+
MinLOD = 0;
16+
MaxLOD = 0;
17+
};
18+
19+
struct VertData
20+
{
21+
float4 pos : POSITION;
22+
float2 uv : TEXCOORD0;
23+
};
24+
25+
VertData mainTransform(VertData v_in)
26+
{
27+
v_in.pos = mul(float4(v_in.pos.xyz, 1.0), ViewProj);
28+
return v_in;
29+
}
30+
31+
float4 mainImage(VertData v_in) : TARGET
32+
{
33+
// Barrel Distortion
34+
float2 uv = v_in.uv * 2. - 1.;
35+
float r_pixel_2 = uv.x * uv.x + uv.y * uv.y;
36+
float barrel = r_pixel_2 * dist;
37+
uv = (barrel > EPS) ? 0.5 * ((uv / barrel * (1. - sqrt(1. - 2. * barrel))) + 1.) : v_in.uv;
38+
39+
// Anti-alias barrel distortion edges
40+
float d = min(min(uv.x, 1. - uv.x), min(uv.y, 1. - uv.y));
41+
float w = length(float2(ddx(d), ddy(d)));
42+
float aa_mask = smoothstep(-0.7, 0.7, (abs(frac(d - 0.25) - 0.5) - 0.25) / w);
43+
44+
float4 color = image.Sample(textureSampler, uv);
45+
float4 blur_color = blur_image.Sample(textureSampler, uv);
46+
// Brightness correction on bloom/blur layer
47+
//blur_color.rgb *= brightness;
48+
float threshold = brightness;
49+
float4 highlight = saturate(blur_color - threshold) * 1.0 / (1.0 - threshold);
50+
// Screen Blending between main color layer and bloom/blur layer
51+
color.rgb = 1.0 - (1.0 - color.rgb) * (1.0 - highlight.rgb);
52+
// Apply black/white levels correction
53+
color.rgb = saturate((color.rgb - black_level) / (white_level - black_level));
54+
// Apply barrel disortion anti-alias mask to alpha channel
55+
color.a *= aa_mask;
56+
return color;
57+
}
58+
59+
technique Draw
60+
{
61+
pass
62+
{
63+
vertex_shader = mainTransform(v_in);
64+
pixel_shader = mainImage(v_in);
65+
}
66+
}

0 commit comments

Comments
 (0)