UnityShader---SurfaceShader(模板和各种效果实现:边缘自发光、火焰流动、燃烧、法线扭曲、简单模糊、消融、区域过度、雪效果等)---17

模板:

//自定义表面着色器:自定义四个函数

Shader "Custom/39"
{
    Properties
    {
        _Color ("Color", Color) = (1,1,1,1)
        _MainTex ("Albedo (RGB)", 2D) = "white" {}
        _BumpMap("BumpMap",2D)="bump"{}
        _Amount("Amount",Range(-0.1,0.1))=0
    }
    SubShader
    {
        Tags{"RenderType"="Transparent"}
        Lod 300
        Blend SrcAlpha OneMinusSrcAlpha

        CGPROGRAM
        //编译指令:#pragma surface 表面函数名 光照模型名(可自定义) vertex:自定义的顶点函数 finalcolor:自定义的修改最终颜色函数 【其他参数:addshadow(添加阴影)exclude_path:deferred exclude_path:prepass(排除的Pass)nometa(不生成meta Pass)】
        #pragma surface surf CustomLambert vertex:myvert finalcolor:mycolor addshadow exclude_path:deferred exclude_path:prepass nometa
        #pragma target 3.0

        fixed4 _Color;
        sampler2D _MainTex;
        sampler2D _BumpMap;
        fixed _Amount;

        struct Input
        {
            //UV命名规范:uv+参数名
            float2 uv_MainTex;
            float2 uv_BumpMap;
        };

        void myvert(inout appdata_full v)
        {
            v.vertex.xyz += v.normal * _Amount;
        }

        void surf(Input IN, inout SurfaceOutput o)
        {
            fixed4 tex = tex2D(_MainTex,IN.uv_MainTex);
            o.Albedo = tex.rgb;
            o.Alpha = tex.a;
            o.Normal = UnpackNormal(tex2D(_BumpMap,IN.uv_BumpMap));
        }

        half4 LightingCustomLambert(SurfaceOutput s, half3 lightDir, half atten)
        {
            half ndotl = dot(s.Normal,lightDir);
            half4 c;
            c.rgb = s.Albedo * _LightColor0.rgb * ndotl * atten;
            c.a = s.Alpha;
            return c;
        }

        void mycolor(Input IN, SurfaceOutput o, inout fixed4 color)
        {
            color *= _Color;
        }

        ENDCG
    }
    FallBack "Diffuse"
}

Blinn-Phong高光:

Shader "Custom/Surface01"
{
    Properties
    {
        _Color ("Color", Color) = (1,1,1,1)
        _MainTex ("Albedo (RGB)", 2D) = "white" {}
		_SpecColor ("SpecColor", Color) = (1,1,1,1)
        _Gloss ("Gloss", Range(0,1)) = 0.5
        _Specular ("Specular", Range(0,1)) = 0.0
    }
    SubShader
    {
        Tags { "RenderType"="Opaque" }
        LOD 200

        CGPROGRAM
        // Physically based Standard lighting model, and enable shadows on all light types
        #pragma surface surf BlinnPhong fullforwardshadows

        // Use shader model 3.0 target, to get nicer looking lighting
        #pragma target 3.0

        sampler2D _MainTex;

        struct Input
        {
            float2 uv_MainTex;
        };

        half _Gloss;
        half _Specular;
        fixed4 _Color;

        // Add instancing support for this shader. You need to check 'Enable Instancing' on materials that use the shader.
        // See https://docs.unity3d.com/Manual/GPUInstancing.html for more information about instancing.
        // #pragma instancing_options assumeuniformscaling
        UNITY_INSTANCING_BUFFER_START(Props)
            // put more per-instance properties here
        UNITY_INSTANCING_BUFFER_END(Props)

        void surf (Input IN, inout SurfaceOutput o)
        {
            // Albedo comes from a texture tinted by color
            fixed4 c = tex2D (_MainTex, IN.uv_MainTex) * _Color;
            o.Albedo = c.rgb;
            // Metallic and smoothness come from slider variables
            o.Specular = _Specular;
            o.Gloss = _Gloss;
            o.Alpha = c.a;
        }
        ENDCG
    }
    FallBack "Diffuse"
}

法线贴图采样:

Shader "Custom/Surface02"
{
    Properties
    {
        _Color ("Color", Color) = (1,1,1,1)
        _MainTex ("Albedo (RGB)", 2D) = "white" {}
        _Glossiness ("Smoothness", Range(0,1)) = 0.5
        _Metallic ("Metallic", Range(0,1)) = 0.0
		_BumpMap("Bumpmap", 2D) = "bump"{}
		_BunmScale("BunmScale",float) = 1
		_ColorTint("Tint", Color) = (1,1,1,1)
    }
    SubShader
    {
        Tags { "RenderType"="Opaque" }
        LOD 200

        CGPROGRAM
        // Physically based Standard lighting model, and enable shadows on all light types
        #pragma surface surf Standard fullforwardshadows finalcolor:final

        // Use shader model 3.0 target, to get nicer looking lighting
        #pragma target 3.0

        sampler2D _MainTex;
		sampler2D _BumpMap;
		float _BunmScale;

        struct Input
        {
            float2 uv_MainTex;
			float2 uv_BumpMap;
        };

        half _Glossiness;
        half _Metallic;
        fixed4 _Color;
		fixed4 _ColorTint;

        // Add instancing support for this shader. You need to check 'Enable Instancing' on materials that use the shader.
        // See https://docs.unity3d.com/Manual/GPUInstancing.html for more information about instancing.
        // #pragma instancing_options assumeuniformscaling
        UNITY_INSTANCING_BUFFER_START(Props)
            // put more per-instance properties here
        UNITY_INSTANCING_BUFFER_END(Props)

        void surf (Input IN, inout SurfaceOutputStandard o)
        {
            // Albedo comes from a texture tinted by color
            fixed4 c = tex2D (_MainTex, IN.uv_MainTex) * _Color;
            o.Albedo = c.rgb;
            // Metallic and smoothness come from slider variables
            o.Metallic = _Metallic;
            o.Smoothness = _Glossiness;
            o.Alpha = c.a;
			float3 normal = UnpackNormal(tex2D(_BumpMap, IN.uv_BumpMap));
			normal.xy *= _BunmScale;
			o.Normal = normal;
        }

		void final(Input IN, SurfaceOutputStandard o, inout fixed4 color)
		{
			color *= _ColorTint;
		}
        ENDCG
    }
    FallBack "Diffuse"
}

