Shader Anisotropic 各项异性

来源:互联网 发布:怎么手机修改淘宝评价 编辑:程序博客网 时间:2024/04/30 17:12

在金属管,CD光碟上常看到这样的效果。水波纹也能形成这样的Specular 反射。


实际上就是因为物体上有水波纹这样的高低起伏的表面,让本来该平滑延展的Specular反射,也变得褶皱。


这是要改变光照模型。


用法线贴图来采样褶皱方向。





Properties{_MainTint("Diffuse Tint", Color) = (1,1,1,1)_MainTex("Base (RGB)", 2D) = "white" {}_SpecularColor("specular Color", Color) = (1,1,1,1)_Specular("Specular Amount", Range(0,1)) = 0.5_SpecPower("Specular Power", Range(0,1)) = 0.5_AnisoDir("Anisotropic Direction", 2D) = "" {}_AnisoOffset("Anisotropic Offset", Range(-1,1)) = -0.2}SubShader{Tags{ "RenderType" = "Opaque" }LOD 200CGPROGRAM#pragma surface surf Anisotropic#pragma target 3.0sampler2D _MainTex;sampler2D _AnisoDir;float4 _MainTint;float4 _SpecularColor;float _AnisoOffset;float _Specular;float _SpecPower;struct SurfaceAnisoOutput{fixed3 Albedo;fixed3 Normal;fixed3 Emission;fixed3 AnisoDirection;half Specular;fixed Gloss;fixed Alpha;};inline fixed4 LightingAnisotropic(SurfaceAnisoOutput s, fixed3 lightDir, half3 viewDir, fixed atten){fixed3 halfVector = normalize(normalize(lightDir) + normalize(viewDir));float NdotL = saturate(dot(s.Normal, lightDir));fixed HdotA = dot(normalize(s.Normal + s.AnisoDirection), halfVector);float aniso = max(0, sin(radians((HdotA + _AnisoOffset) * 180)));float spec = saturate(pow(aniso, s.Gloss * 128) * s.Specular);fixed4 c;c.rgb = ((s.Albedo * _LightColor0.rgb * NdotL) + (_LightColor0.rgb * _SpecularColor.rgb * spec)) * (atten);c.a = 1.0;return c;}struct Input{float2 uv_MainTex;float2 uv_AnisoDir;};void surf(Input IN, inout SurfaceAnisoOutput o){half4 c = tex2D(_MainTex, IN.uv_MainTex) * _MainTint;float3 anisoTex = UnpackNormal(tex2D(_AnisoDir, IN.uv_AnisoDir));o.AnisoDirection = anisoTex;o.Specular = _Specular;o.Gloss = _SpecPower;o.Albedo = c.rgb;o.Alpha = c.a;}ENDCG}FallBack "Diffuse"


原创粉丝点击