先上效果,左边模糊

其实用的是Unity Stard Effect里的资源,一个脚本一个shader

//脚本代码

using UnityEngine;
using System.Collections; [ExecuteInEditMode]
[AddComponentMenu("Image Effects/Blur/Blur")]
public class BlurEffect : MonoBehaviour
{
/// Blur iterations - larger number means more blur.
public int iterations = ; /// Blur spread for each iteration. Lower values
/// give better looking blur, but require more iterations to
/// get large blurs. Value is usually between 0.5 and 1.0.
public float blurSpread = 0.6f; // --------------------------------------------------------
// The blur iteration shader.
// Basically it just takes 4 texture samples and averages them.
// By applying it repeatedly and spreading out sample locations
// we get a Gaussian blur approximation. public Shader blurShader = null; //private static string blurMatString = static Material m_Material = null;
protected Material material {
get {
if (m_Material == null) {
m_Material = new Material(blurShader);
m_Material.hideFlags = HideFlags.DontSave;
}
return m_Material;
}
} protected void OnDisable() {
if( m_Material ) {
DestroyImmediate( m_Material );
}
} // -------------------------------------------------------- protected void Start()
{
// Disable if we don't support image effects
if (!SystemInfo.supportsImageEffects) {
enabled = false;
return;
}
// Disable if the shader can't run on the users graphics card
if (!blurShader || !material.shader.isSupported) {
enabled = false;
return;
}
} // Performs one blur iteration.
public void FourTapCone (RenderTexture source, RenderTexture dest, int iteration)
{
float off = 0.5f + iteration*blurSpread;
Graphics.BlitMultiTap (source, dest, material,
new Vector2(-off, -off),
new Vector2(-off, off),
new Vector2( off, off),
new Vector2( off, -off)
);
} // Downsamples the texture to a quarter resolution.
private void DownSample4x (RenderTexture source, RenderTexture dest)
{
float off = 1.0f;
Graphics.BlitMultiTap (source, dest, material,
new Vector2(-off, -off),
new Vector2(-off, off),
new Vector2( off, off),
new Vector2( off, -off)
);
} // Called by the camera to apply the image effect
void OnRenderImage (RenderTexture source, RenderTexture destination) {
int rtW = source.width/;
int rtH = source.height/;
RenderTexture buffer = RenderTexture.GetTemporary(rtW, rtH, ); // Copy source to the 4x4 smaller texture.
DownSample4x (source, buffer); // Blur the small texture
for(int i = ; i < iterations; i++)
{
RenderTexture buffer2 = RenderTexture.GetTemporary(rtW, rtH, );
FourTapCone (buffer, buffer2, i);
RenderTexture.ReleaseTemporary(buffer);
buffer = buffer2;
}
Graphics.Blit(buffer, destination); RenderTexture.ReleaseTemporary(buffer);
}
}

//shader

// electricity/lightning shader
// pixel shader 2.0 based rendering of electric spark
// by Ori Hanegby
// Free for any kind of use. Shader "FX/Lightning" {
Properties {
_SparkDist ("Spark Distribution", range(-,)) =
_MainTex ("MainTex (RGB)", 2D) = "white" {}
_Noise ("Noise", 2D) = "noise" {}
_StartSeed ("StartSeed", Float) =
_SparkMag ("Spark Magnitude" , range(,)) =
_SparkWidth ("Spark Width" , range(0.001,0.499)) = 0.25
} Category { // We must be transparent, so other objects are drawn before this one.
Tags { "Queue"="Transparent" } SubShader { // Main pass: Take the texture grabbed above and use the bumpmap to perturb it
// on to the screen
Blend one one
ZWrite off
Pass {
Name "BASE"
Tags { "LightMode" = "Always" } CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#pragma fragmentoption ARB_precision_hint_fastest
#include "UnityCG.cginc" struct appdata_t {
float4 vertex : POSITION;
float2 texcoord: TEXCOORD0;
}; struct v2f {
float4 vertex : POSITION;
float2 uvmain : TEXCOORD0;
}; float _SparkDist;
float4 _Noise_ST;
float4 _MainTex_ST;
float4 _ObjectScale; v2f vert (appdata_t v)
{
v2f o;
o.vertex = mul(UNITY_MATRIX_MVP, v.vertex); o.uvmain = TRANSFORM_TEX( v.texcoord, _MainTex );
return o;
} sampler2D _GrabTexture;
float4 _GrabTexture_TexelSize;
sampler2D _Noise;
sampler2D _MainTex;
float _GlowSpread;
float _GlowIntensity;
float _StartSeed;
float _SparkMag;
float _SparkWidth; half4 frag( v2f i ) : COLOR
{ float2 noiseVec = float2(i.uvmain.y / ,abs(sin(_Time.x + _StartSeed)) * );
float4 noiseSamp = tex2D( _Noise,noiseVec); float dvdr = 1.0 - abs(i.uvmain.y - 0.5) * ;
dvdr = clamp(dvdr+_SparkDist,,); float fullWidth = - _SparkWidth * ;
// Center the scaled texture
float scaledTexel = (i.uvmain.x - _SparkWidth) / fullWidth; float offs = scaledTexel + ((0.5 - noiseSamp.x)/) * _SparkMag * dvdr;
offs = clamp(offs,,); float2 texSampVec = float2(offs,i.uvmain.y);
half4 col = tex2D( _MainTex, texSampVec); return col;
}
ENDCG
}
} // ------------------------------------------------------------------
// Fallback for older cards
SubShader {
Blend one one
ZWrite off
Pass {
Name "BASE"
SetTexture [_MainTex] { combine texture }
}
}
} }

