赞
踩
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;
用到了SceneTextureLookup和Calculate1DGaussian两个函数, 在前面通过这个方式导入,并不在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;
3.材质模糊
其他
关于效率问题也研究了一下放在知乎:
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。