边缘自发光:

Shader "Custom/Surface03"
{
     Properties
    {
        _Color ("Color", Color) = (1,1,1,1)
        _MainTex ("Albedo (RGB)", 2D) = "white" {}
        _Glossiness ("Smoothness", Range(0,1)) = 0.5
        _Metallic ("Metallic", Range(0,1)) = 0.0
		_BumpMap("Bumpmap", 2D) = "bump"{}
		_BunmScale("BunmScale",float) = 1
		_ColorTint("Tint", Color) = (1,1,1,1)
		_RimColor("RimColor", Color) = (1,0,0,1)
		_RimPower("RimPower", Range(0.1,8.0)) = 1
    }
    SubShader
    {
        Tags { "RenderType"="Opaque" }
        LOD 200

        CGPROGRAM
        // Physically based Standard lighting model, and enable shadows on all light types
        #pragma surface surf Standard fullforwardshadows finalcolor:final

        // Use shader model 3.0 target, to get nicer looking lighting
        #pragma target 3.0

        sampler2D _MainTex;
		sampler2D _BumpMap;
		float _BunmScale;

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

        half _Glossiness;
        half _Metallic;
        fixed4 _Color;
		fixed4 _ColorTint;
		fixed4 _RimColor;
		float _RimPower;

        // Add instancing support for this shader. You need to check 'Enable Instancing' on materials that use the shader.
        // See https://docs.unity3d.com/Manual/GPUInstancing.html for more information about instancing.
        // #pragma instancing_options assumeuniformscaling
        UNITY_INSTANCING_BUFFER_START(Props)
            // put more per-instance properties here
        UNITY_INSTANCING_BUFFER_END(Props)

        void surf (Input IN, inout SurfaceOutputStandard o)
        {
            // Albedo comes from a texture tinted by color
            fixed4 c = tex2D (_MainTex, IN.uv_MainTex) * _Color;
            o.Albedo = c.rgb;
            // Metallic and smoothness come from slider variables
            o.Metallic = _Metallic;
            o.Smoothness = _Glossiness;
            o.Alpha = c.a;
			float3 normal = UnpackNormal(tex2D(_BumpMap, IN.uv_BumpMap));
			normal.xy *= _BunmScale;
			o.Normal = normal;
			half rim = 1.0 - saturate(dot(normalize(IN.viewDir), o.Normal));
			o.Emission = _RimColor.rgb * pow(rim, _RimPower);
        }

		void final(Input IN, SurfaceOutputStandard o, inout fixed4 color)
		{
			color *= _ColorTint;
		}
        ENDCG
    }
    FallBack "Diffuse"
}

自定义卡通光照+修改最终颜色:

