拐角处不会发生模糊

时间:2019-07-19 08:46:53

标签: opengl glsl

这是我在@ 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 ;
    }
}

着色器按预期工作,但在硬边附近看不到模糊效果。

enter image description here

我如何在边缘周围产生模糊效果?

0 个答案:

没有答案