均值模糊

HLSL
// 均值模糊
// float2         UV          UV
// TextureObject  Texture     纹理对象
// float2         TexSize     图片大小,比如float2(512,512)
// float2         BlurCore    模糊大小,比如float2(5,5)
int2 UVOfferBegin = ceil(BlurCore / -2);
float3 OutColor={0.0, 0.0, 0.0};
for(int i = 0; i < BlurCore.y; i++)
    for(int j = 0; j < BlurCore.x; j++) {
        OutColor += Texture2DSample(Texture, TextureSampler, UV + float2((UVOfferBegin.x + j) / TexSize.x, (UVOfferBegin.y + i) / TexSize.y));
    }
return float4(OutColor / BlurCore.x / BlurCore.y, 1.0f);
点击展开查看更多

5x5高斯模糊

HLSL
// 5x5高斯模糊
// float2           UV      贴图UV
// TextureObject    Texture 纹理对象
// float2           TexSize 图片大小,比如float2(512,512)
int UVOfferset[] = {-2, -1, 0, 1, 2};
float Weights[] =
{
    0.0036,0.0146,0.0256,0.0146,0.0036,
    0.0146,0.0586,0.0952,0.0586,0.0146,
    0.0256,0.0952,0.1501,0.0952,0.0256,
    0.0146,0.0586,0.0952,0.0586,0.0146,
    0.0036,0.0146,0.0256,0.0146,0.0036
};
float3 OutColor = {0.0, 0.0, 0.0};
for(int i = 0; i < 5; i++)
    for(int j = 0; j < 5; j++)
        OutColor += Weights[i * 5 + j] * Texture2DSample(Texture, TextureSampler, UV + float2(UVOfferset[j] / TexSize.x, UVOfferset[i] / TexSize.y));
return float4(OutColor, 1.0f);
点击展开查看更多

在UnrealEngine中用Custom节点实现高斯模糊 - 湛蓝玫瑰 - 博客园

版权声明

作者: Chaim

链接: https://chaim.eu.org/posts/%E6%A8%A1%E7%B3%8A%E7%AE%97%E6%B3%95-blur/

许可证: CC BY-NC-SA 4.0

This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License. Please attribute the source, use non-commercially, and maintain the same license.

开始搜索

输入关键词搜索文章内容

↑↓
ESC
⌘K 快捷键