<Shader> 自定义光照模型

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

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值