When I use the FastBloom (Bloom Optimized) image effect, I noticed that there are two blur types, which are “standard” and “Sgx”.
When I toggle between them, there is no difference on rendering side. Then I check the shader, both of them are 7 * 7 gaussian blur. The way they do the for loop is different, but they all have 7 times texture reading, so there shouldn’t be dramatic performance difference.
So what’s the difference? And why the second one is named “Sgx”? What does “Sgx” stand for?
I don’t know where sgx stands for, but it’s probably a different type of sampling.
The traditional way of doing a Gaussian is with samples that are uniformly distributed and have different weights based on the Gaussian function. The disadvantage of this is that some samples contribute very little to the end result.
So another way is to apply importance sampling. In that case the weights are all the same, but the distribution is non-uniform. The disadvantage of this is that there are some wider gaps between the samples, which means there is a higher chance of skipping pixels.
The visual difference can be fairly minimal. Not the greatest image, but it shows the idea a bit:
Thank you for your reply. I get what you are saying about importance sampling. However, I don’t think the Sgx blur is the importance sampling.
Shader code from FastBloom (I will just copy the horizontal):
standard:
vert:
frag:
Sgx:
vert:
frag:
Here is the curve4 both of them use:
static const half4 curve4[7] = { half4(0.0205,0.0205,0.0205,0), half4(0.0855,0.0855,0.0855,0), half4(0.232,0.232,0.232,0), half4(0.324,0.324,0.324,1), half4(0.232,0.232,0.232,0), half4(0.0855,0.0855,0.0855,0), half4(0.0205,0.0205,0.0205,0) };
If we set _Parameter.x to 2, and resolution to 1024 * 768, standard version samples:
uv - 6/1024, uv - 4/1024, uv - 2/1024, uv, uv + 2/1024, uv + 4/1024, uv + 6/1024
I did some more research, so SGX is a GPUs series from PowerVR. It’s used on newer versions of iPhone (starting with the iPhone 3GS).
so I guess there should be something in the standard blur type that cannot be done on the SGX hardware, or there is something special in the SGX blur type that can only be done on the SGX hardware?
It’s about avoiding dependent texture reads for mobile. Modifying the UVs in the fragment shader makes reading textures much slower on mobile. On desktop it doesn’t matter as much, and not passing extra data from the vertex to the fragment can often save you more time than it takes to do the calculations per-pixel.
Note that the UnityStereoScreenSpaceUVAdjust() function does nothing on mobile platforms so the UVs aren’t being modified.
That is for VR, and it’s defined by enabling Virtual Reality Support and Single-Pass Stereo Rendering in the player settings. No additional #pragma multicompile is needed.