参考《Unity Shaders and Effects CookBook》
屏幕特效不仅仅限于颜色控制RenderTexture,同事还可以结合图片和RenderTexture的混合,这种技术和PhotoShop新建一个 层级,然后选择混合模式,混合两张图片是一样的,但是Untiy里的效果更艺术,整个场景的立体效果都蒙上这种效果,混合模式有Multiplay,Add,Overlay三种模式。
然后基本的原理和动作跟上一篇灰度屏幕特效类似。
下面我们分别看下三种混合模式的屏幕特效:
1.Multiply混合模式
首先看脚本:
Shader脚本:
Shader "MyShaders/BlendImageEffect"
{
Properties
{
_MainTex("Base (RGB)", 2D) = "white" {}
_BlendTex("Blend Texture", 2D) = "white"{}
_Opacity("Blend Opacity", Range(0,1)) = 1
}
SubShader
{
Pass
{
CGPROGRAM
#pragma vertex vert_img
#pragma fragment frag
#pragma fragmentoption ARB_precision_hint_fastest
#include "UnityCG.cginc"
uniform sampler2D _MainTex;
uniform sampler2D _BlendTex;
fixed _Opacity;
fixed4 frag(v2f_img i) : COLOR
{
//Get the colors from the RenderTexture and the uv's
//from the v2f_img struct
fixed4 renderTex = tex2D(_MainTex, i.uv);
fixed4 blendTex = tex2D(_BlendTex, i.uv);
//Perform a multiply Blend mode
fixed4 blendedMultiply = renderTex * blendTex;
//Adjust amount of Blend Mode with a lerp
renderTex = lerp(renderTex, blendedMultiply, _Opacity);
return renderTex;
}
ENDCG
}
}
FallBack off
}
cs脚本:
using UnityEngine;
using System.Collections;
[ExecuteInEditMode]
public class BlendImageEffect : MonoBehaviour
{