File: glow_source.effect

package info (click to toggle)
obs-stroke-glow-shadow 1.5.2-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,376 kB
  • sloc: ansic: 3,316; sh: 153; makefile: 27; cpp: 16
file content (178 lines) | stat: -rw-r--r-- 4,439 bytes parent folder | download
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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
uniform float4x4 ViewProj;
uniform texture2d image;
uniform texture2d glow_fill_source;
uniform texture2d output_image;
uniform float4 glow_fill_color;
uniform texture2d glow_mask;
uniform float intensity;
uniform float2 offset;
uniform float fill_behind = 0.0;
// For crop/padding
uniform float2 mul_val;
uniform float2 add_val;

uniform float threshold;

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

sampler_state padSampler {
	Filter    = Linear;
	AddressU  = Border;
	AddressV  = Border;
	BorderColor = 00000000;
};

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

VertData VSCrop(VertData v_in)
{
	VertData vert_out;
	vert_out.pos = mul(float4(v_in.pos.xyz, 1.0), ViewProj);
	vert_out.uv = v_in.uv * mul_val + add_val;
	return vert_out;
}


float srgb_nonlinear_to_linear_channel(float u)
{
	return (u <= 0.04045) ? (u / 12.92) : pow((u + 0.055) / 1.055, 2.4);
}

float4 srgb_nonlinear_to_linear(float4 v)
{
	return float4(srgb_nonlinear_to_linear_channel(v.r), srgb_nonlinear_to_linear_channel(v.g), srgb_nonlinear_to_linear_channel(v.b), v.a);
}

float4 PSCrop(VertData v_in) : TARGET
{
	float4 rgba = image.Sample(padSampler, v_in.uv);
	rgba.rgb *= (rgba.a > 0.) ? (1. / rgba.a) : 0.;
	return rgba;
}

float4 drawOutput(VertData v_in) : TARGET
{
	float4 px = output_image.Sample(textureSampler, v_in.uv);
	return px;
}

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

float4 mainImageThresholdMask(VertData v_in) : TARGET
{
	float4 color = image.Sample(textureSampler, v_in.uv);
	return float4(1.0, 1.0, 1.0, clamp(color.a / threshold, 0.0, 1.0));
}

float4 mainImageOuterGlowColor(VertData v_in) : TARGET
{
	float4 mask_alpha = glow_mask.Sample(textureSampler, v_in.uv - offset);
	float4 color = image.Sample(textureSampler, v_in.uv);
	float4 glow = float4(glow_fill_color.rgb, clamp(glow_fill_color.a * intensity * mask_alpha.a, 0.0f, 1.0f));
	float blend_mask = clamp(step(threshold, color.a) + step(glow.a, 0.0001), 0.0, 1.0);
	return fill_behind * glow + (1.0 - fill_behind) * (1.0 - blend_mask) * float4(glow.rgb, glow.a * step(color.a, threshold) * (1.0 - color.a));
}

float4 mainImageOuterGlowSource(VertData v_in) : TARGET
{
	float4 mask_alpha = glow_mask.Sample(textureSampler, v_in.uv - offset);
	float4 color = image.Sample(textureSampler, v_in.uv);
	float4 fill_color = glow_fill_source.Sample(textureSampler, v_in.uv);
	float4 glow = float4(fill_color.rgb, clamp(fill_color.a * intensity * mask_alpha.a, 0.0f, 1.0f));
	float blend_mask = clamp(step(threshold, color.a) + step(glow.a, 0.0001), 0.0, 1.0);
	return fill_behind * glow + (1.0 - fill_behind) * (1.0 - blend_mask) * float4(glow.rgb, glow.a * step(color.a, threshold) * (1.0 - color.a));
}

float4 mainImageInnerGlowColor(VertData v_in) : TARGET
{
	float4 mask_col = glow_mask.Sample(textureSampler, v_in.uv - offset);
	float4 col = image.Sample(textureSampler, v_in.uv);
	float mask_alpha = clamp(intensity * (1.0 - mask_col.a), 0.0f, 1.0f) * col.a;
	return float4(glow_fill_color.rgb, glow_fill_color.a * mask_alpha);
}

float4 mainImageInnerGlowSource(VertData v_in) : TARGET
{
	float4 mask_col = glow_mask.Sample(textureSampler, v_in.uv - offset);
	float4 col = image.Sample(textureSampler, v_in.uv);
	float4 fill_col = glow_fill_source.Sample(textureSampler, v_in.uv);
	float mask_alpha = clamp(intensity * (1.0 - mask_col.a) * col.a, 0.0, 1.0);
	return float4(fill_col.rgb, fill_col.a * mask_alpha);
}

technique DrawCropPad
{
	pass
	{
		vertex_shader = VSCrop(v_in);
		pixel_shader = PSCrop(v_in);
	}
}

technique DrawOutput
{
	pass
	{
		vertex_shader = VSCrop(v_in);
		pixel_shader = drawOutput(v_in);
	}
}

technique ThresholdMask
{
	pass
	{
		vertex_shader = mainTransform(v_in);
		pixel_shader = mainImageThresholdMask(v_in);
	}
}

technique FilterOuterGlowColor
{
	pass
	{
		vertex_shader = mainTransform(v_in);
		pixel_shader = mainImageOuterGlowColor(v_in);
	}
}

technique FilterOuterGlowSource
{
	pass
	{
		vertex_shader = mainTransform(v_in);
		pixel_shader = mainImageOuterGlowSource(v_in);
	}
}

technique FilterInnerGlowColor
{
	pass
	{
		vertex_shader = mainTransform(v_in);
		pixel_shader = mainImageInnerGlowColor(v_in);
	}
}

technique FilterInnerGlowSource
{
	pass
	{
		vertex_shader = mainTransform(v_in);
		pixel_shader = mainImageInnerGlowSource(v_in);
	}
}