着色器,因为它可以抵消纹理

时间:2014-01-01 03:43:38

标签: c# unity3d shader cg

我想创建一个平铺的着色器,它会回绕到自身,因为它会随着时间的推移偏移透明纹理。结果将使用表示单个步骤的纹理在网格上形成“移动人行道/旅行者”。

这是我到目前为止所拥有的。但它没有环绕(不使用外部依赖关系设置纹理的包装模式重复)

Shader "Custom/ScrollingTextureUnlitShader" 
{

Properties
{
    _FadeValue ("Fade Value", Range(0, 1)) = 1
    _ColorTint ("Color Tint", Color) = (1,1,1,1)
    _MainTex ("Base (RGB)", 2D) = "white" {}
    _ScrollXSpeed ("X Scroll Speed", Range(-10, 10)) = -5
    _ScrollYSpeed ("Y Scroll Speed", Range(-10, 10)) = 0
}

SubShader
{
    Tags { "RenderType"="Transparent" "Queue"="Transparent" }
    LOD 200

    CGPROGRAM
    #pragma surface surf Unlit alpha

    float _FadeValue;
    float4 _ColorTint;
    sampler2D _MainTex;
    fixed _ScrollXSpeed;
    fixed _ScrollYSpeed;

    struct Input
    {
        float2 uv_MainTex;
    };

    void surf (Input IN, inout SurfaceOutput o)
    {
        fixed2 scrolledUV = IN.uv_MainTex;

        fixed xScrollValue = _ScrollXSpeed * _Time;
        fixed yScrollValue = _ScrollYSpeed * _Time;

        scrolledUV += fixed2 (xScrollValue, yScrollValue);

        half4 c = tex2D (_MainTex, scrolledUV);
        o.Albedo = c.rgb * _ColorTint;
        o.Alpha = c.a * _FadeValue;
    }

    inline fixed4 LightingUnlit (SurfaceOutput s, fixed3 lightDir, fixed3 viewDir, fixed atten)
    {
        fixed4 c;
        c.rgb = s.Albedo;
        c.a = s.Alpha;

        return c;
    }

    ENDCG
}

FallBack "Transparent/Diffuse"
}

0 个答案:

没有答案