- Home /
is possible to tile within a texture atlas?
is possible to tile within a texture atlas?
In other words If I have a small brick texture inside a larger texture atlas. Is there a way to only tile the brick part across the mesh.
Good to know because I got really dissapointed when I saw it working on 3Dmax and destroyed once imported into unity.
Answer by michael 4 · Feb 07, 2012 at 06:14 PM
I have found that it is indeed possible to tile textures in a texture atlas by modifying the shader.
In your pixel output function where the text2D() sampler function is called change your IN.uv_MainTex (or what ever your main texture uv variable is called) to:
(frac(IN.uv_MainTex) * 0.25f + offset) //this assumes a 4 x 4 texture atlas
so the entire line will look like this
fixed4 tex = tex2D(_MainTex, (frac(IN.uv_MainTex) * 0.25f) + offset);
instead of
fixed4 tex = tex2D(_MainTex, IN.uv_MainTex);
you will have to set offset as a variable that is present in the editor by declaring it in the properties section of your HLSL code
Sure, if you wrap it manually it's possible ;) Haven't thought of wrapping the UVs in the fragment shader.
Would this code work on iOS? And if so, would it cause any performance hit?
I guess it should work. The overhead is marginal. Well like every fragment-shader the load depends on how much of this object is visible on the screen, but the operations aren't really heavy.
Would this approach mean that there would need to be one material for each part of the texture? If so then surely there is no benefit to even using atlases right because each material is batched separately... Where else does the offset
get defined?
Your answer
Follow this Question
Related Questions
How To Apply A Texture Atlas For UI Image Objects? 0 Answers
Best way to implement texture atlas for objects sharing the same mesh? 0 Answers
how do you assign a texture atlas pict to a texture 2 Answers
Sprite Atlas not working 0 Answers
Questions about texturing models, draw calls, and unity. 0 Answers