<Shader> 自定义光照模型

来源:互联网 发布:淘宝网免费活动 编辑:程序博客网 时间:2024/06/04 18:55
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 200CGPROGRAM#pragma surface suf BasicDiffusefloat4  _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"}

原创粉丝点击