利用Shader Forge 做出树叶摆动的效果2DSprite__Unity

基于Shader Forge的2DSprite上制作,效果图如下:

 

Shader Forge的版本为 v1.3.8.0,unity版本为2017.1.0f3.

相关的shader和Demo稍后会分享资源,喜欢的同学去下载~

Shader源码如下:

// Shader created with Shader Forge v1.38 
// Shader Forge (c) Neat Corporation / Joachim Holmer - http://www.acegikmo.com/shaderforge/
// Note: Manually altering this data may prevent you from opening it in Shader Forge
/*SF_DATA;ver:1.38;sub:START;pass:START;ps:flbk:,iptp:1,cusa:True,bamd:0,cgin:,lico:1,lgpr:1,limd:0,spmd:1,trmd:0,grmd:0,uamb:True,mssp:True,bkdf:False,hqlp:False,rprd:False,enco:False,rmgx:True,imps:True,rpth:0,vtps:0,hqsc:True,nrmq:1,nrsp:0,vomd:0,spxs:True,tesm:0,olmd:1,culm:2,bsrc:3,bdst:7,dpts:2,wrdp:False,dith:0,atcv:False,rfrpo:True,rfrpn:Refraction,coma:15,ufog:False,aust:True,igpj:True,qofs:0,qpre:3,rntp:2,fgom:False,fgoc:False,fgod:False,fgor:False,fgmd:0,fgcr:0.5,fgcg:0.5,fgcb:0.5,fgca:1,fgde:0.01,fgrn:0,fgrf:300,stcl:True,atwp:True,stva:128,stmr:255,stmw:255,stcp:6,stps:0,stfa:0,stfz:0,ofsf:0,ofsu:0,f2p0:False,fnsp:False,fnfb:False,fsmp:False;n:type:ShaderForge.SFN_Final,id:1873,x:33229,y:32719,varname:node_1873,prsc:2|emission-1749-OUT,alpha-603-OUT;n:type:ShaderForge.SFN_Tex2d,id:4805,x:32551,y:32729,ptovrint:False,ptlb:MainTex,ptin:_MainTex,varname:_MainTex_copy,prsc:2,glob:False,taghide:False,taghdr:False,tagprd:True,tagnsco:False,tagnrm:False,tex:ee719558e39385b49b91f364303fc463,ntxv:0,isnm:False|UVIN-1249-UVOUT;n:type:ShaderForge.SFN_Multiply,id:1086,x:32812,y:32818,cmnt:RGB,varname:node_1086,prsc:2|A-4805-RGB,B-5983-RGB,C-5376-RGB;n:type:ShaderForge.SFN_Color,id:5983,x:32551,y:32915,ptovrint:False,ptlb:Color,ptin:_Color,varname:_Color_copy,prsc:2,glob:False,taghide:False,taghdr:False,tagprd:False,tagnsco:False,tagnrm:False,c1:0.06660901,c2:0.8235294,c3:0.2284335,c4:1;n:type:ShaderForge.SFN_VertexColor,id:5376,x:32551,y:33079,varname:node_5376,prsc:2;n:type:ShaderForge.SFN_Multiply,id:1749,x:33025,y:32818,cmnt:Premultiply Alpha,varname:node_1749,prsc:2|A-1086-OUT,B-603-OUT;n:type:ShaderForge.SFN_Multiply,id:603,x:32812,y:32992,cmnt:A,varname:node_603,prsc:2|A-4805-A,B-5983-A,C-5376-A;n:type:ShaderForge.SFN_TexCoord,id:8999,x:31084,y:32359,varname:node_8999,prsc:2,uv:0,uaff:False;n:type:ShaderForge.SFN_Vector2,id:3705,x:31084,y:32527,varname:node_3705,prsc:2,v1:0.5,v2:0.5;n:type:ShaderForge.SFN_Distance,id:7124,x:31315,y:32426,varname:node_7124,prsc:2|A-8999-UVOUT,B-3705-OUT;n:type:ShaderForge.SFN_Multiply,id:1354,x:31546,y:32635,varname:node_1354,prsc:2|A-7124-OUT,B-7302-OUT;n:type:ShaderForge.SFN_OneMinus,id:4617,x:31726,y:32635,varname:node_4617,prsc:2|IN-1354-OUT;n:type:ShaderForge.SFN_Tau,id:7153,x:31946,y:32989,cmnt:2pi,varname:node_7153,prsc:2;n:type:ShaderForge.SFN_Multiply,id:6909,x:32131,y:32831,varname:node_6909,prsc:2|A-3830-OUT,B-694-OUT,C-7153-OUT;n:type:ShaderForge.SFN_TexCoord,id:1061,x:32131,y:32635,varname:node_1061,prsc:2,uv:0,uaff:False;n:type:ShaderForge.SFN_Rotator,id:1249,x:32335,y:32729,varname:node_1249,prsc:2|UVIN-1061-UVOUT,ANG-6909-OUT;n:type:ShaderForge.SFN_Clamp01,id:3830,x:31913,y:32635,varname:node_3830,prsc:2|IN-4617-OUT;n:type:ShaderForge.SFN_Slider,id:7302,x:31158,y:32656,ptovrint:False,ptlb:Contort range,ptin:_Contortrange,varname:node_7302,prsc:2,glob:False,taghide:False,taghdr:False,tagprd:False,tagnsco:False,tagnrm:False,min:0,cur:2,max:5;n:type:ShaderForge.SFN_Time,id:8575,x:31315,y:32765,varname:node_8575,prsc:2;n:type:ShaderForge.SFN_Sin,id:2755,x:31711,y:32785,varname:node_2755,prsc:2|IN-3595-OUT;n:type:ShaderForge.SFN_Divide,id:694,x:31913,y:32849,varname:node_694,prsc:2|A-2755-OUT,B-501-OUT;n:type:ShaderForge.SFN_Slider,id:501,x:31573,y:32956,ptovrint:False,ptlb:Contort value,ptin:_Contortvalue,varname:node_501,prsc:2,glob:False,taghide:False,taghdr:False,tagprd:False,tagnsco:False,tagnrm:False,min:10,cur:8.97382,max:1;n:type:ShaderForge.SFN_Slider,id:6694,x:31158,y:32919,ptovrint:False,ptlb:Rotate velocity ,ptin:_Rotatevelocity,varname:node_6694,prsc:2,glob:False,taghide:False,taghdr:False,tagprd:False,tagnsco:False,tagnrm:False,min:1,cur:1.830662,max:5;n:type:ShaderForge.SFN_Multiply,id:3595,x:31546,y:32785,varname:node_3595,prsc:2|A-8575-T,B-6694-OUT;proporder:4805-5983-7302-501-6694;pass:END;sub:END;*/

