@@ -71,6 +71,10 @@ float4 PSKawaseFocalBlur(VertDataOut v_in) : TARGET
71
71
return sum;
72
72
}
73
73
74
+ /**
75
+ * Standard Kawase blur
76
+ * While it's not being used, we keep it here for reference.
77
+ */
74
78
float4 PSKawaseBlur(VertDataOut v_in) : TARGET
75
79
{
76
80
// Calculate the blur value from neighboring pixels
@@ -83,6 +87,41 @@ float4 PSKawaseBlur(VertDataOut v_in) : TARGET
83
87
return sum;
84
88
}
85
89
90
+ /**
91
+ * Mask aware Kawase blur
92
+ * Only uses pixels which are in the masked area for blur. This prevents the "Halo Effect" on
93
+ * the border pixels of the mask.
94
+ */
95
+ float4 PSKawaseBlurMaskAware(VertDataOut v_in) : TARGET
96
+ {
97
+ if (focalmask.Sample(textureSampler, v_in.uv).r == 0) {
98
+ // No mask - return the original image value without any blur
99
+ return image.Sample(textureSampler, v_in.uv);
100
+ }
101
+
102
+ // Calculate the blur value from neighboring pixels
103
+
104
+ float alphaValue1 = focalmask.Sample(textureSampler, v_in.uv + float2( xOffset, yOffset)).r;
105
+ float4 sum = image.Sample(textureSampler, v_in.uv + float2( xOffset, yOffset)) * alphaValue1;
106
+ float pixelCounter = alphaValue1;
107
+
108
+ float alphaValue2 = focalmask.Sample(textureSampler, v_in.uv + float2(-xOffset, yOffset)).r;
109
+ sum += image.Sample(textureSampler, v_in.uv + float2(-xOffset, yOffset)) * alphaValue2;
110
+ pixelCounter += alphaValue2;
111
+
112
+ float alphaValue3 = focalmask.Sample(textureSampler, v_in.uv + float2( xOffset, -yOffset)).r;
113
+ sum += image.Sample(textureSampler, v_in.uv + float2( xOffset, -yOffset)) * alphaValue3;
114
+ pixelCounter += alphaValue3;
115
+
116
+ float alphaValue4 = focalmask.Sample(textureSampler, v_in.uv + float2(-xOffset, -yOffset)).r;
117
+ sum += image.Sample(textureSampler, v_in.uv + float2(-xOffset, -yOffset)) * alphaValue4;
118
+ pixelCounter += alphaValue4;
119
+
120
+ // Complement the blur pixels with a relative fraction of the center pixel
121
+ return (sum + image.Sample(textureSampler, v_in.uv) * (4.0 - pixelCounter)) * 0.25;
122
+ }
123
+
124
+
86
125
technique DrawFocalBlur
87
126
{
88
127
pass
@@ -97,6 +136,6 @@ technique Draw
97
136
pass
98
137
{
99
138
vertex_shader = VSDefault(v_in);
100
- pixel_shader = PSKawaseBlur (v_in);
139
+ pixel_shader = PSKawaseBlurMaskAware (v_in);
101
140
}
102
141
}
0 commit comments