Unity全屏模糊
先上效果,左边模糊

其实用的是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全屏模糊的更多相关文章
- unity 全屏乱影 BlitMultiTap
http://m.blog.csdn.net/blog/stalendp/40859441 官方例子AngryBots的链接地址:http://u3d.as/content/unity-technol ...
- Unity打开摄像头占满全屏
Unity打开摄像头占满全屏 AR项目需求,Unity打开摄像头作为背景渲染占满全屏~ Unity对设备硬件操作的API并不是太友好~打开一个摄像头,渲染到屏幕上也都得自己写,虽然步骤少,提取摄像头t ...
- unity 竖屏不能全屏显示
最近遇到一个问题,硬件显示屏是1080*1920的竖屏,但是导出后打开exe进去并不能全屏 处理办法是1.确认配置都是正确的,简单来说,就是自适应设定,这个网上有很多,就不赘述了. 2.exe启动时需 ...
- Unity3D去掉全屏时的屏幕黑边
给全屏后不在乎拉伸变形仍想让画面占满屏幕的朋友,网上搜了一上午,实在是没有相关的资料,只能自己琢磨了. 使用Canvas Scaler在全屏后Unity虽然会为我们自动拉伸UI,但拉伸后仍然保持我们在 ...
- Unity3D在Windows的全屏和跨屏(双屏)方案
方案1 unity中2个摄像机场景显示在两个显示器屏幕上(一个窗口跨屏) 1.设置场景中的两个摄像机 摄像机1 摄像机2 2.设置发布的平台及分辨率 3.全屏运行游戏,没有标题栏还可以通过-popup ...
- CSS之全屏背景图
吐槽啦:Yeah 明天就是国庆了o(* ̄▽ ̄*)o!哈哈,提前祝福各位园友国庆快乐.假期愉快.生活美满.天天开心!国庆我要回家一趟,把一些不用的东西带回家,走访一下亲朋好友,在家打几天酱油~~~ 言 ...
- H5项目常见问题及注意事项,视频全屏,定位,屏幕旋转和触摸,偏页面重构向 来源joacycode的github
Meta基础知识: H5页面窗口自动调整到设备宽度,并禁止用户缩放页面 //一.HTML页面结构 <meta name="viewport" content="wi ...
- 使用CSS3实现响应式标题全屏居中和站点前端性能
要实现标题全屏居中(同一时候在垂直和水平方向居中).有若干种方法,包含使用弹性布局.表格单元.绝对定位和自己主动外边距等. 全屏居中 当中眼下比較流行也比較easy理解的方法是使用绝对定位+偏移实现. ...
- vlc播放器设置开机自动全屏播放网络视频流
因工作需要,要用vlc视频播放器实现开机自动全屏播放某个网络视频流.百度了下,说的都很模糊,经过整理,设置方法如下: 一,添加视频流地址:rtsp://wowzaec2demo.streamlock. ...
随机推荐
- VIP卡
VIP卡:http://item.taobao.com/item.htm?id=6826715667&ali_refid=a3_420435_1006:1102617497:6::683ff3 ...
- 使用cachemanager做缓存(Session的缓存)
1.我在这里直接用 cachemanager.redis 往redis里面存储缓存数据2.步骤 1)下载CacheManager.Redis(包含了CacheManager.Core) 下载Stack ...
- ASP.NET MVC 快速开发框架之 SqlSugar+SyntacticSugar+JQWidgetsSugar+jqwidgets(转)
jqwidgets.js: 是一个功能完整的框架,它具有专业的可触摸的jQuery插件.主题.输入验证.拖放插件.数据适配器,内置WAI-ARIA(无障碍网页应用)可访问性.国际化和MVVM模式支持. ...
- vim中大小写转换
转自:http://www.cnblogs.com/fortran/archive/2010/07/25/1784513.html vim中大小写转化的命令是:gu或者gU,形象一点的解释就是小u意味 ...
- django学习<一>:安装
这两天打算摸索下和python相关的东西,然后正好小伙伴有个关于网站的任务,就怀着好奇的心态了解了下,然后就很自然地开始涉及django的问题. 首先就是django安装的问题,想不到第一步就出问题了 ...
- Easyui中使用jquery或js动态添加元素时出现的样式失效的解决方法
Easyui中使用jquery或js动态添加元素时出现的样式失效的解决方法 2014-03-27 11:44:46| 分类: Easy UI|举报|字号 订阅 可以使用$.parser.pa ...
- [原] Android快速开发框架-AndroidFine,GitHub开源
Android快速开发框架 UI组件,不止是简单整合,更易用 沉浸式状态栏,界面更漂亮 左滑返回,非常流畅 简单.可复用.易扩展的底部导航 PagerSlidingTabStrip,导航标签文字颜色和 ...
- 调用shell脚本,IP处理
//调用shell脚本,IP处理 package com.letv.sdns.web.utils; import org.slf4j.Logger; import org.slf4j.LoggerFa ...
- [转]C++模板学习
1. 模板的概念. 我们已经学过重载(Overloading),对重载函数而言,C++的检查机制能通过函数参数的不同及所属类的不同.正确的调用重载函数.例如,为求两个数的最大值,我们定义MAX()函数 ...
- MFC Edit控件 追加文本
// 追加文本到EditControl void InstmDebugMainDlg::AppendText(int controlId, CString strAdd) { ((CEdit* ...