1. 程式人生 > >Shader 學習02:屬性發認識2與圖片混合公式

Shader 學習02:屬性發認識2與圖片混合公式

Shader "Hidden/NewImageEffectShader"
{
	Properties
	{
		_MainTex ("Texture", 2D) = "white" {}
		_BlendTex ("Texture", 2D) = "white" {}
		_ConstanctColor("Color",color)=(1,0,0,1)
	}
	SubShader
	{
		// No culling or depth
		Cull Off ZWrite Off ZTest Always

		Pass
		{
			color(1,0,0,1)
			//SetTexture[_MainTex]	_MainTex:文理變數
			//Previous  表示前面一個SetTexture出來以後的畫素值
			//Primary	表示頂點計算出來的顏色
			//Texture	等於SetTexture當前文理的變數
			//Constant	表示一個固定的顏色(1,1,1,1)

			//更改圖片 _MainTex
			SetTexture[_MainTex]
			{//越乘越暗  越加越亮
				combine	Primary*Texture  
			}
			//更改圖片 _BlendTex
			SetTexture[_BlendTex]
			{
			 //圖片混合公式
			 //Lerp插值
			 //讓SetTexture1與SetTexture3進行混合
			 //	混合的方式  取決於SetTexture2的alpha值:
			 //(1-t)A+tB
			 //  結合       前一個      插值 
				combine 	Previous	Lerp(Texture)	 Texture
			}

			SetTexture[_BlendTex]
			{
			 //兩種寫法
			 //constantColor(1,0,0,1)
				constantColor[_ConstanctColor]
			 // 結合  Texture等於SetTexture當前文理的變數 * constabtColor(1,0,0,1)設定後就等於Constant
				combine Texture*Constant
			}
		}
	}
}