<p>One solution would be to use repeating texture wrapping, and then use a texture transformation matrix. So let's say you normally set the texture coordinates of your <code>GL_TEXTURE_2D</code> to be 0-1 in <code>u</code> and <code>v</code>. Instead, ensure that your <code>GL_TEXTURE_WRAP_S</code> and <code>GL_TEXTURE_WRAP_T</code> are set to <code>GL_REPEAT</code> or <code>GL_MIRRORED_REPEAT</code> and set the texture coordinates to be the tile number to tile number + 1. So the first one would still be 0 to 1. The second one would be 1 to 2, the third would be 2 to 3, etc.</p>

<p>Next, your vertex shader would have a <code>mat4</code> uniform called <code>textureMatrix</code> or something like that. The texture matrix you pass in could have scaling in it (and probably other transformations, too). You just multiply the texture coordinates for the polygons by the texture matrix in the vertex shader, and it should apply appropriately.</p>

CC BY-SA 3.0
2017-09-06T01:33:06.573Z
Using a transform matrix for UVs is super clever! I'll have to refactor my system a little, since I was (happily) using only 1 uv, but your answer seems like a good solution. Thank you!
scx
CC BY-SA 3.0
2017-09-05T02:31:28.663Z
2017-09-05T02:31:28.663Z
user1118321
<p>Scaling up or down a texture is quite simple, modify the UVs.</p>

<p>In my particular scenario though, I have multiple "quads" (it is a patch tessellation shader) each with a tiling texture. Does anyone know of a way to change the texture scale, while retaining the tiling in the shader?</p>

<p>Is precomputing/scaling the uvs on the CPU the only option?</p>

<p>Example of (traditional) tiling problem:</p>

<p><a href="https://i.sstatic.net/zHYzP.jpg" rel="nofollow noreferrer"><img src="https://i.sstatic.net/zHYzP.jpg" alt="tiling issue"></a></p>

<opengl><texture><glsl><uv-mapping>
How do you scale an image across planes while retaining perfect tiling?
scx
# How do you scale an image across planes while retaining perfect tiling?

(Asked by: username_0 on 2017-09-04)

Scaling up or down a texture is quite simple, modify the UVs.

In my particular scenario though, I have multiple "quads" (it is a patch tessellation shader) each with a tiling texture. Does anyone know of a way to change the texture scale, while retaining the tiling in the shader?

Is precomputing/scaling the uvs on the CPU the only option?

Example of (traditional) tiling problem:

[![tiling issue](https://i.sstatic.net/zHYzP.jpg)](https://i.sstatic.net/zHYzP.jpg)

**Tags:** opengl, texture, glsl, uv-mapping


---

## 1 answers

### Answer by username_1 on 2017-09-05. Score: 1 | Accepted answer

One solution would be to use repeating texture wrapping, and then use a texture transformation matrix. So let's say you normally set the texture coordinates of your `GL_TEXTURE_2D` to be 0-1 in `u` and `v`. Instead, ensure that your `GL_TEXTURE_WRAP_S` and `GL_TEXTURE_WRAP_T` are set to `GL_REPEAT` or `GL_MIRRORED_REPEAT` and set the texture coordinates to be the tile number to tile number + 1. So the first one would still be 0 to 1. The second one would be 1 to 2, the third would be 2 to 3, etc.

Next, your vertex shader would have a `mat4` uniform called `textureMatrix` or something like that. The texture matrix you pass in could have scaling in it (and probably other transformations, too). You just multiply the texture coordinates for the polygons by the texture matrix in the vertex shader, and it should apply appropriately.

> **Comments:**
> **username_0**: Using a transform matrix for UVs is super clever! I'll have to refactor my system a little, since I was (happily) using only 1 uv, but your answer seems like a good solution. Thank you!  

---

