shader scroll UVs

This nice short & sweet shader scrolls the texture using time & some float values, in the x/y or u/v directions. All we're doing is manipulating the u and v values.

Unity provides us with the time variable "_Time". According to the docs, the time is in Seconds & is scaled by the game's time multiplier. Beneath the shader are some docs time variables and info.

 

 Shader "Dave/Unlit/UVSCROLL"{
    Properties{
        _MainTex("Texture",2D) = "white"{}
        _ScrollX("Scroll X",Range(-5,5))=1
        _ScrollY("Scroll Y",Range(-5,5))=1
        
    }
        SubShader{
        CGPROGRAM
        #pragma surface surf Lambert
        sampler2D _MainTex;
        float _ScrollX;
        float _ScrollY;

        struct Input {
        float2 uv_MainTex;
        };
        
    

    void surf(Input IN, inout SurfaceOutput o) {
        _ScrollX *= _Time;
        _ScrollY *= _Time;
        float2 newuv = IN.uv_MainTex + float2(_ScrollX, _ScrollY);
        o.Albedo=tex2D(_MainTex, newuv).rgb;

        }


        ENDCG
    }
             
    Fallback "Diffuse"
}

 


NameType Value
_Time float4 Time since level load (t/20, t, t*2, t*3), use to animate things inside the shaders.
_SinTime float4 Sine of time: (t/8, t/4, t/2, t).
_CosTime float4 Cosine of time: (t/8, t/4, t/2, t).
unity_DeltaTime float4 Delta time: (dt, 1/dt, smoothDt, 1/smoothDt).

 

Comments

Popular posts from this blog

setting VFX graph properties using C#

scripting custom render texture creation, assignment, shaders