3x3高斯模糊
//input sW 分辨率宽
//input sH 分辨率高
//input NotUse 为了开启SceneTextureLookup函数而连接的节点,但是不参与逻辑
//input UV 屏幕缓存的坐标
//14是原始颜色
int tIndex=14;
float4 x1y1=0.0625*SceneTextureLookup(UV+float2(-1.0f/sW,-1.0/sH),tIndex,false);
float4 x2y1=0.125*SceneTextureLookup(UV+float2(0.0f,-1.0/sH),tIndex,false);
float4 x3y1=0.0625*SceneTextureLookup(UV+float2(1.0f/sW,-1.0/sH),tIndex,false);
float4 x1y2=0.125*SceneTextureLookup(UV+float2(-1.0f/sW,0.0f),tIndex,false);
float4 x2y2=0.25*SceneTextureLookup(UV+float2(0.0f,0.0f),tIndex,false);
float4 x3y2=0.125*SceneTextureLookup(UV+float2(1.0f/sW,0.0f),tIndex,false);
float4 x1y3=0.0625*SceneTextureLookup(UV+float2(-1.0f/sW,1.0/sH),tIndex,false);
float4 x2y3=0.125*SceneTextureLookup(UV+float2(0.0f,1.0/sH),tIndex,false);
float4 x3y3=0.0625*SceneTextureLookup(UV+float2(1.0f/sW,1.0/sH),tIndex,false);
return x1y1+x2y1+x3y1+x1y2+x2y2+x3y2+x1y3+x2y3+x3y3;

  

3X3均值模糊
//input sW 分辨率宽
//input sH 分辨率高
//input NotUse 为了开启SceneTextureLookup函数而连接的节点,但是不参与逻辑
//input UV 屏幕缓存的坐标
//14是原始颜色
int tIndex=14;
float4 x1y1=SceneTextureLookup(UV+float2(-1.0f/sW,-1.0/sH),tIndex,false);
float4 x2y1=SceneTextureLookup(UV+float2(0.0f,-1.0/sH),tIndex,false);
float4 x3y1=SceneTextureLookup(UV+float2(1.0f/sW,-1.0/sH),tIndex,false);
float4 x1y2=SceneTextureLookup(UV+float2(-1.0f/sW,0.0f),tIndex,false);
float4 x2y2=SceneTextureLookup(UV+float2(0.0f,0.0f),tIndex,false);
float4 x3y2=SceneTextureLookup(UV+float2(1.0f/sW,0.0f),tIndex,false);
float4 x1y3=SceneTextureLookup(UV+float2(-1.0f/sW,1.0/sH),tIndex,false);
float4 x2y3=SceneTextureLookup(UV+float2(0.0f,1.0/sH),tIndex,false);
float4 x3y3=SceneTextureLookup(UV+float2(1.0f/sW,1.0/sH),tIndex,false);
return (x1y1+x2y1+x3y1+x1y2+x2y2+x3y2+x1y3+x2y3+x3y3)/9;

  看了官方论坛的帖子,法线Custom里面可以写for循环,于是……

//5x5高斯模糊
//input sW 分辨率宽
//input sH 分辨率高
//input NotUse 为了开启SceneTextureLookup函数而连接的节点,但是不参与逻辑
//input UV 屏幕缓存的坐标
//14是原始颜色
int tIndex=14;
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<=4;i++)
{
for(int j=0;j<=4;j++)
{
OutColor+=Weights[i*5+j]*SceneTextureLookup(UV+float2(UVOfferset[j]/sW,UVOfferset[i]/sH),tIndex,false).xyz;
}
}
return float4(OutColor,1.0f);

  

参考了一下网上的文章写了个可以动态调整的高斯模糊

//动态高斯模糊
//input sW 分辨率宽
//input sH 分辨率高
//input NotUse 为了开启SceneTextureLookup函数而连接的节点,但是不参与逻辑
//input Radius 模糊半径
//input UV 屏幕缓存的坐标
//14是原始颜色
int tIndex=14;
if(Radius<1.0)
return SceneTextureLookup(UV,tIndex,false);
float3 OutColor={0.0,0.0,0.0};
Radius=floor(Radius);
float Sigma=Radius/3;
float Sigma2=2*Sigma*Sigma;
int Number=Radius;
float WeightsSum;
for(int i=-Number;i<=Number;i++)
{
for(int j=-Number;j<=Number;j++)
{
float Weights=(1/(Sigma2*3.1415))*exp(-(j*j+i*i)/Sigma2);
WeightsSum+=Weights;
OutColor+=Weights*SceneTextureLookup(UV+float2(j/sW,i/sH),tIndex,false).xyz;
}
}
OutColor/=WeightsSum;
return float4(OutColor,1.0f);

  

群里朋友需要一个模糊贴图的于是又写了个

//5x5高斯模糊
//input UV 贴图UV
//input Texture 传入TextureObject
//input 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<=4;i++)
{
for(int j=0;j<=4;j++)
{
OutColor+=Weights[i*5+j]*Texture2DSample(Texture, TextureSampler, UV+float2(UVOfferset[j]/TexSize.x,UVOfferset[i]/TexSize.y));
}
}
return float4(OutColor,1.0f);

  

