- Home /
Repeat texture in mirror mode
Is it possible to set your uv tiling on mirror repeat? I do know that OpenGL supports it and DirectX does so too.
So, instead of just repeating the texture, the texture needs to be flipped instead of just repeated.
http://www.opengl.org/registry/specs/ARB/texture\_mirrored\_repeat.txt
Answer by Mortennobel · Sep 17, 2011 at 02:19 PM
No it is not possible to change the UV to mirror mode. However if your UVs is set to repeat, you can easily achieve the same effect by writing a custom shader.
I have implemented a simple diffuse shader that does the trick:
Shader "Custom/DiffuseUVMirrowShader" {
Properties {
_Color ("Main Color", Color) = (1,1,1,1)
_MainTex ("Base (RGB)", 2D) = "white" {}
}
SubShader {
Tags { "RenderType"="Opaque" }
LOD 200
CGPROGRAM
#pragma surface surf Lambert
sampler2D _MainTex;
float4 _Color;
struct Input {
float2 uv_MainTex;
};
void surf (Input IN, inout SurfaceOutput o) {
float2 t = frac(IN.uv_MainTex*0.5)*2.0;
float2 length = {1.0,1.0};
float2 mirrorTexCoords = length-abs(t-length);
half4 c = tex2D(_MainTex, mirrorTexCoords) * _Color;
o.Albedo = c.rgb;
o.Alpha = c.a;
}
ENDCG
}
Fallback "VertexLit"
}
Ok thanks for the confirmation and the shader example. That was my second option, but I don't like writing shaders for every different kind of change I want to make. Because I would need to write shaders for every kind of lighting that needs this functionality. So: Diffuse, Specular, Transparent of all... It wouldn't make it better. I think I can better change my texture to make it seamless. That will be an easier solution.
I you change your $$anonymous$$d and want to play with shaders: I have written a blog post about how I changed the diffuse shader to use UV mirroring: http://blog.nobel-joergensen.com/2011/09/17/mirror-texture-coordinates-in-unity/
Thanks so much for this shader code! I can now halve my texture size for symmetrical objects in my mobile game - every bit of optimization counts ;)
Your answer
Follow this Question
Related Questions
Texture Tiling Stopped Working in Unity 4? 2 Answers
Repeating a texture over an object 2 Answers
How to properly apply texture to sphere in Unity 1 Answer
Having Trouble with Texture Tiling and offset values. Very specific case. 2 Answers
How to match texture Scaling/offset to UV coordinates 1 Answer