Skip to content

Commit fe4fe0f

Browse files
committed
update shaders for opengl
1 parent 1f6b925 commit fe4fe0f

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+534
-263
lines changed

CMakeLists.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ else()
66
cmake_minimum_required(VERSION 3.18)
77
endif()
88

9-
project(obs-shaderfilter VERSION 1.21.2)
9+
project(obs-shaderfilter VERSION 1.21.3)
1010
set(PROJECT_FULL_NAME "OBS Shaderfilter")
1111

1212
# Set new UUIDs when you start to create a new plugin.

buildspec.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -79,5 +79,5 @@
7979
}
8080
},
8181
"name": "obs-shaderfilter",
82-
"version": "1.21.2"
82+
"version": "1.21.3"
8383
}

data/examples/Luminance.shader

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
//Converted to OpenGL by Exeldro February 22, 2022
12
uniform float4 color;
23
uniform float level = 10;
34
uniform bool invertImageColor;
@@ -25,7 +26,7 @@ float4 mainImage(VertData v_in) : TARGET
2526
{
2627
rgba = InvertColor(rgba);
2728
}
28-
float intensity = dot(rgba * color, float3(0.299, 0.587, 0.114));
29+
float intensity = rgba.r * color.r * 0.299 + rgba.g * color.g * 0.587 + rgba.b * color.b * 0.114;
2930

3031
//intensity = min(max(intensity,minIntensity),maxIntensity);
3132

data/examples/VCR.shader

+10-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
//based on https://www.shadertoy.com/view/ldjGzV
2+
//Converted to OpenGL by Exeldro February 19, 2022
23
uniform float vertical_shift = 0.4;
34
uniform float distort = 1.2;
45
uniform float vignet = 1.0;
@@ -19,19 +20,24 @@ float ramp(float y, float start, float end)
1920

2021
}
2122

23+
float modu(float x, float y)
24+
{
25+
return (x / y) - floor(x / y);
26+
}
27+
2228
float stripes(float2 uv)
2329
{
24-
return ramp((uv.y*4. + elapsed_time/2.+sin(elapsed_time + sin(elapsed_time*0.63))%1.),0.5,0.6)*stripe;
30+
return ramp(modu(uv.y*4. + elapsed_time/2.+sin(elapsed_time + sin(elapsed_time*0.63)),1.),0.5,0.6)*stripe;
2531
}
2632

2733
float4 getVideo(float2 uv)
2834
{
2935
float2 look = uv;
30-
float window = 1./(1.+20.*(look.y-((elapsed_time/4.)%1.))*(look.y-((elapsed_time/4.)%1.)));
36+
float window = 1./(1.+20.*(look.y-modu(elapsed_time/4.,1.))*(look.y-modu(elapsed_time/4.,1.)));
3137
look.x = look.x + sin(look.y*10. + elapsed_time)/50.*onOff(4.,4.,.3)*(1.+cos(elapsed_time*80.))*window;
3238
float vShift = vertical_shift*onOff(2.,3.,.9)*(sin(elapsed_time)*sin(elapsed_time*20.) +
3339
(0.5 + 0.1*sin(elapsed_time*200.)*cos(elapsed_time)));
34-
look.y = ((look.y + vShift) % 1.);
40+
look.y = modu((look.y + vShift) , 1.);
3541
return image.Sample(textureSampler, look);
3642
}
3743

@@ -52,6 +58,6 @@ float4 mainImage(VertData v_in) : TARGET
5258
float vignette = ((1.-vigAmt*(uv.y-.5)*(uv.y-.5))*(1.-vigAmt*(uv.x-.5)*(uv.x-.5))-1.)*vignet+1.;
5359
video += stripes(uv);
5460
video *= vignette;
55-
video *= (((12.+((uv.y*vertical_height+elapsed_time)%1.))/13.)-1.)*vertical_factor+1.;
61+
video *= (((12.+modu((uv.y*vertical_height+elapsed_time),1.))/13.)-1.)*vertical_factor+1.;
5662
return float4(video.r, video.g, video.b ,1.0);
5763
}

