internal void SetSampleParameters()
{
int sampleMid = (mBlurSampleCount / 2);
float[] sampleWeights = new float[mBlurSampleCount];
Vector2[] sampleOffsetsHor = new Vector2[mBlurSampleCount];
Vector2[] sampleOffsetsVer = new Vector2[mBlurSampleCount];
Vector2 pixelSize = PostProcessingManager.PixelSize;
// Calculate values using normal (gaussian) distribution
float weightSum = 0f;
for (int i = 0; i < mBlurSampleCount; i++)
{
// Get weight
sampleWeights[i] =
1f / (((float)System.Math.Sqrt(2.0 * System.Math.PI) / mBlurStandardDeviation) *
(float)System.Math.Pow(System.Math.E,
System.Math.Pow((double)(i - sampleMid), 2.0) /
(2.0 * System.Math.Pow((double)mBlurStandardDeviation, 2.0))));
// Add to total weight value (for normalization)
weightSum += sampleWeights[i];
// Get offset
sampleOffsetsHor[i] = (new Vector2(
(float)(i - sampleMid) * 2.0f * mSampleScale + 0.5f, 0.5f)) * pixelSize;
sampleOffsetsVer[i] = (new Vector2(
0.5f, (float)(i - sampleMid) * 2.0f * mSampleScale + 0.5f)) * pixelSize;
}
// Normalize sample weights
for (int i = 0; i < sampleWeights.Length; i++)
{
sampleWeights[i] /= weightSum;
}
// Set parameters in shader
mSampleWeights = sampleWeights;
mSampleOffsetsHor = sampleOffsetsHor;
mSampleOffsetsVer = sampleOffsetsVer;
}