//7x7均值模糊
//input UV 贴图UV
//input Texture 传入TextureObject
//input TexSize 图片大小,比如float2(512,512)
int UVOfferset[]={-3,-2,-1,0,1,2,3};
float Weights[]=
{
1,1,1,1,1,1,1,
1,1,1,1,1,1,1,
1,1,1,1,1,1,1,
1,1,1,1,1,1,1,
1,1,1,1,1,1,1,
1,1,1,1,1,1,1,
1,1,1,1,1,1,1
};
float3 OutColor={0.0,0.0,0.0};
for(int i=0;i<=6;i++)
{
for(int j=0;j<=6;j++)
{
OutColor+=Weights[i*7+j]*Texture2DSample(Texture, TextureSampler, UV+float2(UVOfferset[j]/TexSize.x,UVOfferset[i]/TexSize.y));
}
}
return float4(OutColor,1.0f)/49;

  

在UnrealEngine中用Custom节点实现高斯模糊的更多相关文章

  1. 在UnrealEngine中用Custom节点实现描边效果

    在<Real Time Rendering, third edition>一书中,作者把描边算法分成了5种类型.1.基于观察角度与表面法线的轮廓渲染.缺点很明显.2.过程式几何轮廓渲染.即 ...

  2. 在UnrealEngine中用Custom节点实现毛玻璃的效果

    本人在论坛上找到了一篇实现毛玻璃效果的文章:https://forums.unrealengine.com/showthread.php?70143-So-Blurred-glass-material ...

  3. 在UnrealEngine中用Custom节点实现径向模糊

    //input NotUse 为了开启SceneTextureLookup函数而连接的节点,但是不参与逻辑 //input UV 屏幕缓存的坐标坐标 //input Strength 力度 //inp ...

  4. 在UnrealEngine中用Custom节点实现马赛克效果

    参考这位大神的Shaderhttp://blog.csdn.net/noahzuo/article/details/51316015 //input BaseUV 屏幕UV //intput Tili ...

  5. 有关UnrealEngine材质编辑器中的Custom节点的一些小贴士

    PS:本文写于2017.2.1日,使用版本为4.13.第二次更新时间为2017.3.15增加了四.一些材质编辑器中的奇怪的技巧: 一.前言在Unreal中材质编辑器提供了Custom节点,作为HLSL ...

  6. Rocket - debug - TLDebugModuleInner - Drive Custom Access

    https://mp.weixin.qq.com/s/1bIqzDYXM36MIfSsjvvYIw 简单介绍TLDebugModuleInner中的针对Custom的访问. 1. customNode ...

  7. 剖析Unreal Engine超真实人类的渲染技术Part 2 - 眼球渲染

    目录 三.眼球渲染 3.1 眼球的构造及理论 3.1.1 眼球的构造 3.1.2 眼球的渲染理论 3.2 眼球的渲染技术 3.2.1 角膜的半透和光泽反射 3.2.2 瞳孔的次表面散射 3.2.3 瞳 ...

  8. 遗传算法在JobShop中的应用研究(part 5:解码)

    解码操作是整个遗传算法最重要的一步,在这步里面我们利用配置文件中的信息将染色体解码成一个有向无环图. 在介绍解码操作之前我们先来看一下配置文件,在part1绪论中我们已经介绍了一个车间调度问题的基本信 ...

  9. hbm.xml 详解总结

    转自 http://blog.csdn.net/tuke_tuke/article/details/49717991 一.hibernate映射文件的作用: Hibernate映射文件是Hiberna ...

随机推荐

  1. java 关键字transient

    http://www.cnblogs.com/lanxuezaipiao/p/3369962.html 1. transient的作用及使用方法 我们都知道一个对象只要实现了Serilizable接口 ...

  2. Python游戏编程(Pygame)

    安装Pygame pip install pygame C:\Users> pip install pygame Collecting pygame Downloading https://fi ...

  3. Idea 12配置SPring MVC 和Tomcat Server

    配置Spring 1. 添加idea插件 都选上了.也许有用! 2. 添加Spring库 下载spring,添加java库,指向spring库的目录: 配置tomcat Server 1. 安装tom ...

  4. mac下安装Brew 警告:Warning: /usr/local/bin is not in your PATH.

    终端输入命令 export PATH=/usr/local/bin:$PATH

  5. MyBatis - 7.MyBatis逆向 Generator

    MyBatis Generator: 简称MBG,是一个专门为MyBatis框架使用者定制的代码生成器,可以快速的根据表生成对应的映射文件,接口,以及bean类.支持基本的增删改查,以及QBC风格的条 ...

  6. Project 2013 安装找不到office.zh cn的解决办法

    先按照百度的办法,去“C:\Users\<你的电脑名>\AppData\Local\Temp\”下找类似“OWPFD24.tmp”的文件夹,结果发现并没有这个文件夹 , 没办法,自己硬着头 ...

  7. Git基础(三) 跟踪文件

    检查当前文件状态 git status 跟踪新文件 git add README 状态简览 git status -s 或 git status --short 忽略文件 创建一个名为.gitigno ...

  8. [转] Node.js使用MongoDB3.4+Access control is not enabled for the database解决方案

    今天使用MongoDB时遇到了一些问题 建立数据库连接时出现了warnings 出现这个警告的原因是新版本的MongDB为了让我们创建一个安全的数据库 必须要进行验证 后来在外网找到了答案 解决方案如 ...

  9. 重排DL

    题解: https://www.luogu.org/problemnew/show/T51442 从这题上还是学到不少东西.. 以前并没有写过ex-bsgs 正好拿这个复习中国剩余定理和bsgs了(我 ...

  10. 【CF526F】Pudding Monsters

    题意: 给你一个排列pi,问你有对少个区间的值域段是连续的. n≤3e5 题解: bzoj3745