data/examples/VHS.shader

+47-4
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,22 @@
1-
//based on https://www.shadertoy.com/view/Ms3XWH
1+
//based on https://www.shadertoy.com/view/Ms3XWH converted by Exeldro v 1.0
2+
//updated by Charles 'Surn' Fettinger for obs-shaderfilter 9/2020
3+
//Converted to OpenGL by Exeldro February 19, 2022
24
uniform float range = 0.05;
35
uniform float noiseQuality = 250.0;
46
uniform float noiseIntensity = 0.88;
57
uniform float offsetIntensity = 0.02;
68
uniform float colorOffsetIntensity = 1.3;
9+
uniform float lumaMin = 0.01;
10+
uniform float lumaMinSmooth = 0.04;
11+
uniform float Alpha_Percentage = 100; //<Range(0.0,100.0)>
12+
uniform bool Apply_To_Image;
13+
uniform bool Replace_Image_Color;
14+
uniform float4 Color_To_Replace;
15+
uniform bool Apply_To_Specific_Color;
16+
17+
float dot(float2 a,float2 b){
18+
return a.x*b.x+a.y*b.y;
19+
}
720

821
float rand(float2 co)
922
{
@@ -20,12 +33,21 @@ float verticalBar(float pos, float uvY, float offset)
2033
return x;
2134
}
2235

