Motion Blur
【Motion Blur】
此篇介绍最简单的全局Motion Blur。算法是将当前帧与前一帧按某一比例混合。这是一个过程,例如有10帧,在第1帧中,只有第1帧原图,第2帧中有1、2帧原图,第3帧中会有1、2、3帧原图,依次类推。

假设混合比较为a,即原图为1-a,累积图为a,那么1帧新进入的图,在下一帧中,所占的比例就只有a,再下一帧就只有a^2,再下一帧就只有a^3,依次类推,第N帧后,比例会接近于0。a越小,消失的会越快,也就意味着MotionBlur效果越弱。相反,a越大,MotionBlur效果越强。通过将此混合参数叫做BlurAmount。为了防止完全抛弃新进帧的情况,通常会限制BlurAmount不大于0.92。

最后,MotionBlur的Shader需要特殊处理一下。首先需要将原始帧与累积帧混合在一起。但普通的混合会连带alpha一起混合,而我们想做做的只是混合RGB,希望alpha保留。所以需要2个Pass,第一个Pass根据BlurAmount混合RGB,第二个Pass直接写入新的alpha。完整Shader如下:
Shader "Hidden/MotionBlur" {
Properties {
_MainTex ("Base (RGB)", 2D) = "white" {}
_AccumOrig("AccumOrig", Float) = 0.65
}
SubShader {
ZTest Always Cull Off ZWrite Off
Fog { Mode off }
Pass {
Blend SrcAlpha OneMinusSrcAlpha
ColorMask RGB
BindChannels {
Bind "vertex", vertex
Bind "texcoord", texcoord
}
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#pragma fragmentoption ARB_precision_hint_fastest
#include "UnityCG.cginc"
struct appdata_t {
float4 vertex : POSITION;
float2 texcoord : TEXCOORD;
};
struct v2f {
float4 vertex : POSITION;
float2 texcoord : TEXCOORD;
};
float4 _MainTex_ST;
float _AccumOrig;
v2f vert (appdata_t v)
{
v2f o;
o.vertex = mul(UNITY_MATRIX_MVP, v.vertex);
o.texcoord = TRANSFORM_TEX(v.texcoord, _MainTex);
return o;
}
sampler2D _MainTex;
half4 frag (v2f i) : COLOR
{
return half4(tex2D(_MainTex, i.texcoord).rgb, _AccumOrig );
}
ENDCG
}
Pass {
Blend One Zero
ColorMask A
BindChannels {
Bind "vertex", vertex
Bind "texcoord", texcoord
}
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#pragma fragmentoption ARB_precision_hint_fastest
#include "UnityCG.cginc"
struct appdata_t {
float4 vertex : POSITION;
float2 texcoord : TEXCOORD;
};
struct v2f {
float4 vertex : POSITION;
float2 texcoord : TEXCOORD;
};
float4 _MainTex_ST;
v2f vert (appdata_t v)
{
v2f o;
o.vertex = mul(UNITY_MATRIX_MVP, v.vertex);
o.texcoord = TRANSFORM_TEX(v.texcoord, _MainTex);
return o;
}
sampler2D _MainTex;
half4 frag (v2f i) : COLOR
{
return tex2D(_MainTex, i.texcoord);
}
ENDCG
}
}
SubShader {
ZTest Always Cull Off ZWrite Off
Fog { Mode off }
Pass {
Blend SrcAlpha OneMinusSrcAlpha
ColorMask RGB
SetTexture [_MainTex] {
ConstantColor (,,,[_AccumOrig])
Combine texture, constant
}
}
Pass {
Blend One Zero
ColorMask A
SetTexture [_MainTex] {
Combine texture
}
}
}
Fallback off
}
Motion Blur的更多相关文章
- 【OpenCV】motion blur 的简单实现
先推荐界面比较丑,但是还不错的在线图片处理网站: http://www168.lunapic.com/editor/ 由于最近在做毕设了,结合前面关于图像处理和机器学习的操作,想做一些好玩的东西,其中 ...
- What is Away3D
做了几个基于Flash平台的3D的项目,一路走来收获颇多.Away3D作为一个开源的Flash3D引擎,在3D页游领域,无疑是当前OGRE在国内的地位. 翻译出了多年前做Away3D中国社区的时候翻译 ...
- Interpolation particles In Katana
I write the sphere radius interpolation for katana plugin that can transfer attributes,render attrib ...
- [OSG]OSG例子程序简介
1.example_osganimate一)演示了路径动画的使用(AnimationPath.AnimationPathCallback),路径动画回调可以作用在Camera.CameraView.M ...
- [转]显卡帝揭秘3D游戏画质特效
显卡帝揭秘3D游戏画质特效 近几年来,大量采用最新技术制作的大型3D游戏让大部分玩家都享受到了前所未有的游戏画质体验,同时在显卡硬件方面的技术革新也日新月异.对于经常玩游戏的玩家来说,可能对游戏画质提 ...
- ae学习
Ae 提供者CoSA 1993年1月 版本1.0 代号Egg 主要加入法人功能layered compositing with mask, effect, transforms, ...
- {ICIP2014}{收录论文列表}
This article come from HEREARS-L1: Learning Tuesday 10:30–12:30; Oral Session; Room: Leonard de Vinc ...
- Computer Graphics Research Software
Computer Graphics Research Software Helping you avoid re-inventing the wheel since 2009! Last update ...
- OSG中的示例程序简介
OSG中的示例程序简介 转自:http://www.cnblogs.com/indif/archive/2011/05/13/2045136.html 1.example_osganimate一)演示 ...
随机推荐
- Java——基本概念
body, table{font-family: 微软雅黑; font-size: 10pt} table{border-collapse: collapse; border: solid gray; ...
- 报错:Syntax error on tokens, delete these tokens
该问题意思是说:你有两个双引号或者你有没有关闭%>符号. 仔细检查代码 出现这样的错误一般是括号.中英文字符.中英文标点.代码前面的空格,尤其是复制粘贴的代码,去掉即可.
- [LOJ2541]「PKUWC2018」猎人杀
loj description 有\(n\)个猎人,每个猎人有一个仇恨度\(w_i\),每个猎人死后会开一枪打死一个还活着的猎人,打中每个猎人的概率与他的仇恨度成正比. 现在你开了第一枪,打死每个猎人 ...
- 图解VS2005之单元测试
据说VS2005里即提供了测试功能,可是对于像我或者我们这样的开发人或团队真还没有进化到用测试这块.一直以来都是手工测试或等到用户发现问题.今天在网上找了一个介绍单元测试的WORD文档,按里面说的做了 ...
- Chrome Developer Tools 中的 Preview 不显示 HTML 的问题
Chrome Developer Tools 中的 Preview 不显示 HTML 的问题 最近升级到 Chrome V64,发现 Chrome Developer Tools 中的 Preview ...
- github之本地上传
在打算上传到github之前需要在github上面首先创建一个项目(点击右上角“+”号,点击New repository):
- Oracle.DataAccess.dll 部署安装
Oracle.DataAccess.dll 要拷贝到项目发布目录 项目发布的时候,还必须要拷贝以下几个文件在运行目录1.oci.dll 2.oraociicus11.dll 3.OraOps11w.d ...
- 微软开源rDSN分布式系统开发框架
摘要:微软亚洲研究院系统组开发的分布式系统开发框架——Robust Distributed System Nucleus(rDSN)正式在GitHub平台开源.据悉,rDSN是一个旨在为广大分布式系统 ...
- springboot 整合 elasticsearch
1引入jar包 <!--elasticsearch--> <dependency> <groupId>org.springframework.boot</gr ...
- sysbench 参数
1)插入指定条数的数据 --events=N limit for total number of events [0] --time=N limit for total execution time ...