Hi there, I have created a simple shader to shift the texture on a sprite. Code (CSharp): float4 frag(Fragment IN) : COLOR { IN.uv_MainTex.x += _ScrollX; IN.uv_MainTex.y += _ScrollY; half4 c = tex2D (_MainTex, IN.uv_MainTex); return c; } The result can be seen below. The texture is shifted allright, but at the borders no wrap around occurs. Instead the pixels seem to be duplicated. Is there a way to fix this (i.e. make the texture repeat)?
The sprite textures do not have this setting :-( I almost solved the problem by using the following shader code: Code (CSharp): float4 frag(Fragment IN) : COLOR { IN.texcoord.x += _ScrollX; IN.texcoord.y += _ScrollY; if(IN.texcoord.x >= 1.0f) IN.texcoord.x -= 1.0f; if(IN.texcoord.x < 0.0f) IN.texcoord.x += 1.0f; if(IN.texcoord.y >= 1.0f) IN.texcoord.y -= 1.0f; if(IN.texcoord.y < 0.0f) IN.texcoord.y += 1.0f; half4 c = tex2D (_MainTex, IN.texcoord); return c; } Only one problem remains: There is a small but ugly seam where the wrap-around occurs (see screenshot). I would be very thankful for any advice on how to get rid of this...
try this instead: Code (CSharp): float mod (float x, float y){ return x - y * floor(x/y); } float4 frag(Fragment IN) : COLOR { IN.texcoord.x = mod(IN.texcoord.x + _ScrollX, 1.0); IN.texcoord.y = mod(IN.texcoord.y + _ScrollY, 1.0); half4 c = tex2D (_MainTex, IN.texcoord); return c; }