场景淡入淡出
SceneFadeInAndOut.cs
==============================================================
using UnityEngine;
using System.Collections;
public class SceneFadeInAndOut : MonoBehaviour {
public Material ma;
//初始化
void Start () {
ma = new Material(Shader.Find("Custom/SceneFadeInAndOut")); //创建一个材质
}
//这允许你使用基于shader的过滤器来处理最后的图片,
//进入的图片是source渲染纹理,结果是destination渲染纹理。
void OnRenderImage (RenderTexture source, RenderTexture destination) {
//拷贝源纹理到目的渲染纹理。这主要是用于实现图像效果。
//Blit设置dest到激活的渲染纹理,在材质上设置source作为
//_MainTex属性,并且绘制一个全屏方块。
Graphics.Blit(source, destination, ma);
}
}
SceneFadeInAndOut.shader
=============================================================
Shader "Custom/SceneFadeInAndOut" {
Properties{
_MainTex("Base (RGB)", 2D) = "white" {}
_Float1("Float1",Float) = 0.0
}
SubShader{
Pass{
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
uniform sampler2D _MainTex;
uniform float _Float1;
struct Input {
float4 pos : POSITION;
float2 uv : TEXCOORD0;
};
struct v2f {
float4 pos : POSITION;
float2 uv : TEXCOORD0;
};
v2f vert(Input i) {
v2f o;
o.pos = mul(UNITY_MATRIX_MVP, i.pos);
o.uv = i.uv;
return o;
}
float4 frag(v2f i) : COLOR{
float4 outColor;
outColor = tex2D(_MainTex, i.uv) + _Float1;
return outColor;
}
ENDCG
}
}
Fallback off
}