1.挂载cs脚本,拖入材质球
using UnityEngine;
using System.Collections;
[ExecuteInEditMode]
public class FadeBack : MonoBehaviour
{
[SerializeField]
private Material m_Material;
// Use this for initialization
void Start()
{
//OnRenderImage()
}
// Update is called once per frame
void Update()
{
}
void OnRenderImage(RenderTexture source, RenderTexture destination)
{
//RenderTexture src0 = RenderTexture.GetTemporary(source.width, source.height);
//m_Material.SetTexture("_MainTex", source);
//Graphics.Blit(source, src0, m_Material, 0);
//Graphics.Blit(src0, destination);
//RenderTexture.ReleaseTemporary(src0);
Graphics.Blit(source, destination, m_Material);
}
}
2.随着时间变暗效果实现
// Upgrade NOTE: replaced 'mul(UNITY_MATRIX_MVP,*)' with 'UnityObjectToClipPos(*)'
Shader "szw/OVRScreenFade2"
{
Properties
{
_MainTex("Texture", 2D) = "white" {}
}
SubShader
{
// No culling or depth top set
Cull Off ZWrite On ZTest Always
Pass
{
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#include "UnityCG.cginc"
struct appdata
{
float4 vertex : POSITION;
float2 uv : TEXCOORD0;
};
struct v2f
{
float2 uv : TEXCOORD0;
float4 vertex : SV_POSITION;
};
v2f vert(appdata v)
{
v2f o;
o.vertex = UnityObjectToClipPos(v.vertex);
o.uv = v.uv;
return o;
}
uniform float _Timer;
uniform sampler2D _MainTex;
fixed4 frag(v2f i) : SV_Target
{
fixed4 col = tex2D(_MainTex, i.uv);
fixed4 black = 1 - fixed4(_Time.yyy / 2, 1);
col *= black;
return col;
}
ENDCG
}
}
}