Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Scrolling Sprite

Discussion in 'Shaders' started by Daybreaker32, Jan 22, 2016.

  1. Daybreaker32

    Daybreaker32

    Joined:
    Jun 11, 2014
    Posts:
    73
    Hello,

    I have created a simple uv scroller shader and it works perfectly on planes or other 3D meshes but not on 2D sprites.


    Left: sprite. Right: 3D plane

    Is there any way to make it works on sprite shader?
    I've attached the project and here is the shader:
    Code (CSharp):
    1. Shader "Custom/ScrollingTexture" {
    2.     Properties {
    3.         _MainTex ("Base (RGB)", 2D) = "white" {}
    4.         _TextureScroll ("Texture X Scroll", Range(0, 10)) = 5
    5.     }
    6.     SubShader {
    7.         Tags { "RenderType"="Opaque" }
    8.         LOD 200
    9.        
    10.         CGPROGRAM
    11.         #pragma surface surf Lambert
    12.  
    13.         sampler2D _MainTex;
    14.         float _TextureScroll;
    15.  
    16.         struct Input {
    17.             float2 uv_MainTex;
    18.             float3 uv_NormalTex;
    19.             float3 vertColor;
    20.         };
    21.  
    22.         void surf (Input IN, inout SurfaceOutput o) {
    23.             float2 scrolledUV = IN.uv_MainTex;
    24.             float scrollSpeed = _TextureScroll * _Time;
    25.             scrolledUV += float2(scrollSpeed, scrollSpeed);
    26.        
    27.             half4 c = tex2D (_MainTex, scrolledUV);
    28.             o.Albedo = c.rgb;
    29.             o.Alpha = c.a;
    30.         }
    31.         ENDCG
    32.     }
    33.     FallBack "Diffuse"
    34. }
    35.  
    Thanks.
     

    Attached Files:

  2. brownboot67

    brownboot67

    Joined:
    Jan 5, 2013
    Posts:
    375
    Your sprite is set to clamp not repeat mode.
     
  3. Daybreaker32

    Daybreaker32

    Joined:
    Jun 11, 2014
    Posts:
    73
    Hmm,

    Is it possible to set the wrap mode for sprite on Unity5?
     
  4. Daybreaker32

    Daybreaker32

    Joined:
    Jun 11, 2014
    Posts:
    73
    Or should I post this on 2D sub forum instead?
     
  5. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,400
    Not out of the box, no.

    --Eric
     
  6. brownboot67

    brownboot67

    Joined:
    Jan 5, 2013
    Posts:
    375
    Oh that's true, sorry. 1. that's underwhelming... 2. you might be able to use an Image set to to Tiled type instead of a Sprite for your use case... 3. metas have a wrapmode setting for any texture but I haven't messed with this to see what happens if you change it on a sprite and do something Unity hides (might be fine? lot of dumb black boxing in other systems).

    EDIT: You can set repeat mode on a sprite... Set texture import to advanced. Then sprite mode to whatever. Then you can set repeat mode.
     
    Last edited: Jan 28, 2016
    Daybreaker32 likes this.
  7. Daybreaker32

    Daybreaker32

    Joined:
    Jun 11, 2014
    Posts:
    73
    Oh my, it works!
    Thanks.