在UnrealEngine中用Custom节点实现高斯模糊
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节点实现高斯模糊的更多相关文章
- 在UnrealEngine中用Custom节点实现描边效果
在<Real Time Rendering, third edition>一书中,作者把描边算法分成了5种类型.1.基于观察角度与表面法线的轮廓渲染.缺点很明显.2.过程式几何轮廓渲染.即 ...
- 在UnrealEngine中用Custom节点实现毛玻璃的效果
本人在论坛上找到了一篇实现毛玻璃效果的文章:https://forums.unrealengine.com/showthread.php?70143-So-Blurred-glass-material ...
- 在UnrealEngine中用Custom节点实现径向模糊
//input NotUse 为了开启SceneTextureLookup函数而连接的节点,但是不参与逻辑 //input UV 屏幕缓存的坐标坐标 //input Strength 力度 //inp ...
- 在UnrealEngine中用Custom节点实现马赛克效果
参考这位大神的Shaderhttp://blog.csdn.net/noahzuo/article/details/51316015 //input BaseUV 屏幕UV //intput Tili ...
- 有关UnrealEngine材质编辑器中的Custom节点的一些小贴士
PS:本文写于2017.2.1日,使用版本为4.13.第二次更新时间为2017.3.15增加了四.一些材质编辑器中的奇怪的技巧: 一.前言在Unreal中材质编辑器提供了Custom节点,作为HLSL ...
- Rocket - debug - TLDebugModuleInner - Drive Custom Access
https://mp.weixin.qq.com/s/1bIqzDYXM36MIfSsjvvYIw 简单介绍TLDebugModuleInner中的针对Custom的访问. 1. customNode ...
- 剖析Unreal Engine超真实人类的渲染技术Part 2 - 眼球渲染
目录 三.眼球渲染 3.1 眼球的构造及理论 3.1.1 眼球的构造 3.1.2 眼球的渲染理论 3.2 眼球的渲染技术 3.2.1 角膜的半透和光泽反射 3.2.2 瞳孔的次表面散射 3.2.3 瞳 ...
- 遗传算法在JobShop中的应用研究(part 5:解码)
解码操作是整个遗传算法最重要的一步,在这步里面我们利用配置文件中的信息将染色体解码成一个有向无环图. 在介绍解码操作之前我们先来看一下配置文件,在part1绪论中我们已经介绍了一个车间调度问题的基本信 ...
- hbm.xml 详解总结
转自 http://blog.csdn.net/tuke_tuke/article/details/49717991 一.hibernate映射文件的作用: Hibernate映射文件是Hiberna ...
随机推荐
- PHP 方法,类与对象的相关函数学习
1.function_exists function_exists(string)检测函数是否存在,string表示需要检测的函数名称(注意与property_exists,method_exists ...
- 创建WIFI热点
@echo off:beginecho 笔记本做无线WiFi程序(首次使用请先设置WiFi帐户.)echo 1.设置WiFi帐户,请按1echo 2.开启WiFi功能,请按2echo 3.闭关WiFi ...
- 从0开始简单使用git进行项目开发【SourceTree+Coding.net】
一.什么是git? 含义:Git 是 Linux 发明者 Linus 开发的一款新时代的版本控制系统,相比于原来的svn系统更加简单和实用 作用: 熟悉编程的知道,我们在软件开发中源代码其实是最重要的 ...
- C#算法 选择排序、冒泡排序、插入排序
1.冒泡排序: 方法一: public static int[] MaoPao(int[] arr) { //执行多少次 for (int i = 0; i < arr.Length; i++) ...
- 【Socket】Java Socket编程基础及深入讲解
Socket是Java网络编程的基础,了解还是有好处的, 这篇文章主要讲解Socket的基础编程.Socket用在哪呢,主要用在进程间,网络间通信.本篇比较长,特别做了个目录: 一.Socket通信基 ...
- C# 之 串口数据侦听的实现
当需要编程操纵硬件时会遇到过这样的问题,就是通过串口来接收硬件发来的数据,或是通过串口向硬件发送某种格式的命令.在C#平台上,可以通过 System.IO.Ports 命名空间下的SerialPort ...
- makefile:n: *** missing separator. Stop
makefile has a very stupid relation with tabs, all actions of every rule are identified by tabs .... ...
- 【AtCoder】AGC016
A - Shrinking 用每个字母模拟一下就行 #include <bits/stdc++.h> #define fi first #define se second #define ...
- ConcurrentModificationException(并发修改异常)的分析
1)介绍 并发修改ConcurrentModificationException错误是开发中一个常见错误,多发生在对一个Collection边遍历边做影响size变化的操作中,下面以ArrayList ...
- 查看name的状态,是属于active还是standby
sudo -E -u hadoop /home/hadoop/bin/hdfs haadmin -getServiceState nn1 sudo -E -u hadoop /home/hadoop/ ...