x


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.

more ▼

asked Feb 07, 2012 at 03:06 PM

michael 4 gravatar image

michael 4
357 124 102 103

(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first

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

more ▼

answered Feb 07, 2012 at 06:14 PM

michael 4 gravatar image

michael 4
357 124 102 103

Sure, if you wrap it manually it's possible ;) Haven't thought of wrapping the UVs in the fragment shader.

Feb 07, 2012 at 07:13 PM Bunny83

Would this code work on iOS? And if so, would it cause any performance hit?

Mar 09, 2012 at 11:56 PM eem

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.

Mar 10, 2012 at 01:53 AM Bunny83

What kind of variable is "offset"? A Vector?

Mar 31, 2012 at 07:46 PM Acheron

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?

Apr 16, 2012 at 04:18 PM numberkruncher
(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x3394
x22

asked: Feb 07, 2012 at 03:06 PM

Seen: 5392 times

Last Updated: Dec 27, 2013 at 04:08 AM