先上效果,左边模糊

其实用的是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. asp.net mvc 4 高级编程学习笔记:第四章 模型

    数据模型 数据模型及O/R转化,采用EntityFramework实现. 可以采用firstCode模型,首先定义模型,通过模型生成数据库,也可以通过安装EFPowerTools,通过数据库自动生成对 ...

  2. [MongoDB]count,gourp,distinct

    摘要 上篇文章介绍了CRUD的操作,会了这些,基本上可以完成很多工作了.但如果遇到统计类的操作,那么就需要学习下本篇的内容了. 相关文章 [MongoDB]入门操作 [MongoDB]增删改查 cou ...

  3. c++异常总结

    堆栈辗转开解(stack-unwinding):如果一个函数中出现异常,在当前函数内即通过 try..catch 捕捉(且捕捉到)的话,可以继续往下执行:如果不捕捉(或未捕捉到)就会抛出(与通过 th ...

  4. 从svn检出项目---------不是web项目

    javaweb项目从svn检出变成java项目 javaweb项目从svn检出后变成java项目,解决办法是: 1.项目右键–properties–Project Facets,勾选上Dynamic ...

  5. [原] Android快速开发框架-AndroidFine,GitHub开源

    Android快速开发框架 UI组件,不止是简单整合,更易用 沉浸式状态栏,界面更漂亮 左滑返回,非常流畅 简单.可复用.易扩展的底部导航 PagerSlidingTabStrip,导航标签文字颜色和 ...

  6. 【Solr】solr的增删改查

    目录 创建工程 增 删 改 查 高量查询 回到顶部 创建工程 普通的java web工程即可,我采用的是spring mvc! 回到顶部 增 @Autowired private SolrServer ...

  7. visual studio2010 “类视图”和“对象浏览器”图标

    “类视图”和“对象浏览器”显示一些图标,这些图标表示代码实体,例如命名空间.类.函数和变量. 下表以图文并茂的形式说明了这些图标. 图标 说明 图标 说明 namespace 方法或函数 类 运算符 ...

  8. iOS并发编程指南之同步

    1.gcd fmdb使用了gcd,它是通过 建立系列化的G-C-D队列 从多线程同时调用调用方法,GCD也会按它接收的块的顺序来执行. fmdb使用的是dispatch_sync,多线程调用a ser ...

  9. SQL Server 查询、搜索命令、语句

    --查询所有表 SELECT NAME,* FROM SYSOBJECTS WHERE XTYPE='U' order by SYSOBJECTS.name --查询所有存储过程 select * f ...

  10. 【转】AspNetPager分页控件用法

    AspNetPager分页控件解决了分页中的很多问题,直接采用该控件进行分页处理,会将繁琐的分页工作变得简单化,下面是我如何使用AspNetPager控件进行分页处理的详细代码: 1.首先到www.w ...