当前位置:   article > 正文

[UE4]后处理模糊,几种方法_ue4材质边缘虚化

ue4材质边缘虚化

1.高斯模糊

 

static const int SceneTextureId = 14;
float2 TexelSize = View.ViewSizeAndInvSize.zw;
float2 UV = GetDefaultSceneTextureUV(Parameters, SceneTextureId);
float3 PixelSum = float3(0, 0, 0);
float WeightSum = 0;

for (int x = -Radius; x <= Radius; x++)
{
    for (int y = -Radius; y <= Radius; y++)
    {
        float2 Offset = UV + float2(x, y) * TexelSize;
        float3 PixelColor = SceneTextureLookup(Offset, SceneTextureId, 0).rgb;
        float Weight = Calculate1DGaussian(x / Radius) * Calculate1DGaussian(y / Radius);
        PixelSum += PixelColor * Weight;
        WeightSum += Weight;

    }
}

return PixelSum / WeightSum;

用到了SceneTextureLookupCalculate1DGaussian两个函数, 在前面通过这个方式导入,并不在Custom的Shader里起作用

Global:

    return 1;
}

float Calculate1DGaussian(float x)
{
    return exp(-0.5 * pow(3.141 * (x), 2));
 

 

这段代码在HLSL里面会自动补全

2.矩形模糊

UV = ViewportUVToBufferUV(UV);
float3 blur = SceneTextureLookup(UV, 14, false);
for(int i = 0; i < r; i++)
{
    blur += SceneTextureLookup(UV+float2(i*dist.x, 0), 14, false);
    blur += SceneTextureLookup(UV-float2(i*dist.y, 0), 14, false);
}

blur /= 2*r+1;
return blur;

改写自UE4官方​​​​​​https://docs.unrealengine.com/4.27/en-US/RenderingAndGraphics/Materials/ExpressionReference/Custom/

3.材质模糊

其他

关于效率问题也研究了一下放在知乎:

【UE4】几种全屏模糊方法的效率测试 - 知乎

声明:本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:【wpsshop博客】
推荐阅读
相关标签
  

闽ICP备14008679号