Shader "Custom/Surface04"
{
   Properties
    {
        _Color ("Color", Color) = (1,1,1,1)
        _MainTex ("Albedo (RGB)", 2D) = "white" {}
        _Glossiness ("Smoothness", Range(0,150)) = 120
        _Metallic ("Metallic", Range(0,1)) = 0.0
		_BumpMap("Bumpmap", 2D) = "bump"{}
		_BunmScale("BunmScale",float) = 1
		_ColorTint("Tint", Color) = (1,1,1,1)
		_RimColor("RimColor", Color) = (1,0,0,1)
		_RimPower("RimPower", Range(0.1,8.0)) = 1
		_Steps("Steps", Range(1,30)) = 1
		_ToonEffect("ToonEffect", Range(0,1)) = 0.5
		_Outline("Outline", Range(0,1)) = 0.5
		_OutlineColor("OutlineColor", Color)= (0,0,0,0)
		//Xray
		_XRayColor("XRayColor", Color) =(1,1,1,1)
		_XRayPower("XRayPower", Range(0.0001,3)) = 1
    }
    SubShader
    {
        Tags { "RenderType"="Opaque" }
        LOD 200

		Pass
		{
			Blend SrcAlpha One 
			ZWrite Off
			ZTest Greater
			CGPROGRAM
			#pragma vertex vert
			#pragma fragment frag
			#include "UnityCG.cginc"

			fixed4 _XRayColor;
			float _XRayPower;

			struct v2f
			{
				float4 vertex: SV_POSITION;
				float3  viewDir :TEXCOORD0;
				float3 normal :TEXCOORD1;
			};

			v2f vert(appdata_base v)
			{
				v2f o;
				o.vertex =  UnityObjectToClipPos(v.vertex);
				o.normal = v.normal;
				o.viewDir = ObjSpaceViewDir(v.vertex);
				return o;
			}

			fixed4 frag(v2f i):SV_Target
			{
				float rim = 1 - dot(normalize(i.normal),normalize( i.viewDir));
				return _XRayColor * pow(rim,1/_XRayPower);
			}
				
			ENDCG
		}

		Pass
		{
			Name "Outline"
			Cull Front
			CGPROGRAM
			#pragma vertex vert
			#pragma fragment frag
			#include "UnityCG.cginc"

			float _Outline;
			fixed4 _OutlineColor;

			struct v2f
			{
				float4 vertex : SV_POSITION;
			};

			v2f vert(appdata_base v)
			{
				v2f o;
				o.vertex = UnityObjectToClipPos(v.vertex);
				float3 normal = normalize(mul((float3x3)UNITY_MATRIX_IT_MV, v.normal));
				float2 viewNormal = TransformViewToProjection(normal.xy);
				o.vertex.xy += viewNormal * _Outline;
				return o;
			}

			float4 frag(v2f i) : SV_Target
			{
				return _OutlineColor;
			}

			ENDCG
		}

        CGPROGRAM
        // Physically based Standard lighting model, and enable shadows on all light types
        #pragma surface surf Toon fullforwardshadows nolightmap finalcolor:final

        // Use shader model 3.0 target, to get nicer looking lighting
        #pragma target 3.0

        sampler2D _MainTex;
		sampler2D _BumpMap;
		float _BunmScale;

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

        half _Glossiness;
        half _Metallic;
        fixed4 _Color;
		fixed4 _ColorTint;
		fixed4 _RimColor;
		float _RimPower;
		float _Steps;
		float _ToonEffect;

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

			difLight = smoothstep(0,1,difLight);
			float toon = floor(difLight * _Steps)/ _Steps;
			difLight = lerp(difLight, toon, _ToonEffect);

			fixed3 diffuse = _LightColor0 * s.Albedo * difLight;

			fixed3 halfDir = normalize(lightDir + viewDir);
			fixed3 specular = _LightColor0.rgb * _Color.rgb * pow(max(0,dot(s.Normal, halfDir)), s.Gloss );

			return half4(diffuse + specular,1);
		}

        // Add instancing support for this shader. You need to check 'Enable Instancing' on materials that use the shader.
        // See https://docs.unity3d.com/Manual/GPUInstancing.html for more information about instancing.
        // #pragma instancing_options assumeuniformscaling
        UNITY_INSTANCING_BUFFER_START(Props)
            // put more per-instance properties here
        UNITY_INSTANCING_BUFFER_END(Props)

        void surf (Input IN, inout SurfaceOutput o)
        {
            // Albedo comes from a texture tinted by color
            fixed4 c = tex2D (_MainTex, IN.uv_MainTex) * _Color;
            o.Albedo = c.rgb;
            // Metallic and smoothness come from slider variables
            o.Specular = _Metallic;
            o.Gloss = _Glossiness;
            o.Alpha = c.a;
			float3 normal = UnpackNormal(tex2D(_BumpMap, IN.uv_BumpMap));
			normal.xy *= _BunmScale;
			o.Normal = normal;
			half rim = 1.0 - saturate(dot(normalize(IN.viewDir), o.Normal));
			o.Emission = _RimColor.rgb * pow(rim, _RimPower);
        }

		void final(Input IN, SurfaceOutput o, inout fixed4 color)
		{
			color *= _ColorTint;
		}
        ENDCG
    }
    FallBack "Diffuse"
}

火焰流动:

Shader "Custom/Surface05"
{
    Properties
    {
        _Color ("Color", Color) = (1,1,1,1)
        _MainTex ("Albedo (RGB)", 2D) = "white" {}
        _Smoothness ("Smoothness", Range(0,1)) = 0.5
		_Normal("Normal", 2D) = "bump" {}
		_Mask("Mask",2D) = "white"{}
		_Specular("Specular", 2D) = "white" {}
		_Fire("Fire",2D) = "white" {}
		_FireIntensity("FireIntensity", Range(0,2)) = 1
		_FireSpeed("FireSpeed", Vector) = (0,0,0,0)
    }
    SubShader
    {
        Tags { "RenderType"="Opaque" "Queue" = "Geometry"}
        LOD 200

        CGPROGRAM
        // Physically based Standard lighting model, and enable shadows on all light types
        #pragma surface surf StandardSpecular fullforwardshadows

        // Use shader model 3.0 target, to get nicer looking lighting
        #pragma target 3.0

        sampler2D _MainTex;
		sampler2D _Normal;
		sampler2D _Mask;
		sampler2D _Specular;
		sampler2D _Fire;

        struct Input
        {
            float2 uv_MainTex;
        };

        half _Smoothness;
		half _FireIntensity;
		half2 _FireSpeed;
        fixed4 _Color;

        // Add instancing support for this shader. You need to check 'Enable Instancing' on materials that use the shader.
        // See https://docs.unity3d.com/Manual/GPUInstancing.html for more information about instancing.
        // #pragma instancing_options assumeuniformscaling
        UNITY_INSTANCING_BUFFER_START(Props)
            // put more per-instance properties here
        UNITY_INSTANCING_BUFFER_END(Props)

        void surf (Input IN, inout SurfaceOutputStandardSpecular o)
        {
            // Albedo comes from a texture tinted by color
            o.Albedo = tex2D (_MainTex, IN.uv_MainTex) * _Color;
			o.Normal = UnpackNormal(tex2D(_Normal,IN.uv_MainTex));
			float2 uv = IN.uv_MainTex + _Time.x * _FireSpeed;
			o.Emission = ((tex2D(_Mask, IN.uv_MainTex) * tex2D(_Fire, uv)) * (_FireIntensity * (_SinTime.w + 2.5))).rgb;
            // Metallic and smoothness come from slider variables
			o.Specular = tex2D(_Specular ,IN.uv_MainTex ).rgb;
            o.Smoothness = _Smoothness;
            o.Alpha = 1;
        }
        ENDCG
    }
    FallBack "Diffuse"
}

