火多多 发表于 2017-7-19 16:20:26

写的一个卡通shader

我初学者   大家多多指导

Shader "MyToon/Toon-Surface_Normal" {
    Properties {
      _MainTex ("Base (RGB)", 2D) = "white" {}
      _Bump ("Bump", 2D) = "bump" {}
      _Ramp ("Ramp Texture", 2D) = "white" {}
      _Tooniness ("Tooniness", Range(0.1,20)) = 4

      _OutlineColor("Outline Color", Color) = (0,0,0,1)
                _Outline("Outline Width", Range(.0, 2)) = .5
    }
    SubShader {
      Tags { "RenderType"="Opaque" }
      LOD 200

      CGPROGRAM
      #pragma surface surf Toon

      sampler2D _MainTex;
      sampler2D _Bump;
      sampler2D _Ramp;
      float _Tooniness;
      float _Outline;

      struct Input {
            float2 uv_MainTex;
            float2 uv_Bump;
            float3 viewDir;
      };

      void surf (Input IN, inout SurfaceOutput o) {
            half4 c = tex2D (_MainTex, IN.uv_MainTex);
            o.Normal = UnpackNormal( tex2D(_Bump, IN.uv_Bump));

            half edge = saturate(dot (o.Normal, normalize(IN.viewDir)));   
            edge = edge < _Outline ? edge/4 : 1;

            o.Albedo = (floor(c.rgb * _Tooniness)/_Tooniness) * edge;
            o.Alpha = c.a;
      }

      half4 LightingToon(SurfaceOutput s, fixed3 lightDir, half3 viewDir, fixed atten)
      {
            float difLight = dot (s.Normal, lightDir);
            float dif_hLambert = difLight * 0.5 + 0.5;   

            float rimLight = dot (s.Normal, viewDir);   
            float rim_hLambert = rimLight * 0.5 + 0.5;   

            float3 ramp = tex2D(_Ramp, float2(rim_hLambert, dif_hLambert)).rgb;   

            float4 c;   
            c.rgb = s.Albedo * _LightColor0.rgb * ramp * atten * 2;
            c.a = s.Alpha;
            return c;
      }

      ENDCG
Tags { "RenderType"="Opaque" }
                ZWrite on
                Cull Front
                CGPROGRAM
       #pragma surface surf Standard fullforwardshadows vertex:vert
                #include "UnityCG.cginc"
                #pragma target 3.0

                struct Input {
                        float2 uv_MainTex;
                };


                float4 _OutlineColor;
                inline fixed4 LightingOutline(SurfaceOutputStandard s, UnityGI gi)
                {
                        return _OutlineColor;
                }
                inline void LightingOutline_GI(SurfaceOutputStandard s, UnityGIInput data, inout UnityGI gi)
                {
                        gi = UnityGlobalIllumination(data, 1.0, s.Normal);
                }

                float _Outline;
      
      void vert (inout appdata_full v) {
                              
                v.vertex.xyz+=v.normal*_Outline;
      }

          void surf (Input IN, inout SurfaceOutputStandard o) {
                        o.Albedo = _OutlineColor;
                        o.Alpha = 1;
                }
          ENDCG
    }   
    FallBack "Diffuse"
}
借用网上模型如果有IP之类冲突联系我删除   !!




YuFeiNiao 发表于 2017-7-20 10:05:15

没有效果图,,看不懂~~~~·

火多多 发表于 2017-7-20 11:55:18

linnan0807 发表于 2017-7-20 10:05
没有效果图,,看不懂~~~~·

之前不知道 怎么发图刚刚加上

星爷万岁 发表于 2017-7-20 16:18:08

不错的shader

火多多 发表于 2017-7-21 12:29:41

星爷万岁 发表于 2017-7-20 16:18
不错的shader

我是初学者多多指导

汉堡 发表于 2017-8-22 11:01:36

没图不懂

idrsky 发表于 2017-9-5 17:24:25


看看

炽炎红尘 发表于 2018-10-18 10:21:52

请选择您此刻的心情图片并写下今天最想说的话!

tim_chen 发表于 2018-11-22 13:41:26

下午好

⊙_⌒咚 发表于 2018-11-22 13:42:54

不知道怎么用

tyzyu 发表于 2018-11-22 14:13:46

从业不识微元素,做遍项目也枉然

qq_奔波儿灞_xU9 发表于 2020-12-3 15:55:08

666666666666666666666

神佛之上 发表于 2022-11-22 23:28:32

给力!元素有你更精彩
页: [1]
查看完整版本: 写的一个卡通shader