Super Sampling anti-aliasing
SSAA is a relatively expensive one in many anti-aliasing algorithms, the age is relatively long, but the method is relatively simple,
The main two-step
1. Find edges
2. Blur edges
This is a post processing processing method,
Then we'll see how it's going to come true
Find Edgesthe reason for finding edges is also because of the reduced consumption, so that you can only super-sample at the edges, and you do not have to sample the full image.
The previous article described in detail three ways to find edges Roberts,sobel,canny, where Sobel is optimal, so we're using Sobel to find edges
Here's a quick look at the different edges of the filter, but it's all horizontal and vertical sampling.
The two filters of the Sobel operator calculate the horizontal and vertical gray scale respectively.
The GX is the horizontal filter, the Gy is the vertical filter, the vertical filter is the horizontal filter rotates 90 degrees.
The filter is a 3x3 matrix that will be used as a planar convolution of the image.
If there is no edge then the two point color is very close, the filter returns a small value, otherwise you can determine the existence of the edge.
You can blur the edges after you find the edges.
Blur EdgeThe Blur Edge is for super sampling, taking the surrounding pixels and then blending
People often see, for example, ssaax2,ssaax4,x8 .... The number that follows is the count of the sample points.
Previously translated super-sampling on a wiki
There are many ways to blur the edges (sampling), and there are several more popular
Mesh sampling, random sampling, Poisson disc sampling, jitter algorithm sampling, rotating mesh sampling
Part of the sampling range, I set them to the edge of the gray, that is, the edge of the detection of G, because the larger the G-edge, the more obvious the sawtooth, it is necessary to increase the sampling range.
Let's try grid, random, and rotational sampling
Grid sampling is relatively simple, but because it is too regular, the effect of blurring may not be good enough,
To get the dots around and then process the color
FLOAT4 C0 = tex2d (_maintex, I.uv_maintex + fixed2 (0.5, 1)/_size); Float4 C1 = tex2d (_maintex, I.uv_maintex + fixed2 (-0.5, 1)/_size); FLOAT4 C2 = tex2d (_maintex, I.uv_maintex + fixed2 (0.5,-1)/_size); FLOAT4 C3 = Tex2d (_maintex, I.uv_maintex + FIXED2 ( -0.5,-1)/_size);
And then randomly, the individual thinks that the random effect is not very good, because it is like the edge is noisy, there are traces of pixel spread
Float2 Randuv = 0;randuv = rand (FLOAT2 (n.x, N.Y)); Float4 C0 = tex2d (_maintex, I.uv_maintex + float2 (RANDUV.X/2, RANDUV.Y )/_size); Randuv = rand (FLOAT2 (-n.x, N.Y)); Float4 C1 = tex2d (_maintex, I.uv_maintex + float2 (RANDUV.X/2, randuv.y)/_s ize); Randuv = rand (FLOAT2 (n.x,-N.Y)); FLOAT4 C2 = tex2d (_maintex, I.uv_maintex + float2 (RANDUV.X/2, RANDUV.Y)/_size); r Anduv = rand (FLOAT2 (-n.x,-N.Y)), float4 C3 = Tex2d (_maintex, I.uv_maintex + float2 (RANDUV.X/2, RANDUV.Y)/_size);
Then is the rotation of the grid sampling, the best rotation angle is arctan (1/2) (about 26.6°), here to steal a lazy, but also save the rotation of the calculation of consumption, about a position to sample, the effect is good.
<span style= "FONT-SIZE:14PX;" >FLOAT4 C0 = tex2d (_maintex, I.uv_maintex + fixed2 (0.2/2, 0.8)/_size); Float4 C1 = tex2d (_maintex, I.uv_maintex + fi Xed2 (0.8/2, -0.2)/_size) Float4 C2 = tex2d (_maintex, I.uv_maintex + fixed2 ( -0.2/2, -0.8)/_size); FLOAT4 C3 = Tex2d ( _maintex, I.uv_maintex + fixed2 ( -0.8/2, 0.2)/_size);</span>
Results Comparison
Performance
The performance aspect of SSAA is weaker than the other AA, mainly because the method is such violent sampling
The loss of the SSAA sampling method is similar
It's all SSAAx4.
No anti-aliasing
Mesh Sampling
Random sampling
Rotational sampling
The SSAA consumption of image effect in unity is similar to this article
Looking at the other unity antialiasing method, we found that the FXAA consumption was at least 2.8ms or so.
all code is shared to GitHub
-----by wolf96 http://blog.csdn.net/wolf96/
Unity3d Super Sample anti-aliasing super sampling anti-aliasing