基于法线的UV扭曲:

Shader "Custom/Surface06"
{
    Properties
    {
        [HDR]_Color ("Color", Color) = (1,1,1,1)
        _MainTex ("Albedo (RGB)", 2D) = "white" {}
		_DistortTexture("Distort Texture", 2D) = "bump"{}
		_Speed ("_Speed", float) = 0
		_UVDisIntensity("UVDisIntensity", Range(0,1)) = 0
        _Glossiness ("Smoothness", Range(0,1)) = 0.5
        _Metallic ("Metallic", Range(0,1)) = 0.0
    }
    SubShader
    {
        Tags { "RenderType"="Opaque" "Queue"="Geometry"}
        LOD 200

        CGPROGRAM
        // Physically based Standard lighting model, and enable shadows on all light types
        #pragma surface surf Standard fullforwardshadows

        // Use shader model 3.0 target, to get nicer looking lighting
        #pragma target 3.0

        sampler2D _MainTex;
		sampler2D _DistortTexture;

        struct Input
        {
            float2 uv_MainTex;
        };

        half _Glossiness;
        half _Metallic;
		half _Speed;
		half _UVDisIntensity;
        fixed4 _Color;

        // Add instancing support for this shader. You need to check 'Enable Instancing' on materials that use the shader.
        // See https://docs.unity3d.com/Manual/GPUInstancing.html for more information about instancing.
        // #pragma instancing_options assumeuniformscaling
        UNITY_INSTANCING_BUFFER_START(Props)
            // put more per-instance properties here
        UNITY_INSTANCING_BUFFER_END(Props)

        void surf (Input IN, inout SurfaceOutputStandard o)
        {
			float2 uv1 = IN.uv_MainTex + _Time.y * _Speed * float2(-1,-1);
			float2 uv2 = IN.uv_MainTex + _Time.y * _Speed * float2(1,1);
			float3 Distort = UnpackScaleNormal(tex2D(_DistortTexture,IN.uv_MainTex),_UVDisIntensity);
			float4 mainTex1 = tex2D(_MainTex, (float3(uv1,0) + Distort).xy);
			float4 mainTex2 = tex2D(_MainTex, (float3(uv2,0) + Distort).xy);
			float4 color = _Color * mainTex1 * mainTex2;
            // Albedo comes from a texture tinted by color
            //fixed4 c = tex2D (_MainTex, IN.uv_MainTex) * _Color;
            o.Albedo = color;
			o.Emission = color;
            // Metallic and smoothness come from slider variables
            o.Metallic = _Metallic;
            o.Smoothness = _Glossiness;
            o.Alpha = 1;
        }
        ENDCG
    }
    FallBack "Diffuse"
}

燃烧GLow:

