1
$\begingroup$

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

$\endgroup$
1
$\begingroup$

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.

$\endgroup$
  • $\begingroup$ 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! $\endgroup$ – scx Sep 6 '17 at 1:33

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.