SurfaceShader 透明效果

Shader "Custom/StereoRenderShader"
{
	Properties
	{
		_Color("Color", Color) = (0,0,255,1)
		_Alpha("Alpha" , Range(0,3))=  1  
		_LeftEyeTexture("Left Eye Texture", 2D) = "white" {}    //主紋理,外來的貼圖
		_LeftLerpNum("LeftLerpNum" , Range(0,1)) = 0.5
		_RightEyeTexture("Right Eye Texture", 2D) = "white" {}
		_RightLerpNum("RightLerpNum" , Range(0,1)) = 0.5
		//[Space(45)][Header(Transparency Properties)]
		//[Space(10)][MaterialToggle] _UseDirtmapasTransparencymap("Use Dirt map as Transparency map", Float) = 0.5
		//_Transparency("Transparency", Range(0, 1)) = 0.5
		//[HideInInspector]_Cutoff("Alpha cutoff", Range(0,1)) = 0.5
	}

	CGINCLUDE
	#include "UnityCG.cginc"
	#include "UnityInstancing.cginc"
	ENDCG

	SubShader
	{
		Tags { "RenderType" = "Opaque" "Queue" = "Transparent"}

		LOD 200

		CGPROGRAM
    	//#pragma surface surf Lambert alpha  //原來的
		#pragma surface surf BlinnPhong alpha

		sampler2D _LeftEyeTexture;
		sampler2D _RightEyeTexture;
		fixed _Alpha;
		fixed4 _Color;
		fixed _LeftLerpNum;
		fixed _RightLerpNum;
		//fixed _Color;

		struct Input
		{
			float2 uv_MainTex;
			float4 screenPos;
		};

		void surf(Input IN, inout SurfaceOutput o)
		{
			float2 screenUV = IN.screenPos.xy / IN.screenPos.w;

#if UNITY_SINGLE_PASS_STEREO
			float4 scaleOffset = unity_StereoScaleOffset[unity_StereoEyeIndex];
			screenUV = (screenUV - scaleOffset.zw) / scaleOffset.xy;
#endif
			if (unity_StereoEyeIndex == 0)
			{
				fixed4 color = tex2D(_LeftEyeTexture, screenUV);
				fixed3 outColor = _LeftLerpNum * color.rgb + (1 - _LeftLerpNum) * _Color.rgb;
				o.Albedo = outColor;
				o.Alpha = color.a * _Alpha;
			}
			else
			{
				fixed4 color = tex2D(_RightEyeTexture, screenUV);
				fixed3 outColor = _LeftLerpNum * color.rgb + (1 - _LeftLerpNum) * _Color.rgb;
				o.Albedo = outColor;
				o.Alpha = color.a * _Alpha;
			}
		}

		ENDCG
	}

	Fallback "Diffuse"
}

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章