Author Topic: Tile texture on a SkyBox  (Read 4325 times)

Offline zammbi

  • float
  • ****
  • Posts: 361
    • View Profile
Tile texture on a SkyBox
« on: March 04, 2012, 08:08:07 am »
I might be missing something but I can't see how to tile a texture on a SkyBox.
Is it possible?

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: Tile texture on a SkyBox
« Reply #1 on: March 04, 2012, 08:33:55 pm »
Yes, but it's a little complicated. You can get the world instance that the skybox is using. From that world, you can get the actual skybox object (simple the only object in that world). And then, you can get the PolygonManager from that object and set new texture coordinates for it. You'll find code in the forum that does the tiling calculations on an object using the PolygonManager.

The remaining question is: Why would you want to? A tiled sky isn't a real sky anymore, isn't it?

Offline zammbi

  • float
  • ****
  • Posts: 361
    • View Profile
Re: Tile texture on a SkyBox
« Reply #2 on: March 04, 2012, 09:12:37 pm »
Is this the code you talking about?

Code: [Select]
private void tileTexture(Object3D obj, float tileFactor) {
PolygonManager pm = obj.getPolygonManager();

int end = pm.getMaxPolygonID();
for (int i = 0; i < end; i++) {
SimpleVector uv0 = pm.getTextureUV(i, 0);
SimpleVector uv1 = pm.getTextureUV(i, 1);
SimpleVector uv2 = pm.getTextureUV(i, 2);

uv0.scalarMul(tileFactor);
uv1.scalarMul(tileFactor);
uv2.scalarMul(tileFactor);

int id = pm.getPolygonTexture(i);

TextureInfo ti = new TextureInfo(id, uv0.x, uv0.y, uv1.x, uv1.y,
uv2.x, uv2.y);
pm.setPolygonTexture(i, ti);
}
}


Quote
The remaining question is: Why would you want to? A tiled sky isn't a real sky anymore, isn't it?
Since some devices are very low in memory this is one way to save memory. Get a tileable texture and it will look perfect(stretching small images are ugly). For example my spaceship game, space can tile easy :)
I'm surprised no one has done it before.

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: Tile texture on a SkyBox
« Reply #3 on: March 04, 2012, 09:29:41 pm »
Yes, that's the code.

Offline zammbi

  • float
  • ****
  • Posts: 361
    • View Profile
Re: Tile texture on a SkyBox
« Reply #4 on: March 05, 2012, 12:48:00 pm »
Seems I'm doing something wrong, it doesn't want to tile.

Code: [Select]
skyBox = new SkyBox("stars", "stars", "stars", "stars","stars", "stars", 200);
Object3D skybox3DObj = skyBox.getWorld().getObjects().nextElement();
tileTexture(skybox3DObj, 2);

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: Tile texture on a SkyBox
« Reply #5 on: March 05, 2012, 01:24:11 pm »
Look fine so far. Maybe the SkyBox-class does something that prevents this from working...i'll look into it.

Offline zammbi

  • float
  • ****
  • Posts: 361
    • View Profile
Re: Tile texture on a SkyBox
« Reply #6 on: March 05, 2012, 01:31:50 pm »
Quote
Maybe the SkyBox-class does something that prevents this from working...i'll look into it.
Ok thanks.

The texture only shows once and then repeats the edge, doesn't matter what do.
Btw I'm not clamping the texture.

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: Tile texture on a SkyBox
« Reply #7 on: March 05, 2012, 02:14:12 pm »
I see...the SkyBox-class enables this. The stupid thing is, that Texture has an enableClamping()-method only but no way to disable it again. No idea what i was thinking when doing it that way. You can work around this by extending Texture, override enableClamping() with an empty implementation and create your SkyBox-textures using that class instance...

Offline zammbi

  • float
  • ****
  • Posts: 361
    • View Profile
Re: Tile texture on a SkyBox
« Reply #8 on: March 05, 2012, 09:18:01 pm »
Ah thanks I'll give it a try later.
Are you going to disable clamping from skyboxing (or give a option) into JPCT? or/and add a disableClamping method?

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: Tile texture on a SkyBox
« Reply #9 on: March 05, 2012, 09:33:41 pm »
I'll most likely deprecate it and replace it with a setClamping(<boolean>)-method.

Offline zammbi

  • float
  • ****
  • Posts: 361
    • View Profile
Re: Tile texture on a SkyBox
« Reply #10 on: March 06, 2012, 01:26:11 am »
Works great.

Code: [Select]
I'll most likely deprecate it and replace it with a setClamping(<boolean>)-method.
Awesome. Then I just can disable clamping once I setup the skybox instead of overriding?

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: Tile texture on a SkyBox
« Reply #11 on: March 06, 2012, 06:59:57 am »
Awesome. Then I just can disable clamping once I setup the skybox instead of overriding?
Yes.