Tiling in texture atlas

Started by kkl, October 18, 2013, 06:06:10 PM

Previous topic - Next topic

kkl

Hi egon, does JPCT-AE support texture atlas, in API level? Im trying it in Blender, but it seems a lot harder, especially tiling in texture atlas (some suggested to edit uv map by hand till all faces are repeating accordingly, which i think it would take ages to do it). If not supported, do I do it in shader, or some uv trick in Blender? Wish to listen to your advice.

EgonOlsen

No, it doesn't. It just uses the uv-coordinates from the file. You can of course change them in code after loading the model, but i'm not sure if that helps here. Then again, i've no idea what your actually want to do. Can explain the problem in a little more detail?

kkl

#2
For example, an object uses a part of texture from texture atlas, and the object must has repeating texture (aka tile texture, eg floor). One of the ways to make repeating texture is by making the uv coordinate larger than the image and it would repeat the texture automatically, in Blender. However, it does not apply when the image is a texture atlas.

The first image is single texture. The texture is repeating by making uv coordinates bigger than image.
The second image is texture atlas, which the first part of texture cannot be repeated as there are other textures on the same image.
(Made by Blender)

[attachment deleted by admin]

EgonOlsen

Ok,

There are several solutions that come to my mind:


  • If it's causing more problems than it solves, then don't do it. What's the benefit in your case that you want to do this? Don't go mad about performance loss caused by texture changes. The engine does a pretty good job internally to optimize this anyway.
  • Model the objects in a way that it will work "out of the box", if possible.
  • Write some code that reads the uv-coordinates of a loaded model and modifies them to match your texture atlas. The PolygonManager is your friend here.
  • Do it in the shader. But i actually don't recommend this, because fiddling around with uv-mapping in the shader breaks some optimizations that the gpu can apply otherwise and it will slow things down.

kkl

#4
Hi Egon,

1. There are few reasons I need texture atlas. JPCT engine is certainly doing well in texture changes (by reusing the texture if the previous texture used is the same with the current one, i believe), but i heard alot that glBindTexture slows down the performance if app has tons of different texture. For image content privacy and management, it's easier to pack everything in one big image as well.

2. I'm not sure what "out of the box" means, but i'm guessing it has something to do with packing all uv coordinates into an image by hand to make it looks like repeating texture (my last resolve, though abit tedious).

3. Seems like a good idea. What if a polygon's uv is located between inside and outside of image?

4. Yea. I totally agree with you. I tried messing around with shader and it costs performance ALOT.

EgonOlsen

Quote from: kkl on October 19, 2013, 12:57:31 PM
1. There are few reasons I need texture atlas. JPCT engine is certainly doing well in texture changes (by reusing the texture if the previous texture used is the same with the current one, i believe), but i heard alot that glBindTexture slows down the performance if app has tons of different texture. For image content privacy and management, it's easier to pack everything in one big image as well.
As said, i wouldn't go crazy about the perfomance. Whatever you do, consider that you'll lose flexibility with a texture atlas. Changing a texture is possible, but more hassle than it would be with distinct textures and increasing or decreasing a texture's resolution just isn't possible without affecting all textures or reworking the complete atlas.

Quote from: kkl on October 19, 2013, 12:57:31 PM
2. I'm not sure what "out of the box" means, but i'm guessing it has something to do with packing all uv coordinates into an image by hand to make it looks like repeating texture (my last resolve, though abit tedious).
What i meant with that was to apply the proper u/v-coordinates in the modeller. Don't ask me how, i've no clue about this...

Quote from: kkl on October 19, 2013, 12:57:31 PM
3. Seems like a good idea. What if a polygon's uv is located between inside and outside of image?
Just transform it back into the range that you have for that particular texture. This won't work well for none rectangular tiles though.

kkl

QuoteAs said, i wouldn't go crazy about the perfomance. Whatever you do, consider that you'll lose flexibility with a texture atlas. Changing a texture is possible, but more hassle than it would be with distinct textures and increasing or decreasing a texture's resolution just isn't possible without affecting all textures or reworking the complete atlas.
I thought of that too. In fact, I am struggling in adjusting resolution in texture atlas. It has been a big headache. 

QuoteJust transform it back into the range that you have for that particular texture. This won't work well for none rectangular tiles though.
Ahh.. The uv coordinates are non-rectangular. Guess this method doesn't work.

BTW, thanks for the advice. Really appreciate it ; )