36+
float modu(float x, float y)
37+
{
38+
return (x / y) - floor(x / y);
39+
}
40+
41+
float dot(float4 a,float4 b){
42+
return a.r*b.r+a.g*b.g+a.b*b.b+a.a*b.a;
43+
}
44+
2345
float4 mainImage(VertData v_in) : TARGET
2446
{
2547
float2 uv = v_in.uv;
2648
for (float i = 0.0; i < 0.71; i += 0.1313)
2749
{
28-
float d = (elapsed_time * i) % 1.7;
50+
float d = modu(elapsed_time * i, 1.7);
2951
float o = sin(1.0 - tan(elapsed_time * 0.24 * i));
3052
o *= offsetIntensity;
3153
uv.x += verticalBar(d, uv.y, o);
@@ -43,6 +65,27 @@ float4 mainImage(VertData v_in) : TARGET
4365
float g = image.Sample(textureSampler, uv + offsetG).g;
4466
float b = image.Sample(textureSampler, uv).b;
4567

46-
float4 output = float4(r, g, b, 1.0);
47-
return output;
68+
float4 rgba = float4(r, g, b, 1.0);
69+
70+
float4 color;
71+
float4 original_color;
72+
if (Apply_To_Image)
73+
{
74+
color = image.Sample(textureSampler, v_in.uv);
75+
original_color = color;
76+
float luma = dot(color, float4(0.30, 0.59, 0.11, 1.0));
77+
if (Replace_Image_Color)
78+
color = float4(luma,luma,luma,luma);
79+
rgba = lerp(original_color, rgba * color, clamp(Alpha_Percentage * .01, 0, 1.0));
80+
81+
}
82+
if (Apply_To_Specific_Color)
83+
{
84+
color = image.Sample(textureSampler, v_in.uv);
85+
original_color = color;
86+
color = (distance(color.rgb, Color_To_Replace.rgb) <= 0.075) ? rgba : color;
87+
rgba = lerp(original_color, color, clamp(Alpha_Percentage * .01, 0, 1.0));
88+
}
89+
90+
return rgba;
4891
}

data/examples/animated_path.effect

+7-6
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
// Path effect By Charles Fettinger (https://github.com/Oncorporation) 3/2019
2+
//Converted to OpenGL by Q-mii & Exeldro February 24, 2022
23
uniform float4x4 ViewProj;
34
uniform texture2d image;
45

@@ -24,11 +25,11 @@ struct VertData {
2425
float2 uv : TEXCOORD0;
2526
};
2627

27-
float4 convert_pmalpha(float4 color)
28+
float4 convert_pmalpha(float4 c)
2829
{
29-
float4 ret = color;
30-
if (color.a >= 0.001)
31-
ret.xyz /= color.a;
30+
float4 ret = c;
31+
if (c.a >= 0.001)
32+
ret.xyz /= c.a;
3233
else
3334
ret = float4(0.0, 0.0, 0.0, 0.0);
3435
return ret;
@@ -39,7 +40,7 @@ VertData mainTransform(VertData v_in)
3940
VertData vert_out;
4041
float3 pos = v_in.pos.xyz;
4142
float3 current_pos;
42-
float speed = (float)speed_percent * 0.01;
43+
float speed = speed_percent * 0.01;
4344
//vert_out.pos = mul(float4(v_in.pos.xyz, 1.0), ViewProj);
4445
float t = 1.0 + sin(elapsed_time * speed) ;
4546
// combine luma texture and user defined shine color
@@ -60,7 +61,7 @@ VertData mainTransform(VertData v_in)
6061
if (speed == 0.0f)
6162
{
6263
offset.x = 0.0f;
63-
offset.y = 0.0f
64+
offset.y = 0.0f;
6465
}
6566
else
6667
{

data/examples/animated_texture.effect

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Animated Texture By Charles Fettinger (https://github.com/Oncorporation) 3/2020
22
// Animates a texture with polar sizing and color options
33
// for use with obs-shaderfilter 1.0
4-
4+
//Converted to OpenGL by Q-mii & Exeldro February 24, 2022
55
uniform float4x4 ViewProj;
66
uniform texture2d image;
77

@@ -101,7 +101,7 @@ float4 mainImage(VertData v_in) : TARGET
101101
float2 tint_speed_dir = float2(tint_speed_horizontal_percent * 0.01, tint_speed_vertical_percent * 0.01);
102102

103103
//compensate for background vertex shader values
104-
float2 background_offset = -.5f;
104+
float2 background_offset = float2(-.5,-.5);
105105
if (!center_animation)
106106
background_offset = time(speed_dir);
107107
float4 rgba = image.Sample(textureSampler, v_in.uv - background_offset); //float4(0.0,0.0,0.0,0.01);

data/examples/aspect_ratio.shader

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
//Converted to OpenGL by Q-mii & Exeldro March 8, 2022 - DO NOT USE THIS IT WAS NEVER COMPLETED
12
uniform float4x4 ViewProj;
23
uniform texture2d image;
34

@@ -10,7 +11,7 @@ uniform float2 uv_size;
1011

1112

1213
// variables
13-
uniform float4 borderColor = 00000000;
14+
uniform float4 borderColor = {0,0,0,0};
1415
float targetaspect = 16.0f / 9.0f;
1516
uniform string notes;
1617

@@ -35,7 +36,7 @@ VertData mainTransform(VertData v_in)
3536

3637
float2 hw = uv_scale;
3738
// determine the game window's current aspect ratio
38-
float windowaspect = hw.h / hw.w;
39+
float windowaspect = hw.x / hw.y;
3940

4041
// current viewport height should be scaled by this amount
4142
float scaleheight = windowaspect / targetaspect;

data/examples/background_removal.effect

+11-6
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
// background removal effect By Charles Fettinger (https://github.com/Oncorporation) 4/2019
2+
//Converted to OpenGL by Exeldro February 19, 2022
23
uniform float4x4 ViewProj;
34
uniform texture2d image;
45

@@ -35,6 +36,10 @@ struct VertDataOut {
3536
float2 uv2 : TEXCOORD1;
3637
};
3738

39+
float dot(float3 a,float3 b){
40+
return a.x*b.x+a.y*b.y+a.z*b.z;
41+
}
42+
3843
//BT.601 to BT.709
3944
// Correct video colorspace BT.601 [SD] to BT.709 [HD] for HD video input
4045
// Use this shader only if BT.709 [HD] encoded video is incorrectly matrixed to full range RGB with the BT.601 [SD] colorspace.
@@ -56,7 +61,7 @@ float4 Convert709to601(float4 rgba)
5661
VertDataOut VSDefault(VertDataIn v_in)
5762
{
5863
VertDataOut vert_out;
59-
vert_out.pos = mul(float4(v_in.pos.xyz, 1.0), ViewProj);
64+
vert_out.pos = mul(float4(v_in.pos.x, v_in.pos.y, v_in.pos.z, 1.0), ViewProj);
6065
vert_out.uv = v_in.uv;
6166
vert_out.uv2 = v_in.uv * uv_scale + uv_offset;
6267
return vert_out;
@@ -73,14 +78,14 @@ float4 PSColorMaskRGBA(VertDataOut v_in) : TARGET
7378
}
7479
if (Convert_709to601)
7580
{
76-
rgba.rgb = Convert709to601(rgba);
77-
targetRGB.rgb = Convert709to601(targetRGB);
81+
rgba.rgb = Convert709to601(rgba).rgb;
82+
targetRGB.rgb = Convert709to601(targetRGB).rgb;
7883
}
7984

8085
if (Convert_601to709)
8186
{
82-
rgba.rgb = Convert601to709(rgba);
83-
targetRGB.rbg = Convert601to709(targetRGB);
87+
rgba.rgb = Convert601to709(rgba).rgb;
88+
targetRGB.rbg = Convert601to709(targetRGB).rgb;
8489
}
8590

8691
float4 shadowRGB = targetRGB * targetRGB;
@@ -92,7 +97,7 @@ float4 PSColorMaskRGBA(VertDataOut v_in) : TARGET
9297
abs(shadowRGB.g - rgba.g) <= Tolerance &&
9398
abs(shadowRGB.b - rgba.b) <= Tolerance))
9499
{
95-
rgba.rgba = 0;
100+
rgba.rgba = float4(0,0,0,0);
96101
}
97102
return rgba;
98103
}

data/examples/blend_opacity.shader

+8-10
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
// opaicty blend shader by Charles Fettinger for obs-shaderfilter plugin 3/2019
1+
// opacity blend shader by Charles Fettinger for obs-shaderfilter plugin 3/2019
22
//https://github.com/Oncorporation/obs-shaderfilter
3+
//Converted to OpenGL by Exeldro February 14, 2022
34
uniform bool Vertical;
45
uniform bool Rotational;
56
uniform float Rotation_Offset = 0.0; //<Range(0.0, 6.28318531)>
@@ -12,18 +13,15 @@ uniform string Notes = "Spread is wideness of opacity blend and is limited betwe
1213

1314
float4 mainImage(VertData v_in) : TARGET
1415
{
15-
const float PI = 3.14159265f;//acos(-1);
16-
17-
18-
float4 color = image.Sample(textureSampler, v_in.uv);
19-
float luminance = dot(color, float3(0.299, 0.587, 0.114));
20-
float4 gray = {luminance,luminance,luminance, 1};
16+
float4 point_color = image.Sample(textureSampler, v_in.uv);
17+
float luminance = 0.299*point_color.r+0.587*point_color.g+0.114*point_color.b;
18+
float4 gray = float4(luminance,luminance,luminance, 1);
2119

2220
float2 lPos = (v_in.uv * uv_scale + uv_offset) / clamp(Spread, 0.25, 10.0);
2321
float time = (elapsed_time * clamp(Speed, -5.0, 5.0)) / clamp(Spread, 0.25, 10.0);
2422
float dist = distance(v_in.uv , (float2(0.99, 0.99) * uv_scale + uv_offset));
2523

26-
if (color.a > 0.0 || Apply_To_Alpha_Layer == false)
24+
if (point_color.a > 0.0 || Apply_To_Alpha_Layer == false)
2725
{
2826
//set opacity and direction
2927
float opacity = (-1 * lPos.x) * 0.5;
@@ -43,9 +41,9 @@ float4 mainImage(VertData v_in) : TARGET
4341

4442
opacity += time;
4543
opacity = frac(opacity);
46-
color.a = lerp(Opacity_Start_Percent * 0.01, Opacity_End_Percent * 0.01, clamp(opacity, 0.0, 1.0));
44+
point_color.a = lerp(Opacity_Start_Percent * 0.01, Opacity_End_Percent * 0.01, clamp(opacity, 0.0, 1.0));
4745
}
48-
return color;
46+
return point_color;
4947
}
5048

5149

data/examples/bloom.shader

+11-12
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,41 @@
1-
21
// Bloom shader by Charles Fettinger for obs-shaderfilter plugin 3/2019
3-
//https://github.com/Oncorporation/obs-shaderfilter
4-
2+
//https://github.com/Oncorporation/obs-shaderfilter
3+
//Converted to OpenGL by Exeldro February 15, 2022
54
uniform int Angle_Steps = 5; //<range 1 - 20>
65
uniform int Radius_Steps = 9; //<range 0 - 20>
76
uniform float ampFactor = 2.0;
87
uniform string notes = "Steps limited in range from 0 to 20. Edit bloom.shader to remove limits at your own risk.";
98

109
float4 mainImage(VertData v_in) : TARGET
1110
{
12-
float radiusSteps = clamp(Radius_Steps, 0, 20);
13-
float angleSteps = clamp(Angle_Steps, 1, 20);
11+
int radiusSteps = clamp(Radius_Steps, 0, 20);
12+
int angleSteps = clamp(Angle_Steps, 1, 20);
1413
float PI = 3.1415926535897932384626433832795;//acos(-1);
1514
float minRadius = (0.0 * uv_pixel_interval.y);
1615
float maxRadius = (10.0 * uv_pixel_interval.y);
1716

1817
float4 c0 = image.Sample(textureSampler, v_in.uv);
1918
float4 outputPixel = c0;
20-
float4 accumulatedColor = {0,0,0,0};
19+
float4 accumulatedColor = float4(0,0,0,0);
2120

2221
int totalSteps = radiusSteps * angleSteps;
23-
float angleDelta = (2 * PI) / angleSteps;
24-
float radiusDelta = (maxRadius - minRadius) / radiusSteps;
22+
float angleDelta = (2.0 * PI) / float(angleSteps);
23+
float radiusDelta = (maxRadius - minRadius) / float(radiusSteps);
2524

2625
for (int radiusStep = 0; radiusStep < radiusSteps; radiusStep++) {
27-
float radius = minRadius + radiusStep * radiusDelta;
26+
float radius = minRadius + float(radiusStep) * radiusDelta;
2827

29-
for (float angle=0; angle <(2*PI); angle += angleDelta) {
28+
for (float angle=0.0; angle <(2.0*PI); angle += angleDelta) {
3029
float2 currentCoord;
3130

3231
float xDiff = radius * cos(angle);
3332
float yDiff = radius * sin(angle);
3433

3534
currentCoord = v_in.uv + float2(xDiff, yDiff);
3635
float4 currentColor =image.Sample(textureSampler, currentCoord);
37-
float currentFraction = ((float)(radiusSteps+1 - radiusStep)) / (radiusSteps + 1);
36+
float currentFraction = float(radiusSteps+1 - radiusStep) / float(radiusSteps + 1);
3837

39-
accumulatedColor += currentFraction * currentColor / totalSteps;
38+
accumulatedColor += currentFraction * currentColor / float(totalSteps);
4039

4140
}
4241
}

0 commit comments

Comments
 (0)