Unity Shaders——屏幕特效混合模式(Blend mode with screen effects)


       参考《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
{

  • 2
    点赞
  • 12
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值