l

成都手游码农一枚
随笔 - 32, 文章 - 0, 评论 - 117, 引用 - 0
数据加载中……

[Unity]UGUI流光材质shader

关键部分的UV偏移算法:参数自己调吧
OUT.texcoord1 = half2(IN.texcoord.x - fmod(_Time.x * 5, 1) + 0.5, IN.texcoord.y);
Shader "Effect/SimpleImageRGBWithAlpha2"
{
    Properties
    
{
        [PerRendererData] _MainTex (
"Sprite Texture", 2D) = "white" {}
        _Color (
"Tint", Color) = (1,1,1,1)
        
        _StencilComp (
"Stencil Comparison", Float) = 8
        _Stencil (
"Stencil ID", Float) = 0
        _StencilOp (
"Stencil Operation", Float) = 0
        _StencilWriteMask (
"Stencil Write Mask", Float) = 255
        _StencilReadMask (
"Stencil Read Mask", Float) = 255

        _ColorMask (
"Color Mask", Float) = 15
        _AlphaTex (
"Alpha Texture", 2D) = "white" {}
        _LightTex (
"Light Texture", 2D) = "white" {}

        _Scale (
"Scale", Float) = 256
    }


    SubShader
    
{
        Tags
        

            
"Queue"="Transparent" 
            
"IgnoreProjector"="True" 
            
"RenderType"="Transparent" 
            
"PreviewType"="Plane"
            
"CanUseSpriteAtlas"="True"
        }

        
        Stencil
        
{
            Ref [_Stencil]
            Comp [_StencilComp]
            Pass [_StencilOp] 
            ReadMask [_StencilReadMask]
            WriteMask [_StencilWriteMask]
        }


        Cull Off
        Lighting Off
        ZWrite Off
        ZTest [unity_GUIZTestMode]
        Blend SrcAlpha OneMinusSrcAlpha
        ColorMask [_ColorMask]

        Pass
        
{
        CGPROGRAM
            #pragma vertex vert
            #pragma fragment frag
            #include 
"UnityCG.cginc"

            
struct appdata_t
            
{
                float4 vertex   : POSITION;
                float4 color    : COLOR;
                float2 texcoord : TEXCOORD0;
            }
;

            
struct v2f
            
{
                float4 vertex   : SV_POSITION;
                fixed4 color    : COLOR;
                half2 texcoord0  : TEXCOORD0;
                half2 texcoord1  : TEXCOORD1;
            }
;
            
            fixed4 _Color;

            v2f vert(appdata_t IN)
            
{
                v2f OUT;
                OUT.vertex 
= mul(UNITY_MATRIX_MVP, IN.vertex);
                OUT.texcoord0 
= IN.texcoord;
                OUT.texcoord1 
= half2(IN.texcoord.x - fmod(_Time.x * 51+ 0.5, IN.texcoord.y);
#ifdef UNITY_HALF_TEXEL_OFFSET
                OUT.vertex.xy 
+= (_ScreenParams.zw-1.0)*float2(-1,1);
#endif
                OUT.color 
= IN.color * _Color;
                
return OUT;
            }


            sampler2D _MainTex;
            sampler2D _AlphaTex;
            sampler2D _LightTex;

            fixed4 frag(v2f IN) : SV_Target
            
{
                half4 color 
= half4(tex2D(_MainTex, IN.texcoord0).rgb, tex2D(_AlphaTex, IN.texcoord0).r) * IN.color;
                color.rgb 
*= tex2D(_LightTex, IN.texcoord1).r + 1;

                
// TODO why ?
                
//clip (color.a - 0.01);

                
return color;
            }

        ENDCG
        }

    }

}





posted on 2016-01-22 14:13 l1989 阅读(3099) 评论(0)  编辑 收藏 引用 所属分类: 游戏


只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理