Tile texture on a SkyBox

Started by zammbi, March 04, 2012, 08:08:07 AM

Previous topic - Next topic

zammbi

I might be missing something but I can't see how to tile a texture on a SkyBox.
Is it possible?

EgonOlsen

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?

zammbi

Is this the code you talking about?

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);
}
}



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

EgonOlsen


zammbi

Seems I'm doing something wrong, it doesn't want to tile.

skyBox = new SkyBox("stars", "stars", "stars", "stars","stars", "stars", 200);
Object3D skybox3DObj = skyBox.getWorld().getObjects().nextElement();
tileTexture(skybox3DObj, 2);

EgonOlsen

Look fine so far. Maybe the SkyBox-class does something that prevents this from working...i'll look into it.

zammbi

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

EgonOlsen

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

zammbi

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?

EgonOlsen

I'll most likely deprecate it and replace it with a setClamping(<boolean>)-method.

zammbi

Works great.

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?

EgonOlsen

Quote from: zammbi on March 06, 2012, 01:26:11 AM
Awesome. Then I just can disable clamping once I setup the skybox instead of overriding?
Yes.