Shade学习记录点滴02

在前一篇的基础上,加入图片并绘制出来图片的色彩。

在Propertices中加入_RampTex("Ramp Textrue", 2D) = " "{ }

然后在SubShader中CGPROGRAM 结构体中加入  #pragma surface surf BasicDiffuse 添加sampler2D _RampTex;

  inline float4 LightBasicDiffuse(SurfaceOutput s , fixed3 lightDir ,fixed atten)

          float difLight = dot(s.Normal,lightDir);

          float rimLight = dot(s.Normal , viewDir);

          float hLambert = difLight * 0.5 + 0.5;

          //加入2D图片

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


        float4 col;

       col.rgb = s.Albedo * _LightColor0.rgb * (hLambert * atten * 2);

      // col.rgb = s.Albedo * _LightColor0.rgb *  (ramp);

      col.a = s.Alpha;

       return col;         

}

加入图片 以及加入 ViewDirection 

 inline float4 LightBasicDiffuse(SurfaceOutput s , fixed3 lightDir , fixed3 viewDir, fixed atten)

          float difLight = dot(s.Normal,lightDir);

          float rimLight = dot(s.Normal , viewDir);

          float hLambert = difLight * 0.5 + 0.5;

          //加入2D图片。转换为rgb的模式

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


        float4 col;

       col.rgb = s.Albedo * _LightColor0.rgb * (hLambert * atten * 2);

       col.rgb = s.Albedo * _LightColor0.rgb *  (ramp);

      col.a = s.Alpha;

       return col;         

}

在LightBasicDiffuse函数中 加入 fiexed3 ViewDir然后出现的,相关的原理如下


编写出来出现的效果,如下图所示:


面板层的具体参数设置如下图所示:



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值