Shader "Shader Forge/Demo/Demo4" {
    Properties {
        [PerRendererData]_MainTex ("MainTex", 2D) = "white" {}
        _Color ("Color", Color) = (0.06660901,0.8235294,0.2284335,1)
        _Contortrange ("Contort range", Range(0, 5)) = 2
        _Contortvalue ("Contort value", Range(10, 1)) = 8.97382
        _Rotatevelocity ("Rotate velocity ", Range(1, 5)) = 1.830662
        [HideInInspector]_Cutoff ("Alpha cutoff", Range(0,1)) = 0.5
        [MaterialToggle] PixelSnap ("Pixel snap", Float) = 0
        _Stencil ("Stencil ID", Float) = 0
        _StencilReadMask ("Stencil Read Mask", Float) = 255
        _StencilWriteMask ("Stencil Write Mask", Float) = 255
        _StencilComp ("Stencil Comparison", Float) = 8
        _StencilOp ("Stencil Operation", Float) = 0
        _StencilOpFail ("Stencil Fail Operation", Float) = 0
        _StencilOpZFail ("Stencil Z-Fail Operation", Float) = 0
    }
    SubShader {
        Tags {
            "IgnoreProjector"="True"
            "Queue"="Transparent"
            "RenderType"="Transparent"
            "CanUseSpriteAtlas"="True"
            "PreviewType"="Plane"
        }
        Pass {
            Name "FORWARD"
            Tags {
                "LightMode"="ForwardBase"
            }
            Blend SrcAlpha OneMinusSrcAlpha
            Cull Off
            ZWrite Off
            
            Stencil {
                Ref [_Stencil]
                ReadMask [_StencilReadMask]
                WriteMask [_StencilWriteMask]
                Comp [_StencilComp]
                Pass [_StencilOp]
                Fail [_StencilOpFail]
                ZFail [_StencilOpZFail]
            }
            CGPROGRAM
            #pragma vertex vert
            #pragma fragment frag
            #define UNITY_PASS_FORWARDBASE
            #pragma multi_compile _ PIXELSNAP_ON
            #include "UnityCG.cginc"
            #pragma multi_compile_fwdbase
            #pragma only_renderers d3d9 d3d11 glcore gles 
            #pragma target 3.0
            uniform sampler2D _MainTex; uniform float4 _MainTex_ST;
            uniform float4 _Color;
            uniform float _Contortrange;
            uniform float _Contortvalue;
            uniform float _Rotatevelocity;
            struct VertexInput {
                float4 vertex : POSITION;
                float2 texcoord0 : TEXCOORD0;
                float4 vertexColor : COLOR;
            };
            struct VertexOutput {
                float4 pos : SV_POSITION;
                float2 uv0 : TEXCOORD0;
                float4 vertexColor : COLOR;
            };
            VertexOutput vert (VertexInput v) {
                VertexOutput o = (VertexOutput)0;
                o.uv0 = v.texcoord0;
                o.vertexColor = v.vertexColor;
                o.pos = UnityObjectToClipPos( v.vertex );
                #ifdef PIXELSNAP_ON
                    o.pos = UnityPixelSnap(o.pos);
                #endif
                return o;
            }
            float4 frag(VertexOutput i, float facing : VFACE) : COLOR {
                float isFrontFace = ( facing >= 0 ? 1 : 0 );
                float faceSign = ( facing >= 0 ? 1 : -1 );
////// Lighting:
////// Emissive:
                float4 node_8575 = _Time;
                float node_1249_ang = (saturate((1.0 - (distance(i.uv0,float2(0.5,0.5))*_Contortrange)))*(sin((node_8575.g*_Rotatevelocity))/_Contortvalue)*6.28318530718);
                float node_1249_spd = 1.0;
                float node_1249_cos = cos(node_1249_spd*node_1249_ang);
                float node_1249_sin = sin(node_1249_spd*node_1249_ang);
                float2 node_1249_piv = float2(0.5,0.5);
                float2 node_1249 = (mul(i.uv0-node_1249_piv,float2x2( node_1249_cos, -node_1249_sin, node_1249_sin, node_1249_cos))+node_1249_piv);
                float4 _MainTex_var = tex2D(_MainTex,TRANSFORM_TEX(node_1249, _MainTex));
                float node_603 = (_MainTex_var.a*_Color.a*i.vertexColor.a); // A
                float3 emissive = ((_MainTex_var.rgb*_Color.rgb*i.vertexColor.rgb)*node_603);
                float3 finalColor = emissive;
                return fixed4(finalColor,node_603);
            }
            ENDCG
        }
        Pass {
            Name "ShadowCaster"
            Tags {
                "LightMode"="ShadowCaster"
            }
            Offset 1, 1
            Cull Off
            
            CGPROGRAM
            #pragma vertex vert
            #pragma fragment frag
            #define UNITY_PASS_SHADOWCASTER
            #pragma multi_compile _ PIXELSNAP_ON
            #include "UnityCG.cginc"
            #include "Lighting.cginc"
            #pragma fragmentoption ARB_precision_hint_fastest
            #pragma multi_compile_shadowcaster
            #pragma only_renderers d3d9 d3d11 glcore gles 
            #pragma target 3.0
            struct VertexInput {
                float4 vertex : POSITION;
            };
            struct VertexOutput {
                V2F_SHADOW_CASTER;
            };
            VertexOutput vert (VertexInput v) {
                VertexOutput o = (VertexOutput)0;
                o.pos = UnityObjectToClipPos( v.vertex );
                #ifdef PIXELSNAP_ON
                    o.pos = UnityPixelSnap(o.pos);
                #endif
                TRANSFER_SHADOW_CASTER(o)
                return o;
            }
            float4 frag(VertexOutput i, float facing : VFACE) : COLOR {
                float isFrontFace = ( facing >= 0 ? 1 : 0 );
                float faceSign = ( facing >= 0 ? 1 : -1 );
                SHADOW_CASTER_FRAGMENT(i)
            }
            ENDCG
        }
    }
    FallBack "Diffuse"
    CustomEditor "ShaderForgeMaterialInspector"
}

资源链接:

ShaderForge(包含1.35~1.38版本) https://download.csdn.net/download/le_sam/10952660

Demo https://download.csdn.net/download/le_sam/10952668

你可能感兴趣的:(Unity,Shader)