这是我在@ Rabbid76的帮助下创建的高斯模糊着色器的代码。
if( useSoftShadow == 1 )
{
vec3 incrementalGaussian;
incrementalGaussian.x = 1.0f / (sqrt(2.0f * pi) * BlurValue );
incrementalGaussian.y = exp(-0.5f / (BlurValue * BlurValue ));
incrementalGaussian.z = incrementalGaussian.y * incrementalGaussian.y;
vec4 avgValue = vec4(0.0f, 0.0f, 0.0f, 0.0f);
float coefficientSum = 0.0f;
// Take the central sample first...
avgValue += texture2D(text, ShadowTexCoord.st) * incrementalGaussian.x;
coefficientSum += incrementalGaussian.x;
incrementalGaussian.xy *= incrementalGaussian.yz;
//Go through the remaining 8 vertical samples (4 on each side of the center)
for (float i = 1.0f; i <= numBlurPixelsPerSide ; i++) {
avgValue += texture2D(text, ShadowTexCoord.st - i * 0.01f *
blurMultiplyVec) * incrementalGaussian.x;
avgValue += texture2D(text, ShadowTexCoord.st + i * 0.01f *
blurMultiplyVec) * incrementalGaussian.x;
avgValue += texture2D(text, ShadowTexCoord.st - i * 0.01f *
blurMultiplyVecVertical ) * incrementalGaussian.x;
avgValue += texture2D(text, ShadowTexCoord.st + i * 0.01f *
blurMultiplyVecVertical ) * incrementalGaussian.x;
coefficientSum += 2 * incrementalGaussian.x;
incrementalGaussian.xy *= incrementalGaussian.yz;
avgValue.g = avgValue.r;
avgValue.b = avgValue.r;
color = avgValue * vec4(textColor, 1.0) / coefficientSum ;
}
}
着色器按预期工作,但在硬边附近看不到模糊效果。
我如何在边缘周围产生模糊效果?