Author Topic: Tiling in texture atlas  (Read 4009 times)

Offline kkl

  • float
  • ****
  • Posts: 291
    • View Profile
Tiling in texture atlas
« on: October 18, 2013, 06:06:10 pm »
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.

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: Tiling in texture atlas
« Reply #1 on: October 18, 2013, 08:35:46 pm »
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?

Offline kkl

  • float
  • ****
  • Posts: 291
    • View Profile
Re: Tiling in texture atlas
« Reply #2 on: October 19, 2013, 04:44:51 am »
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]
« Last Edit: October 19, 2013, 10:48:13 am by kkl »

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: Tiling in texture atlas
« Reply #3 on: October 19, 2013, 11:23:16 am »
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.

Offline kkl

  • float
  • ****
  • Posts: 291
    • View Profile
Re: Tiling in texture atlas
« Reply #4 on: October 19, 2013, 12:57:31 pm »
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.
« Last Edit: October 19, 2013, 12:59:39 pm by kkl »

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: Tiling in texture atlas
« Reply #5 on: October 20, 2013, 07:29:18 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.

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...

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.

Offline kkl

  • float
  • ****
  • Posts: 291
    • View Profile
Re: Tiling in texture atlas
« Reply #6 on: October 21, 2013, 06:36:16 pm »
Quote
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.
I thought of that too. In fact, I am struggling in adjusting resolution in texture atlas. It has been a big headache. 

Quote
Just 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 ; )