查看: 1904|回复: 2
打印 上一主题 下一主题

[Shaders] 各向异性高光Shader

[复制链接]

2317

主题

54

听众

2万

积分

资深设计师

Rank: 7Rank: 7Rank: 7

纳金币
20645
精华
62

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

跳转到指定楼层
楼主
发表于 2014-4-30 22:45:20 |只看该作者 |倒序浏览
这个shader可以用来做一做各种餐具的shader:
  1. Shader "Bumped Anisotropic Specular" {

  2.      Properties {

  3.          _Color ("Main Color", Color) = (1,1,1,1)

  4.          _MainTex ("Diffuse (RGB) Alpha (A)", 2D) = "white" {}

  5.          _SpecularTex ("Specular (R) Gloss (G) Anisotropic Mask (B)", 2D) = "gray" {}

  6.          _BumpMap ("Normal (Normal)", 2D) = "bump" {}

  7.          _AnisoTex ("Anisotropic Direction (RGB)", 2D) = "bump" {}

  8.          _AnisoOffset ("Anisotropic Highlight Offset", Range(-1,1)) = -0.2

  9.          _Cutoff ("Alpha Cut-Off Threshold", Range(0,1)) = 0.5

  10.      }
  11.      SubShader{

  12.          Tags { "RenderType" = "Opaque" }

  13.      

  14.          CGPROGRAM

  15.          

  16.              struct SurfaceOutputAniso {

  17.                  fixed3 Albedo;

  18.                  fixed3 Normal;

  19.                  fixed4 AnisoDir;

  20.                  fixed3 Emission;

  21.                  half Specular;

  22.                  fixed Gloss;

  23.                  fixed Alpha;

  24.              };
  25.              float _AnisoOffset, _Cutoff;

  26.              inline fixed4 LightingAniso (SurfaceOutputAniso s, fixed3 lightDir, fixed3 viewDir, fixed atten)

  27.              {

  28.                 fixed3 h = normalize(normalize(lightDir) + normalize(viewDir));

  29.                 float NdotL = saturate(dot(s.Normal, lightDir));
  30.                 fixed HdotA = dot(normalize(s.Normal + s.AnisoDir.rgb), h);

  31.                 float aniso = max(0, sin(radians((HdotA + _AnisoOffset) * 180)));
  32.                 float spec = saturate(dot(s.Normal, h));

  33.                 spec = saturate(pow(lerp(spec, aniso, s.AnisoDir.a), s.Gloss * 128) * s.Specular);
  34.                 fixed4 c;

  35.                 c.rgb = ((s.Albedo * _LightColor0.rgb * NdotL) + (_LightColor0.rgb * spec)) * (atten * 2);

  36.                 c.a = 1;

  37.                 clip(s.Alpha - _Cutoff);

  38.                 return c;

  39.              }
  40.              #pragma surface surf Aniso

  41.              #pragma target 3.0

  42.             

  43.              struct Input

  44.              {

  45.                  float2 uv_MainTex;

  46.                  float2 uv_AnisoTex;

  47.              };

  48.             

  49.              sampler2D _MainTex, _SpecularTex, _BumpMap, _AnisoTex;

  50.                  

  51.              void surf (Input IN, inout SurfaceOutputAniso o)

  52.              {

  53.                 fixed4 albedo = tex2D(_MainTex, IN.uv_MainTex);

  54.                  o.Albedo = albedo.rgb;

  55.                  o.Alpha = albedo.a;

  56.                  o.Normal = UnpackNormal(tex2D(_BumpMap, IN.uv_MainTex));

  57.                  fixed3 spec = tex2D(_SpecularTex, IN.uv_MainTex).rgb;

  58.                  o.Specular = spec.r;

  59.                  o.Gloss = spec.g;

  60.                  o.AnisoDir = fixed4(tex2D(_AnisoTex, IN.uv_AnisoTex).rgb, spec.b);

  61.              }

  62.          ENDCG

  63.      }

  64.      FallBack "Transparent/Cutout/VertexLit"

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

使用道具 举报

1

主题

0

听众

372

积分

设计实习生

Rank: 2

纳金币
4
精华
0

最佳新人

沙发
发表于 2014-5-2 17:21:00 |只看该作者
不错,,崇拜!!!
回复

使用道具 举报

1

主题

1

听众

4795

积分

中级设计师

Rank: 5Rank: 5

纳金币
955
精华
0

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

板凳
发表于 2014-5-23 11:45:21 |只看该作者
感谢楼主分享
回复

使用道具 举报

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

关闭

站长推荐上一条 /1 下一条

手机版|纳金网 ( 闽ICP备08008928号

GMT+8, 2024-5-14 02:16 , Processed in 0.124628 second(s), 33 queries .

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

© 2008-2019 Narkii Inc.

回顶部