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. ...
随机推荐
- 配置文件操作模块,configparser
configparser configparser用于处理特定格式的文件,其本质上是利用open来操作文件. # 注释1 ; 注释2 [section1] # 节点 k1 = v1 # 值 k2:v2 ...
- IOS开发中@2x图片等适应不同分辨率手机
开发中,例如: nanshanImage.image=[UIImage imageNamed:@'index_pic.png']; 在项目中还保存中index_pic@2x.png的图片,此图为了只适 ...
- step 3 socket
socket 网络通讯三要素 IP地址(主机名) 网络中设备的标示 不易记忆,可以用主机名 本地回环地址:127.0.0.1 主机名:localhost 每台计算机都有一个 127.0.0.1 如果 ...
- oracle vm virtualbox右ctrl切换显示模式
转自: http://blog.csdn.net/lyc_daniel/article/details/44195515 virtualbox里面有个HOME键,注意这个HOME键不一定是键盘上的HO ...
- CF460D Little Victor and Set (找规律)
D - Little Victor and Set Codeforces Round #262 (Div. 2) D D. Little Victor and Set time limit per t ...
- 8-Highcharts曲线图之对数直线图
<!DOCTYPE> <html lang='en'> <head> <title>8-Highcharts曲线图之对数直线图</title> ...
- oracle中的number类型
number 数据类型 number (precision,scale) a) precision表示数字中的有效位,如果没有指定precision的话,oracle将使用38作为精度: b) ...
- 从svn检出项目---------不是web项目
javaweb项目从svn检出变成java项目 javaweb项目从svn检出后变成java项目,解决办法是: 1.项目右键–properties–Project Facets,勾选上Dynamic ...
- Markdown 写作工具选择
Markdown 写作工具选择 候选产品 参考了少数派网站 markdown 写作工具2015年度盘点 http://sspai.com/32483, Windows 下 Markdown 的编辑工具 ...
- poj3070 Fibonacci
Description In the Fibonacci integer sequence, F0 = 0, F1 = 1, and Fn = Fn − 1 + Fn − 2 for n ≥ 2. F ...