Advertisement

Zooming in on texture atlas.

Started by January 23, 2019 05:44 PM
3 comments, last by Irusan, son of Arusan 6 years ago

I have a texture atlas with two blocks:
attachment.png
And I want to use this texture for my blocks. I don't want each block to use the entire texture, just a part of it, to make the world look bigger, which is why I would've used something like this for the vertex shader:


v_uv = a_position;

Unfortunately since this isn't a single texture, but an atlas, I had to improvise:


v_uv = vec2(0.5 * a_blocktype + mod(a_position.x, 0.5), -a_position.y * 0.5);

And this kinda works, except that it causes this bleeding:
BUtwtOC.png
(notice how there's these spots next to each A. The same problem exists for the other block type).

I then tried adding space between the tiles in the atlas, except now there are just black lines.
terrain.png

Why are the A's in your atlas sharply angled, and those in your scene, curvy? Something odd is happening here.

I would simplify your scene to two rectangles, one with each texture repeated 2.3 times in each direction and look at what it creates. This would give you a better starting point for debugging.

Apart from being unclear why you are multiplying a_position.y by 0.5, I don't see anything obviously wrong. What actually is a_position? Perhaps you could show us some more code?

Advertisement

Because the screenshot actually uses an atlas that is almost identical to the one I'm showing in the above post. The only difference is the A, but both had the same issue.

Also, can you elaborate on your suggestion? I'm not getting it.

Then it would be useful to see the exact texture atlas you used on the screenshot you showed :)

What I'm suggesting is that, just in order to debug, you create a simple scene with just 2 rectangles (four triangles) which show your textures being looped a small number of times, I picked 2.3 as an arbitrary non-integer amount that would allow the tiling to be seen. Generally it's easier to see what is going on when you simplify things.

This topic is closed to new replies.

Advertisement