查看: 1474|回复: 0
打印 上一主题 下一主题

可以用来做头发调光及金属表面效果的shade

[复制链接]

5552

主题

2

听众

8万

积分

首席设计师

Rank: 8Rank: 8

纳金币
-1
精华
11

最佳新人 活跃会员 热心会员 灌水之王 突出贡献

跳转到指定楼层
楼主
发表于 2012-6-27 14:49:07 |只看该作者 |倒序浏览
这个shader可以用来做头发调光及金属表面效果,下面是代码:
这个shader可以用来做头发调光及金属表面效果,下面是代码:复制内容到剪贴板代码:

Shader "Bumped Anisotropic Specular" {
      Properties {
          _Color ("Main Color", Color) = (1,1,1,1)
          _MainTex ("Diffuse (RGB) Alpha (A)", 2D) = "white" {}
          _SpecularTex ("Specular (R) Gloss (G) Anisotropic Mask (B)", 2D) = "gray" {}
          _BumpMap ("Normal (Normal)", 2D) = "bump" {}
          _AnisoTex ("Anisotropic Direction (RGB)", 2D) = "bump" {}
          _AnisoOffset ("Anisotropic Highlight Offset", Range(-1,1)) = -0.2
          _Cutoff ("Alpha Cut-Off Threshold", Range(0,1)) = 0.5
      }

      SubShader{
          Tags { "RenderType" = "Opaque" }
     
          CGPROGRAM
         
              s***ct SurfaceOutputAniso {
                  fixed3 Albedo;
                  fixed3 Normal;
                  fixed4 AnisoDir;
                  fixed3 Emission;
                  half Specular;
                  fixed Gloss;
                  fixed Alpha;
              };

              float _AnisoOffset, _Cutoff;
              inline fixed4 LightingAniso (SurfaceOutputAniso s, fixed3 lightDir, fixed3 viewDir, fixed atten)
              {
                 fixed3 h = normalize(normalize(lightDir) + normalize(viewDir));
                 float NdotL = saturate(dot(s.Normal, lightDir));

                 fixed HdotA = dot(normalize(s.Normal + s.AnisoDir.rgb), h);
                 float aniso = max(0, sin(radians((HdotA + _AnisoOffset) * 180)));

                 float spec = saturate(dot(s.Normal, h));
                 spec = saturate(pow(lerp(spec, aniso, s.AnisoDir.a), s.Gloss * 128) * s.Specular);

                 fixed4 c;
                 c.rgb = ((s.Albedo * _LightColor0.rgb * NdotL) + (_LightColor0.rgb * spec)) * (atten * 2);
                 c.a = 1;
                 clip(s.Alpha - _Cutoff);
                 return c;
              }

              #pragma surface surf Aniso
              #pragma target 3.0
            
              s***ct Input
              {
                  float2 uv_MainTex;
                  float2 uv_AnisoTex;
              };
            
              sampler2D _MainTex, _SpecularTex, _BumpMap, _AnisoTex;
                 
              void surf (Input IN, inout SurfaceOutputAniso o)
              {
                 fixed4 albedo = tex2D(_MainTex, IN.uv_MainTex);
                  o.Albedo = albedo.rgb;
                  o.Alpha = albedo.a;
                  o.Normal = UnpackNormal(tex2D(_BumpMap, IN.uv_MainTex));
                  fixed3 spec = tex2D(_SpecularTex, IN.uv_MainTex).rgb;
                  o.Specular = spec.r;
                  o.Gloss = spec.g;
                  o.AnisoDir = fixed4(tex2D(_AnisoTex, IN.uv_AnisoTex).rgb, spec.b);
              }
          ENDCG
      }
      FallBack "Transparent/Cutout/VertexLit"
}

分享到: QQ好友和群QQ好友和群 腾讯微博腾讯微博 腾讯朋友腾讯朋友 微信微信
转播转播0 分享淘帖0 收藏收藏0 支持支持0 反对反对0
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

手机版|纳金网 ( 闽ICP备2021016425号-2/3

GMT+8, 2025-2-8 18:55 , Processed in 0.063742 second(s), 28 queries .

Powered by Discuz!-创意设计 X2.5

© 2008-2019 Narkii Inc.

回顶部