Shader "Custom/Surface07"
{
    Properties
    {
        _Color ("Color", Color) = (1,1,1,1)
        _MainTex ("Albedo (RGB)", 2D) = "white" {}
		_MainMix("MainMix", Range(0,1)) = 0.5
		_Nomral("Normal", 2D) = "bump"{}
		//此贴图属于正常,不是normal map, alpha通道另有它用
		_BurnNormal("BurnNormal", 2D) = "white" {}
		_NormalTill("NormalTill", Range(0,5)) = 1

		_Mask("Mask", 2D) = "white"{}
		_BurnTill("BurnTill", float) = 1
		_BurnOffset("BurnOffset", float) = 1
		_BurnRange("BurnRange",  Range(0,1)) = 0.5

		_BurnColor("BurnColor", Color) = (0,0,0,0)

		//Glow参数
		_GlowColor("GlowColor", Color) = (1,1,1,1)
		_GlowIntensity("GlowIntensity",Range(0,2)) = 0.5
		_GlowFrequency("GlowFrequency",Range(0,5)) = 0.5
		_GlowOverride("GlowOverride", Range(0,2)) = 0.5
		_GlowEmission("GlowEmission",  Range(0,2)) = 0.5

		_Glossiness ("Smoothness", Range(0,1)) = 0.5
        _Metallic ("Metallic", Range(0,1)) = 0.0
    }
    SubShader
    {
        Tags { "RenderType"="Opaque" "Queue" ="Geometry"}
        LOD 200

        CGPROGRAM
        // Physically based Standard lighting model, and enable shadows on all light types
        #pragma surface surf Standard fullforwardshadows

        // Use shader model 3.0 target, to get nicer looking lighting
        #pragma target 3.0

        sampler2D _MainTex;
		sampler2D _Nomral;
		sampler2D _BurnNormal;
		half _NormalTill;
		sampler2D _Mask;
		half _BurnTill;
		half _BurnOffset;
		half _BurnRange;
		half _MainMix;
		fixed4 _BurnColor;
		fixed4 _GlowColor;
		half _GlowIntensity;
		half _GlowFrequency;
		half _GlowOverride;
		half _GlowEmission;

        struct Input
        {
            float2 uv_MainTex;
        };

        half _Glossiness;
        half _Metallic;
        fixed4 _Color;

        // Add instancing support for this shader. You need to check 'Enable Instancing' on materials that use the shader.
        // See https://docs.unity3d.com/Manual/GPUInstancing.html for more information about instancing.
        // #pragma instancing_options assumeuniformscaling
        UNITY_INSTANCING_BUFFER_START(Props)
            // put more per-instance properties here
        UNITY_INSTANCING_BUFFER_END(Props)

        void surf (Input IN, inout SurfaceOutputStandard o)
        {
			float3 normal1 = UnpackNormal(tex2D(_Nomral, IN.uv_MainTex));
			fixed4 burnTexture = tex2D(_BurnNormal, IN.uv_MainTex * _NormalTill);
			fixed4 burnNormal = fixed4(1, burnTexture.g, 0, burnTexture.r);
			float3 normal2 = UnpackNormal(burnNormal);
			float2 maskUv = IN.uv_MainTex * _BurnTill + _BurnOffset * float2(1,1);
			fixed3 maskColor = tex2D(_Mask, maskUv);
			float maskR = _BurnRange + maskColor.r;
			o.Normal = lerp(normal1,normal2, maskR);
            // Albedo comes from a texture tinted by color

            fixed4 c = tex2D (_MainTex, IN.uv_MainTex) * _Color;
			fixed4 diffuse = lerp(c * _MainMix, _BurnColor ,maskR);
            o.Albedo = diffuse.rgb;

			float4 glow = _GlowColor * _GlowIntensity * ( 0.5f * sin(_Time.y * _GlowFrequency) + _GlowOverride * burnTexture.a);
			//maskColor.r 确定了那部分烧着 ,然后 burnTexture.a 确定了烧着部分哪些地方有火焰
			o.Emission = glow * maskColor.r * burnTexture.a  *  _GlowEmission;
            // Metallic and smoothness come from slider variables
            o.Metallic = _Metallic;
            o.Smoothness = _Glossiness;
            o.Alpha = diffuse.a;
        }
        ENDCG
    }
    FallBack "Diffuse"
}

自定义顶点处理函数+法线外扩:

Shader "Custom/Surface08"
{
    Properties
    {
        _Color ("Color", Color) = (1,1,1,1)
        _MainTex ("Albedo (RGB)", 2D) = "white" {}
		_ExtrusionFrency("Frency" , float) = 0
		_ExtrusionSwing("Swing", Range(0,50)) = 1
        _Glossiness ("Smoothness", Range(0,1)) = 0.5
        _Metallic ("Metallic", Range(0,1)) = 0.0
    }
    SubShader
    {
        Tags { "RenderType"="Opaque" "Queue" = "Geometry"}
        LOD 200

        CGPROGRAM
        // Physically based Standard lighting model, and enable shadows on all light types
        #pragma surface surf Standard fullforwardshadows vertex:vertFun

        // Use shader model 3.0 target, to get nicer looking lighting
        #pragma target 3.0

        sampler2D _MainTex;
		half _ExtrusionFrency;
		half _ExtrusionSwing;

        struct Input
        {
            float2 uv_MainTex;
        };

        half _Glossiness;
        half _Metallic;
        fixed4 _Color;

		void vertFun (inout appdata_full v, out Input o)
		{
			UNITY_INITIALIZE_OUTPUT(Input, o);
			float3 normal = v.normal.xyz;
			float3 vertexPos = v.vertex.xyz;
			v.vertex.xyz += normal * max(sin((vertexPos.y + _Time.x) * _ExtrusionFrency) / _ExtrusionSwing ,0);
		}

        // Add instancing support for this shader. You need to check 'Enable Instancing' on materials that use the shader.
        // See https://docs.unity3d.com/Manual/GPUInstancing.html for more information about instancing.
        // #pragma instancing_options assumeuniformscaling
        UNITY_INSTANCING_BUFFER_START(Props)
            // put more per-instance properties here
        UNITY_INSTANCING_BUFFER_END(Props)

        void surf (Input IN, inout SurfaceOutputStandard o)
        {
            // Albedo comes from a texture tinted by color
            fixed4 c = tex2D (_MainTex, IN.uv_MainTex) * _Color;
            o.Albedo = c.rgb;
            // Metallic and smoothness come from slider variables
            o.Metallic = _Metallic;
            o.Smoothness = _Glossiness;
            o.Alpha = c.a;
        }
        ENDCG
    }
    FallBack "Diffuse"
}

简单模糊:

