-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathobs-xbrz-linux.effect
125 lines (98 loc) · 3.9 KB
/
obs-xbrz-linux.effect
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
uniform float4x4 ViewProj;
uniform texture2d image;
uniform float elapsed_time;
uniform float2 uv_offset;
uniform float2 uv_scale;
uniform float2 uv_pixel_interval;
uniform float rand_f;
uniform float2 uv_size;
uniform float4x4 ViewProj;
uniform texture2d image;
uniform float elapsed_time;
uniform string notes = "Sharpness: -0.84, StartSmoothingWeight = 1, MinFilterWeight = 0, MaxFilterWeight = 1, Smoothing = 0, ScalingFactor = 0.25";
uniform float Sharpness = -0.25; // use positive values to get blurry pixels, use negative values to get clean smooth results
uniform float StartSmoothingWeight = 1.00; // start smoothing eight
uniform float MaxFilterWeight = 0.75; // max filter weigth
uniform float MinFilterWeight = 0.25; // min filter weigth
uniform float Smoothing = 0.33; // effects smoothing
uniform float ScalingFactor = 0.25; // donwsampling 4x in size
uniform float SamplingPointScale1 = 0.5;
sampler_state textureSampler {
Filter = Linear;
AddressU = Border;
AddressV = Border;
BorderColor = 00000000;
};
struct VertData {
float4 pos : POSITION;
float2 uv : TEXCOORD0;
};
VertData mainTransform(VertData v_in)
{
VertData vert_out;
vert_out.pos = mul(float4(v_in.pos.xyz, 1.0), ViewProj);
vert_out.uv = v_in.uv * uv_scale + uv_offset;
return vert_out;
}
float4 mainImage(VertData v_in) : TARGET
{
float2 uv = v_in.uv;
float4 color = image.Sample(textureSampler, v_in.uv );
float3 c = color.xyz;
float x = 0.5 * (1.0 / uv_size.x/ScalingFactor);
float y = 0.5 * (1.0 / uv_size.y/ScalingFactor);
const float3 dt = 1.0 * float3(1.0, 1.0, 1.0);
float2 dg1 = float2( x, y);
float2 dg2 = float2(x, -y);
float2 sd1 = dg1*SamplingPointScale1;
float2 sd2 = dg2*SamplingPointScale1;
float2 ddx = float2( x, 0.0);
float2 ddy = float2( 0.0, y);
float4 t1 = float4(uv-sd1,uv-ddy);
float4 t2 = float4(uv-sd2,uv+ddx);
float4 t3 = float4(uv+sd1,uv+ddy);
float4 t4 = float4(uv+sd2,uv-ddx);
float4 t5 = float4(uv-dg1,uv-dg2);
float4 t6 = float4(uv+dg1,uv+dg2);
float3 i1 = image.Sample(textureSampler, t1.xy).xyz;
float3 i2 = image.Sample(textureSampler, t2.xy).xyz;
float3 i3 = image.Sample(textureSampler, t3.xy).xyz;
float3 i4 = image.Sample(textureSampler, t4.xy).xyz;
float3 o1 = image.Sample(textureSampler, t5.xy).xyz;
float3 o3 = image.Sample(textureSampler, t6.xy).xyz;
float3 o2 = image.Sample(textureSampler, t5.zw).xyz;
float3 o4 = image.Sample(textureSampler, t6.zw).xyz;
float3 s1 = image.Sample(textureSampler, t1.zw).xyz;
float3 s2 = image.Sample(textureSampler, t2.zw).xyz;
float3 s3 = image.Sample(textureSampler, t3.zw).xyz;
float3 s4 = image.Sample(textureSampler, t4.zw).xyz;
float ko1 = dot(abs(o1-c),dt);
float ko2 = dot(abs(o2-c),dt);
float ko3 = dot(abs(o3-c),dt);
float ko4 = dot(abs(o4-c),dt);
float k1=min(dot(abs(i1-i3),dt),max(ko1,ko3));
float k2=min(dot(abs(i2-i4),dt),max(ko2,ko4));
float w1 = k2; if(ko3<ko1) w1*=ko3/ko1;
float w2 = k1; if(ko4<ko2) w2*=ko4/ko2;
float w3 = k2; if(ko1<ko3) w3*=ko1/ko3;
float w4 = k1; if(ko2<ko4) w4*=ko2/ko4;
c=(w1*o1+w2*o2+w3*o3+w4*o4+0.001*c)/(w1+w2+w3+w4+0.001);
w1 = Sharpness*dot(abs(i1-c)+abs(i3-c),dt)/(0.125*dot(i1+i3,dt)+Smoothing);
w2 = Sharpness*dot(abs(i2-c)+abs(i4-c),dt)/(0.125*dot(i2+i4,dt)+Smoothing);
w3 = Sharpness*dot(abs(s1-c)+abs(s3-c),dt)/(0.125*dot(s1+s3,dt)+Smoothing);
w4 = Sharpness*dot(abs(s2-c)+abs(s4-c),dt)/(0.125*dot(s2+s4,dt)+Smoothing);
w1 = clamp(w1+StartSmoothingWeight,MinFilterWeight,MaxFilterWeight);
w2 = clamp(w2+StartSmoothingWeight,MinFilterWeight,MaxFilterWeight);
w3 = clamp(w3+StartSmoothingWeight,MinFilterWeight,MaxFilterWeight);
w4 = clamp(w4+StartSmoothingWeight,MinFilterWeight,MaxFilterWeight);
color = float4((w1*(i1+i3)+w2*(i2+i4)+w3*(s1+s3)+w4*(s2+s4)+c)/(2.0*(w1+w2+w3+w4)+1.0), color.a);
return color;
}
technique Draw
{
pass
{
vertex_shader = mainTransform(v_in);
pixel_shader = mainImage(v_in);
}
}