Effect Comparison
Implementation Method
1, drop sampling
Gradually reduce the length of the original map (source image) to the original 1/4 dimension (Quarter source image), as shown in the following figure.
2, brightness filtering, blur and stretching processing
The quarter image is filtered by the brightness filter, and the darker part of quarter image is filtered to get the bright spots in the image. It is then blur blurred and stretched to soften and amplify the area of the bright spot, which has been given a flare effect.
Brightness Filter Core code:
Half4 Frag (v2f i): color
{
Half4 color = tex2d (_maintex, I.UV);
color = Color * LERP (1.0, COLOR.A, alphamask);//alphamask user input
color = max (Half4 (0,0,0,0), color-filtervalue);//filt Ervalue user input
return color;
}
Blur Core Code:
Half4 color = Half4 (0,0,0,0);
Color + = 0.225 * tex2d (_maintex, I.UV);
Color + = 0.150 * tex2d (_maintex, i.uv01.xy);
Color + = 0.150 * tex2d (_maintex, I.UV01.ZW);
Color + = 0.110 * tex2d (_maintex, i.uv23.xy);
Color + = 0.110 * tex2d (_maintex, I.UV23.ZW);
Color + = 0.075 * tex2d (_maintex, i.uv45.xy);
Color + = 0.075 * tex2d (_maintex, I.UV45.ZW);
Color + = 0.0525 * tex2d (_maintex, i.uv67.xy);
Color + = 0.0525 * tex2d (_maintex, I.UV67.ZW);
Brightness Stretch Core code:
v2f_opts Vertstretch (appdata_img v) {v2f_opts o;
O.pos = Mul (UNITY_MATRIX_MVP, V.vertex);
Half B = stretchwidth;
O.uv0 = V.texcoord.xy; O.uv1 = v.texcoord.xy + b * 2.0 * OFFSETS.XY;
Offsets user input weight value o.uv2 = v.texcoord.xy-b * 2.0 * OFFSETS.XY;
O.uv3 = v.texcoord.xy + b * 4.0 * OFFSETS.XY;
O.UV4 = v.texcoord.xy-b * 4.0 * OFFSETS.XY;
O.UV5 = v.texcoord.xy + b * 6.0 * OFFSETS.XY;
O.UV6 = v.texcoord.xy-b * 6.0 * OFFSETS.XY;
return o;
} half4 Fragstretch (v2f_opts i): color {Half4 color = tex2d (_maintex, i.uv0);
color = max (color, tex2d (_maintex, i.uv1));
color = max (color, tex2d (_maintex, i.uv2));
color = max (color, tex2d (_maintex, I.uv3));
color = max (color, tex2d (_maintex, i.uv4));
color = max (color, tex2d (_maintex, i.uv5));
color = max (color, tex2d (_maintex, i.uv6));
return color; }
3. Map Merge
By blending the original map (source Image) with the Blur stretch map (blurred stretched image), the flare effect is accomplished.
Core code:
Blendop Add
Blend One One
Performance Analysis
This method can be used in weapons display or character appearance, and considering that it can achieve such outstanding artistic effect, so although the traditional bloom effect added 2 draw call, in our view is also value.
At the same time, it is recommended that developers add some passes to the actual application, such as multiple blur or edge-modeled processing methods. In addition, the flare color can be colored aberration processing, the effect is better. We can be based on the needs of their projects to improve.