Shader "Custom/Surface09"
{
    Properties
    {
        _Color ("Color", Color) = (1,1,1,1)
        _MainTex ("Albedo (RGB)", 2D) = "white" {}
        _Glossiness ("Smoothness", Range(0,1)) = 0.5
        _Metallic ("Metallic", Range(0,1)) = 0.0
		[Toggle]_ToggleBulr("ToggleBulr", Range(0,1)) = 0
		_BlurSize("Bulr Size", Range(0,0.1)) = 0
    }
    SubShader
    {
        Tags { "RenderType"="Opaque" }
        LOD 200

        CGPROGRAM
        // Physically based Standard lighting model, and enable shadows on all light types
        #pragma surface surf Standard fullforwardshadows

        // Use shader model 3.0 target, to get nicer looking lighting
        #pragma target 3.0

        sampler2D _MainTex;
		half _ToggleBulr;
		half _BlurSize;

        struct Input
        {
            float2 uv_MainTex;
        };

        half _Glossiness;
        half _Metallic;
        fixed4 _Color;

        // Add instancing support for this shader. You need to check 'Enable Instancing' on materials that use the shader.
        // See https://docs.unity3d.com/Manual/GPUInstancing.html for more information about instancing.
        // #pragma instancing_options assumeuniformscaling
        UNITY_INSTANCING_BUFFER_START(Props)
            // put more per-instance properties here
        UNITY_INSTANCING_BUFFER_END(Props)

        void surf (Input IN, inout SurfaceOutputStandard o)
        {
            // Albedo comes from a texture tinted by color
            fixed4 c = tex2D (_MainTex, IN.uv_MainTex);
			fixed4 offset1 = tex2D (_MainTex, IN.uv_MainTex + float2(0, _BlurSize));
			fixed4 offset2 = tex2D (_MainTex, IN.uv_MainTex + float2(_BlurSize, 0));
			fixed4 offset3 = tex2D (_MainTex, IN.uv_MainTex + float2(_BlurSize, _BlurSize));
			fixed4 offsetColor = c*0.4 + offset1*0.2 + offset2*0.2 + offset3*0.2;
			fixed4 color = lerp(c,offsetColor,step(0.5,_ToggleBulr));
            o.Albedo = color.rgb;
            // Metallic and smoothness come from slider variables
            o.Metallic = _Metallic;
            o.Smoothness = _Glossiness;
            o.Alpha = c.a;
        }
        ENDCG
    }
    FallBack "Diffuse"
}

消融效果:

Shader "Custom/Surface10"
{
    Properties
    {
        _Color ("Color", Color) = (1,1,1,1)
        _MainTex ("Albedo (RGB)", 2D) = "white" {}
		_Normal("Normal", 2D) = "bump" {}
		_NormalScale("NormalScale", Range(0,5)) = 1
        _Glossiness ("Smoothness", Range(0,1)) = 0.5
        _Metallic ("Metallic", Range(0,1)) = 0.0
		_DisolveTex("DisolveTex",2D) = "white"{}
		_Threshold("Threshold",Range(0,1)) = 0
		_EdgeLength("EdgeLength", Range(0,0.2)) = 0.1
		_BurnTex("BurnTex", 2D) = "white"{}
		_BurnInstensity("BurnInstensity", Range(0,5)) = 1
    }
    SubShader
    {
        Tags { "RenderType"="Opaque" }
        LOD 200

        CGPROGRAM
        // Physically based Standard lighting model, and enable shadows on all light types
        #pragma surface surf Standard fullforwardshadows

        // Use shader model 3.0 target, to get nicer looking lighting
        #pragma target 3.0

        sampler2D _MainTex;
		sampler2D _Normal;
		half _NormalScale;
		sampler2D _DisolveTex;
		half _Threshold;
		sampler2D _BurnTex;
		half _EdgeLength;
		half _BurnInstensity;

        struct Input
        {
            float2 uv_MainTex;
			float2 uv_Normal;
			float2 uv_DisolveTex;
        };

        half _Glossiness;
        half _Metallic;
        fixed4 _Color;

        // Add instancing support for this shader. You need to check 'Enable Instancing' on materials that use the shader.
        // See https://docs.unity3d.com/Manual/GPUInstancing.html for more information about instancing.
        // #pragma instancing_options assumeuniformscaling
        UNITY_INSTANCING_BUFFER_START(Props)
            // put more per-instance properties here
        UNITY_INSTANCING_BUFFER_END(Props)

        void surf (Input IN, inout SurfaceOutputStandard o)
        {
            // Albedo comes from a texture tinted by color
            fixed4 c = tex2D (_MainTex, IN.uv_MainTex) * _Color;
			o.Normal = UnpackScaleNormal(tex2D(_Normal, IN.uv_Normal),_NormalScale);
            o.Albedo = c.rgb;

			float cutout = tex2D(_DisolveTex, IN.uv_DisolveTex).r;
			clip(cutout - _Threshold);
			float temp = saturate((cutout - _Threshold) / _EdgeLength);
			fixed4 edgeColor = tex2D(_BurnTex,float2(temp,temp));
			fixed4 finalColor = _BurnInstensity * lerp(edgeColor, fixed4(0,0,0,0), temp);
			o.Emission = finalColor.rgb;
            // Metallic and smoothness come from slider variables
            o.Metallic = _Metallic;
            o.Smoothness = _Glossiness;
            o.Alpha = c.a;
        }
        ENDCG
    }
    FallBack "Diffuse"
}

区域过度:

