0

As u can see in the image, on larger tiles (n > 1) the texture should be repeated as long as the current rect size.. i don't know how i can achieve this!

FYI, im getting the tile texture id with the alpha value of the vertex color.

enter image description here

Here the shader im using..

enter image description here

[UPDATE]

Thanks for clarifying the uv coordinates, unfortunately that doesn't answer my question. Take a look at the following pixture...

enter image description here

Michael
  • 177
  • 2
  • 15
  • What are the UVs like on those larger tris? If the UV range goes past `[0,1]` you might see an effect like this (it would potentially grab pixels from the atlas that aren't part of the requested tile). – rutter Mar 01 '17 at 18:59
  • So for all rectangles the uv coordinates are as following [0, 0] / [0, rect.height] / [rect.width, 0] / [rect.width, rect.height]. So the uvs are going beyond 1 – Michael Mar 01 '17 at 19:09

2 Answers2

1

Your shader is fine; it's actually the vertex UVs that are the problem:

So for all rectangles the uv coordinates are as following [0, 0] / [0, rect.height] / [rect.width, 0] / [rect.width, rect.height]. So the uvs are going beyond 1

Your shader is designed to support the standard UV space, in which case you should replace rect.width and rect.height with 1.

By using UV coords greater than one, you're effectively asking for texels outside of the specified texture. When used with a texture atlas, that means you're asking for texels outside of the specified tile -- in this case, those happen to be white, and that's what you're seeing in the rendered output.


Tiling with an atlas texture

Updating because I missed an important detail: you want a tiling material.

Usually, UVs interpolate linearly:

linear UV plot

For tiling, you essentially want more of a "sawtooth" output:

sawtooth UV plot

For a non-atlas texture, you can adjust material scale/wrap settings and call it done. For an atlas texture, it's possible but you'll end up with a shader and/or geometry that aren't quite standard.

The "most standard" solution would be if your larger quads are on a separate mesh from the smaller ones:

  • Add a float material param named uv_scale or some such
  • Add a Multiply node that scales incoming UVs by uv_scale
  • Pass output from that into a Frac node
  • Pass output from that into the UV Tile node

Pseudocode is roughly: uv = frac(uv * uv_scale)

If you need all of your quads to be in the same mesh, you end up needing non-standard geometry:

  • Change your UVs again (going back to rect.width and rect.height)
  • Add a Frac node before the UV Tile node

This is a simpler shader change, but has the downside that your geometry will no longer be cleanly supported in other shaders.

rutter
  • 11,242
  • 1
  • 30
  • 46
  • I have updated the uv coordinates between 0 and 1 but for the larger rectangles i need to repeate the texture over and over till the rect size is reached. – Michael Mar 02 '17 at 07:26
  • @Michael Apologies, I missed that detail. Answer is updated with more info. – rutter Mar 02 '17 at 14:21
0

Thanks rutter!

i've implemented your solution into my shader and now it works perfectly! so for everyone looking for this here is the shader im using now

Cheers, M

enter image description here

Michael
  • 177
  • 2
  • 15