自定義光照模型

Shader "Custom/LightingModule"{

	Properties{
		_MainColor("Base Color",color) = (1,1,1,1)
		_AmibentColor("Amient Color",color) = (1,1,1,1)
		_MySliderValue("This Slider",range(0,10)) = 2.5
		_RampTex ("Ramp Texture", 2D) = "white"{}  
	}

	SubShader{
		Tags { "RenderType" = "Opaque" }
		LOD 200
		CGPROGRAM
			#pragma surface suf BasicDiffuse

			float4  _MainColor;
			float4	_AmibentColor;
			float 	_MySliderValue;
			sampler2D 	_RampTex;

			struct Input{
				float2 uv_MainTex;
			};

			void suf (Input IN,inout SurfaceOutput o )
			{
				float4 c = pow((_MainColor + _AmibentColor),_MySliderValue);
				o.Albedo = c.rgb;
				o.Alpha  = c.a;
			}

			//-------------------基於半蘭伯特光照模型---------------------------//
			//自定義光照模型 函數必須要以 Lighting 開頭  
			inline float4 LightingBasicDiffuse(SurfaceOutput s,fixed3 lightDirection,fixed atten)
			{
		 	  	float difLight = max(0, dot (s.Normal, lightDirection));
	       	  	// Add this line  
	       	  	float hLambert = difLight * 0.5 + 0.5;

	       	  	float3 ramp = tex2D(_RampTex, float2(hLambert,1)).rgb;  

	       	  	float4 col;
	       	  	// Modify this line
	       	  	col.rgb = s.Albedo * _LightColor0.rgb  * ramp;
	       	  	col.a = s.Alpha;
	       	  	return col;
			}
			//-------------------基於蘭伯特光照模型---------------------------//
//	       inline float4 LightingBasicDiffuse (SurfaceOutput s, fixed3 lightDir, fixed atten)
//	       	{
//	       	  	float difLight = max(0, dot (s.Normal, lightDir));
//	       	  	float4 col;
//	       	  	col.rgb = s.Albedo * _LightColor0.rgb * (difLight * atten * 2);
//	       	  	col.a = s.Alpha;
//	       	  	return col;
//			}

		ENDCG
	}


	FallBack "Diffuse"
}

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