纳金网

标题: 各向异性高光shader [打印本页]

作者: 晃晃    时间: 2011-8-26 08:34
标题: 各向异性高光shader
这个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

         

             struct 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

            

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

}
作者: Mr.cai    时间: 2011-8-27 10:43
2D转3D 哈哈
作者: 晃晃    时间: 2012-2-15 23:23
好可爱的字,学习了

作者: 晃晃    时间: 2012-2-19 23:22
顶!学习了!阅!

作者: 晃晃    时间: 2012-3-2 23:18
顶!学习了!阅!

作者: 奇    时间: 2012-3-25 23:30
好铁多多发,感激分享

作者: 奇    时间: 2012-4-30 23:25
读铁系缘分,顶铁系友情

作者: 菜刀吻电线    时间: 2012-6-21 23:20
既来之,则看之!

作者: 晃晃    时间: 2012-7-8 23:20
无聊时可以刷屏幕 灌水 也可以试试 帖子的标题究竟可以写多长

作者: C.R.CAN    时间: 2012-7-28 23:20
很经典,很实用,学习了!

作者: 菜刀吻电线    时间: 2012-7-30 23:26
好铁多多发,感激分享

作者: C.R.CAN    时间: 2012-10-15 23:21
不错不错,收藏了

作者: tc    时间: 2012-10-19 23:34
不错哦,谢谢楼主

作者: 菜刀吻电线    时间: 2013-1-25 23:21
先垫一块,再说鸟

作者: 晃晃    时间: 2013-2-28 23:19
其实楼主所说的这些,俺支很少用!

作者: 奇    时间: 2013-3-10 23:32
既来之,则看之!





欢迎光临 纳金网 (http://go.narkii.com/club/) Powered by Discuz! X2.5