自定义光照模型

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"
}

你可能感兴趣的:(shader)