- Home /
Moving UV's with a shader (tiling error)
With the following code I tried to animate a texture on a surface by moving its uvs. However it moves, but it doesn't tile correct as the net tile is just grey (stretched from texture's border). Now how do I say that it should display the same texture over nd over again? I also tried TRANSFORM_TEX in the vertex function (same behaviour). Thanks.
Shader "Custom/test" {
Properties {
_Color ("Color", Color) = (1,1,1,1)
_MainTex ("Albedo (RGB)", 2D) = "white" {}
_Offset ("Offset", Range(-2.0, 2.0)) = 0.0
}
SubShader {
Tags { "RenderType"="Opaque" }
LOD 200
CGPROGRAM
#pragma surface surf Lambert alpha:blend vertex:vert
#pragma target 3.0
sampler2D _MainTex;
float _Offset;
struct Input {
float2 uv_MainTex;
};
void vert (inout appdata_full v) {
v.texcoord.xy += _Offset;
}
fixed4 _Color;
void surf (Input IN, inout SurfaceOutput o) {
fixed4 c = tex2D (_MainTex, IN.uv_MainTex) * _Color;
o.Albedo = c.rgb;
o.Alpha = c.a;
}
ENDCG
}
FallBack "Diffuse"
}
Answer by tanoshimi · May 29, 2016 at 07:04 AM
Set the texture wrap mode to Repeat, not Clamp. http://docs.unity3d.com/Manual/class-TextureImporter.html
Thank you so much, I was focused to find an answer in the shader code so i didn't expect this.
Your answer
Follow this Question
Related Questions
Simple Shader Syntax ... or so I thought 0 Answers
Unwrap a mesh with a vertex shader 0 Answers
Fog shader 2 Answers
Using second UV as Lightmap. Slow? 0 Answers
converting HLSL to GLSL. 0 Answers