File: glow.effect

package info (click to toggle)
obs-stroke-glow-shadow 1.5.3-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 2,376 kB
  • sloc: ansic: 3,396; sh: 153; makefile: 27; cpp: 16
file content (211 lines) | stat: -rw-r--r-- 5,980 bytes parent folder | download | duplicates (2)
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
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
uniform float4x4 ViewProj;
uniform texture2d image;
uniform texture2d output_image;
uniform texture2d glow_fill_source;
uniform float4 glow_fill_color;
uniform texture2d glow_mask;
uniform float intensity;
uniform float2 offset;
uniform float threshold;

// For crop/padding
uniform float2 mul_val;
uniform float2 add_val;

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 mainTransform(VertData v_in)
{
	v_in.pos = mul(float4(v_in.pos.xyz, 1.0), ViewProj);
	return v_in;
}


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);
}

float srgb_linear_to_nonlinear_channel(float u)
{
	return (u <= 0.0031308) ? (12.92 * u) : ((1.055 * pow(u, 1. / 2.4)) - 0.055);
}

float4 srgb_linear_to_nonlinear(float4 v)
{
	return float4(srgb_linear_to_nonlinear_channel(v.r), srgb_linear_to_nonlinear_channel(v.g), srgb_linear_to_nonlinear_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 srgb_nonlinear_to_linear(px);
}

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);
	color.rgb *= (color.a > 0.) ? (1. / color.a) : 0.;
	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 blend_mask * float4(color.rgb * color.a, color.a) + (1.0 - blend_mask) * (float4(color.rgb * color.a, color.a) + glow * (1.0 - color.a));
}

float4 mainImageOuterGlowSource(VertData v_in) : TARGET
{
	float4 color = image.Sample(textureSampler, v_in.uv);
	color.rgb *= (color.a > 0.) ? (1. / color.a) : 0.;
	float4 mask_alpha = glow_mask.Sample(textureSampler, v_in.uv - offset);
	float4 glow_fill_col = srgb_nonlinear_to_linear(glow_fill_source.Sample(textureSampler, v_in.uv));
	glow_fill_col.rgb *= (glow_fill_col.a > 0.) ? (1. / glow_fill_col.a) : 0.;
	glow_fill_col= srgb_linear_to_nonlinear(glow_fill_col);
	float4 glow = float4(glow_fill_col.rgb, clamp(glow_fill_col.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 blend_mask * float4(color.rgb * color.a, color.a) + (1.0 - blend_mask) * (float4(color.rgb * color.a, color.a) + glow * (1.0 - color.a));
}

float4 mainImageInnerGlowColor(VertData v_in) : TARGET
{
	float3 gamma = float3(2.2f, 2.2f, 2.2f);
	float3 gamma_i = float3(0.454545f, 0.454545f, 0.454545f);
	
	float4 mask_col = glow_mask.Sample(textureSampler, v_in.uv - offset);
	float4 color = image.Sample(textureSampler, v_in.uv);
	color.rgb *= (color.a > 0.) ? (1. / color.a) : 0.;
	float3 color_rgb_l = pow(color.rgb, gamma);
	float3 glow_fill_l = pow(glow_fill_color.rgb, gamma);
	
	float mask_alpha = clamp(intensity * (1.0f - mask_col.a), 0.0f, 1.0f);
	float alpha = clamp(mask_alpha + (1.0f - mask_alpha) * color.a, 0.0f, color.a);
	return float4(pow(glow_fill_l.rgb * mask_alpha + color_rgb_l * (1.0 - mask_alpha), gamma_i), alpha);
}

float4 mainImageInnerGlowSource(VertData v_in) : TARGET
{
	float3 gamma = float3(2.2f, 2.2f, 2.2f);
	float3 gamma_i = float3(0.454545f, 0.454545f, 0.454545f);
	
	float4 mask_col = glow_mask.Sample(textureSampler, v_in.uv - offset);
	float4 color = image.Sample(textureSampler, v_in.uv);
	color.rgb *= (color.a > 0.) ? (1. / color.a) : 0.;
	float4 glow_fill_col = srgb_nonlinear_to_linear(glow_fill_source.Sample(textureSampler, v_in.uv));
	glow_fill_col.rgb *= (glow_fill_col.a > 0.) ? (1. / glow_fill_col.a) : 0.;
	glow_fill_col= srgb_linear_to_nonlinear(glow_fill_col);
	float3 color_rgb_l = pow(color.rgb, gamma);
	float3 glow_fill_l = pow(glow_fill_col.rgb, gamma);
	
	float mask_alpha = clamp(intensity * (1.0f - mask_col.a), 0.0f, 1.0f);
	float alpha = clamp(mask_alpha + (1.0f - mask_alpha) * color.a, 0.0f, color.a);
	return float4(pow(glow_fill_l.rgb * mask_alpha + color_rgb_l * (1.0 - mask_alpha), gamma_i), alpha);
}

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

technique DrawOutput
{
	pass
	{
		vertex_shader = VSCrop(v_in);
		//vertex_shader = mainTransform(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);
	}
}