用法:

创建个摄像机,挂上上面的脚本,然后把Blur Shader用这个shader赋值就行了

Unity全屏模糊的更多相关文章

  1. unity 全屏乱影 BlitMultiTap

    http://m.blog.csdn.net/blog/stalendp/40859441 官方例子AngryBots的链接地址:http://u3d.as/content/unity-technol ...

  2. Unity打开摄像头占满全屏

    Unity打开摄像头占满全屏 AR项目需求,Unity打开摄像头作为背景渲染占满全屏~ Unity对设备硬件操作的API并不是太友好~打开一个摄像头,渲染到屏幕上也都得自己写,虽然步骤少,提取摄像头t ...

  3. unity 竖屏不能全屏显示

    最近遇到一个问题,硬件显示屏是1080*1920的竖屏,但是导出后打开exe进去并不能全屏 处理办法是1.确认配置都是正确的,简单来说,就是自适应设定,这个网上有很多,就不赘述了. 2.exe启动时需 ...

  4. Unity3D去掉全屏时的屏幕黑边

    给全屏后不在乎拉伸变形仍想让画面占满屏幕的朋友,网上搜了一上午,实在是没有相关的资料,只能自己琢磨了. 使用Canvas Scaler在全屏后Unity虽然会为我们自动拉伸UI,但拉伸后仍然保持我们在 ...

  5. Unity3D在Windows的全屏和跨屏(双屏)方案

    方案1 unity中2个摄像机场景显示在两个显示器屏幕上(一个窗口跨屏) 1.设置场景中的两个摄像机 摄像机1 摄像机2 2.设置发布的平台及分辨率 3.全屏运行游戏,没有标题栏还可以通过-popup ...

  6. CSS之全屏背景图

    吐槽啦:Yeah  明天就是国庆了o(* ̄▽ ̄*)o!哈哈,提前祝福各位园友国庆快乐.假期愉快.生活美满.天天开心!国庆我要回家一趟,把一些不用的东西带回家,走访一下亲朋好友,在家打几天酱油~~~ 言 ...

  7. H5项目常见问题及注意事项,视频全屏,定位,屏幕旋转和触摸,偏页面重构向 来源joacycode的github

    Meta基础知识: H5页面窗口自动调整到设备宽度,并禁止用户缩放页面 //一.HTML页面结构 <meta name="viewport" content="wi ...

  8. 使用CSS3实现响应式标题全屏居中和站点前端性能

    要实现标题全屏居中(同一时候在垂直和水平方向居中).有若干种方法,包含使用弹性布局.表格单元.绝对定位和自己主动外边距等. 全屏居中 当中眼下比較流行也比較easy理解的方法是使用绝对定位+偏移实现. ...

  9. vlc播放器设置开机自动全屏播放网络视频流

    因工作需要,要用vlc视频播放器实现开机自动全屏播放某个网络视频流.百度了下,说的都很模糊,经过整理,设置方法如下: 一,添加视频流地址:rtsp://wowzaec2demo.streamlock. ...

随机推荐

  1. javascript Date 总结

    构造函数 Date 对象的构造函数有以下4种: (1)var variable = new Date(); (2)var variable = new Date(millisenconds); (3) ...

  2. Wordpress文章图片不居中与开头缩进问题

    //段落开头缩进 .Mid2L_con p {text-indent:2em;} //文章内图片不居中(设置居中后) .Mid2L_con .aligncenter { display: block; ...

  3. JavaScript 五种(构造方式)继承

    一.对象冒充 function Parent(username){ this.username = username; this.hello = function(){ alert(this.user ...

  4. 获取Executor提交的并发执行的任务返回结果的两种方式/ExecutorCompletionService使用

    当我们通过Executor提交一组并发执行的任务,并且希望在每一个任务完成后能立即得到结果,有两种方式可以采取: 方式一: 通过一个list来保存一组future,然后在循环中轮训这组future,直 ...

  5. CentOS 与 RedHat 关系和区别

    转自http://www.aixchina.net/club/archiver/tid-26784.html CentOS 发行版介绍 CentOS 是 Community ENTerprise Op ...

  6. addEventListener和on的区别

    为什么需要addEventListener? 先来看一个片段: html代码 <div id="box">追梦子</div> 用on的代码 1 window ...

  7. 一张图读懂https加密协议

    搭建CA服务器和iis启用https:http://blog.csdn.net/dier4836/article/details/7719532 一张图读懂https加密协议 https是一种加密传输 ...

  8. javascript 2048游戏

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

  9. R语言 小程序

    x<-sample(1:11) x 日期和时间 ###Data and Time### > data_time <- data.frame(data = c("2015-0 ...

  10. 设置p标签自动换行

    <body>     <p style="width:20px;height:100px;background-color:#069; word-wrap: break-w ...