Shader "Custom/Surface11"
{
    Properties
    {
        _Color ("Color", Color) = (1,1,1,1)
        _MainTex ("Albedo (RGB)", 2D) = "white" {}
        _Glossiness ("Smoothness", Range(0,1)) = 0.5
        _Metallic ("Metallic", Range(0,1)) = 0.0
		_Dis("Dis",Range(0.1,10)) = 1
		_StartPoint("StratPoint",Range(-10,10)) = 1
		_Tex2("Tex2",2D) = "white" {}
		_UnderInfluence("UnderInfluence",Range(0,1)) = 0
    }
    SubShader
    {
        Tags { "RenderType"="Opaque" }
        LOD 200

        CGPROGRAM
        // Physically based Standard lighting model, and enable shadows on all light types
        #pragma surface surf Standard fullforwardshadows

        // Use shader model 3.0 target, to get nicer looking lighting
        #pragma target 3.0

        sampler2D _MainTex;
		half _StartPoint;
		fixed4 _Tint;
		half _Dis;
		half _UnderInfluence;
		sampler2D _Tex2;

        struct Input
        {
            float2 uv_MainTex;
			float3 worldPos;
			float2 uv_Tex2;
        };

        half _Glossiness;
        half _Metallic;
        fixed4 _Color;

        // Add instancing support for this shader. You need to check 'Enable Instancing' on materials that use the shader.
        // See https://docs.unity3d.com/Manual/GPUInstancing.html for more information about instancing.
        // #pragma instancing_options assumeuniformscaling
        UNITY_INSTANCING_BUFFER_START(Props)
            // put more per-instance properties here
        UNITY_INSTANCING_BUFFER_END(Props)

        void surf (Input IN, inout SurfaceOutputStandard o)
        {
            // Albedo comes from a texture tinted by color
			float temp =  saturate((IN.worldPos.y + _StartPoint)/_Dis);
            fixed4 c = tex2D (_MainTex, IN.uv_MainTex) * _Color;
			float clampTemp = clamp(temp, _UnderInfluence,1);
			fixed4 color = lerp(tex2D(_Tex2,IN.uv_Tex2),c,clampTemp);
            o.Albedo = color.rgb;
            // Metallic and smoothness come from slider variables
            o.Metallic = _Metallic;
            o.Smoothness = _Glossiness;
            o.Alpha = c.a;
        }
        ENDCG
    }
    FallBack "Diffuse"
}

透明度测试:

Shader "Custom/Surface12"
{
    Properties
    {
        _Color ("Color", Color) = (1,1,1,1)
        _MainTex ("Albedo (RGB)", 2D) = "white" {}
        _Glossiness ("Smoothness", Range(0,1)) = 0.5
        _Metallic ("Metallic", Range(0,1)) = 0.0
		_Cutoff("Cutoff",Range(0,1)) = 0.5
    }
    SubShader
    {
        Tags { "RenderType"="Transparent" "Queue"="AlphaTest"}
        LOD 200
		Cull off

        CGPROGRAM
        // Physically based Standard lighting model, and enable shadows on all light types
        #pragma surface surf Standard alphatest:_Cutoff noshadow addshadow

        // Use shader model 3.0 target, to get nicer looking lighting
        #pragma target 3.0

        sampler2D _MainTex;

        struct Input
        {
            float2 uv_MainTex;
        };

        half _Glossiness;
        half _Metallic;
        fixed4 _Color;

        // Add instancing support for this shader. You need to check 'Enable Instancing' on materials that use the shader.
        // See https://docs.unity3d.com/Manual/GPUInstancing.html for more information about instancing.
        // #pragma instancing_options assumeuniformscaling
        UNITY_INSTANCING_BUFFER_START(Props)
            // put more per-instance properties here
        UNITY_INSTANCING_BUFFER_END(Props)

        void surf (Input IN, inout SurfaceOutputStandard o)
        {
            // Albedo comes from a texture tinted by color
            fixed4 c = tex2D (_MainTex, IN.uv_MainTex) * _Color;
            o.Albedo = c.rgb;
            // Metallic and smoothness come from slider variables
            o.Metallic = _Metallic;
            o.Smoothness = _Glossiness;
            o.Alpha = c.a;
        }
        ENDCG
    }
    FallBack "Diffuse"
}

透明度混合:

Shader "Custom/Surface13"
{
    Properties
    {
        _Color ("Color", Color) = (1,1,1,1)
        _MainTex ("Albedo (RGB)", 2D) = "white" {}
        _Glossiness ("Smoothness", Range(0,1)) = 0.5
        _Metallic ("Metallic", Range(0,1)) = 0.0
    }
    SubShader
    {
        Tags { "RenderType"="Transparent" "Queue"= "Transparent"}
        LOD 200
		Cull off

        CGPROGRAM
        // Physically based Standard lighting model, and enable shadows on all light types
        #pragma surface surf Standard alpha:blend noshadow

        // Use shader model 3.0 target, to get nicer looking lighting
        #pragma target 3.0

        sampler2D _MainTex;

        struct Input
        {
            float2 uv_MainTex;
        };

        half _Glossiness;
        half _Metallic;
        fixed4 _Color;

        // Add instancing support for this shader. You need to check 'Enable Instancing' on materials that use the shader.
        // See https://docs.unity3d.com/Manual/GPUInstancing.html for more information about instancing.
        // #pragma instancing_options assumeuniformscaling
        UNITY_INSTANCING_BUFFER_START(Props)
            // put more per-instance properties here
        UNITY_INSTANCING_BUFFER_END(Props)

        void surf (Input IN, inout SurfaceOutputStandard o)
        {
            // Albedo comes from a texture tinted by color
            fixed4 c = tex2D (_MainTex, IN.uv_MainTex) * _Color;
            o.Albedo = c.rgb;
            // Metallic and smoothness come from slider variables
            o.Metallic = _Metallic;
            o.Smoothness = _Glossiness;
            o.Alpha = c.a;
        }
        ENDCG
    }    
}

雪:

Shader "Custom/Surface14"
{
    Properties
    {
        _Color ("Color", Color) = (1,1,1,1)
        _MainTex ("Albedo (RGB)", 2D) = "white" {}
		_SonwTex("SnowTex",2D) = "white"{}
		_NormalTex("Noraml", 2D) = "bump"{}
		_SnowDir("SnowDir",Vector) = (0,1,0)
		_SnowAmount("_SnowAmount", Range(0,2)) = 1
    }
    SubShader
    {
        Tags { "RenderType"="Opaque" }
        LOD 200

        CGPROGRAM
        // Physically based Standard lighting model, and enable shadows on all light types
        #pragma surface surf StandardSpecular fullforwardshadows

        // Use shader model 3.0 target, to get nicer looking lighting
        #pragma target 3.0

        sampler2D _MainTex;
		sampler2D _NormalTex;
		sampler2D _SonwTex;

        struct Input
        {
            float2 uv_MainTex;
			float2 uv_NormalTex;
			float2 uv_SonwTex;
			float3 worldNormal; 
			INTERNAL_DATA
        };

        half _Glossiness;
        half _Metallic;
        fixed4 _Color;
		float4 _SnowDir;
		half _SnowAmount;

        // Add instancing support for this shader. You need to check 'Enable Instancing' on materials that use the shader.
        // See https://docs.unity3d.com/Manual/GPUInstancing.html for more information about instancing.
        // #pragma instancing_options assumeuniformscaling
        UNITY_INSTANCING_BUFFER_START(Props)
            // put more per-instance properties here
        UNITY_INSTANCING_BUFFER_END(Props)

        void surf (Input IN, inout SurfaceOutputStandardSpecular o)
        {
			float3 normalTex = UnpackNormal(tex2D(_NormalTex, IN.uv_NormalTex));
			o.Normal = normalTex;
			fixed3 wNormal = WorldNormalVector(IN, normalTex);

			float lerpVal = saturate(dot(wNormal, _SnowDir.xyz));
            // Albedo comes from a texture tinted by color
            fixed4 c = lerp( tex2D (_MainTex, IN.uv_MainTex), tex2D(_SonwTex, IN.uv_SonwTex), lerpVal * _SnowAmount) * _Color;
            o.Albedo = c.rgb;
            // Metallic and smoothness come from slider variables
            o.Alpha = c.a;
        }
        ENDCG
    }
    FallBack "Diffuse"
}

雪优化:

Shader "Custom/Surface15"
{
	Properties
	{
		_Color("Color", Color) = (1,1,1,1)
		_MainTex("Albedo (RGB)", 2D) = "white" {}
		_SonwTex("SnowTex",2D) = "white"{}
		_NormalTex("Noraml", 2D) = "bump"{}
		_SnowNormal("SnowNoraml",2D) = "bump"{}
		_SnowDir("SnowDir",Vector) = (0,1,0)
		_SnowAmount("_SnowAmount", Range(0,2)) = 1
	}

	SubShader
	{
		Tags { "RenderType" = "Opaque" }
		LOD 200

		CGPROGRAM
		// Physically based Standard lighting model, and enable shadows on all light types
		#pragma surface surf StandardSpecular fullforwardshadows

		// Use shader model 3.0 target, to get nicer looking lighting
		#pragma target 3.0

		sampler2D _MainTex;
		sampler2D _NormalTex;
		sampler2D _SonwTex;
		sampler2D _SnowNormal;

		struct Input
		{
			float2 uv_MainTex;
			float2 uv_NormalTex;
			float2 uv_SonwTex;
			float2 uv_SnowNormal;
			float3 worldNormal;
			INTERNAL_DATA
		};

		half _Glossiness;
		half _Metallic;
		fixed4 _Color;
		float4 _SnowDir;
		half _SnowAmount;

		// Add instancing support for this shader. You need to check 'Enable Instancing' on materials that use the shader.
		// See https://docs.unity3d.com/Manual/GPUInstancing.html for more information about instancing.
		// #pragma instancing_options assumeuniformscaling
		UNITY_INSTANCING_BUFFER_START(Props)
			// put more per-instance properties here
		UNITY_INSTANCING_BUFFER_END(Props)

		void surf(Input IN, inout SurfaceOutputStandardSpecular o)
		{
			float3 normalTex = UnpackNormal(tex2D(_NormalTex, IN.uv_NormalTex));
			float3 snowNorTex = UnpackNormal(tex2D(_SnowNormal, IN.uv_SnowNormal));
			fixed3 wNormal = WorldNormalVector(IN, float3(0,0,1));
			fixed3 finalNormal = lerp(normalTex, snowNorTex, saturate(dot(wNormal, _SnowDir.xyz)) * _SnowAmount);
			o.Normal = finalNormal;

			fixed3 fWNormal = WorldNormalVector(IN, finalNormal);
			float lerpVal = saturate(dot(fWNormal, _SnowDir.xyz));
			// Albedo comes from a texture tinted by color
			fixed4 c = lerp(tex2D(_MainTex, IN.uv_MainTex), tex2D(_SonwTex, IN.uv_SonwTex), lerpVal * _SnowAmount);
			o.Albedo = c.rgb;
			// Metallic and smoothness come from slider variables
			o.Alpha = c.a;
		}
		ENDCG
	}
	FallBack "Diffuse"
}
  • 0
    点赞
  • 15
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值