Handmade Network»Forums
Jack Mott
110 posts
Web Developer by day, game hobbyist by night.
Creating skybox / cubemap textures programatically
I'm looking for info on how to go about creating a skybox texture.

I'm going to be generating 3d data (star positions) at runtime. I then want to produce a cubemap that I can use for a skybox. I have no idea how to do the mapping from 3d coordinates to the six 2D cube faces. I really just need some guidance on the math, don't need source code or details on specific cube map formats (yet!) though that would work too.

511 posts
Creating skybox / cubemap textures programatically
find the component with the highest absolute value and then project the coordinate onto the plane in that direction

aka if it's the x component and it is negative then the coordinates on the -x plane is (-y/x, -z/x)

(do double check how the order of coordinates works out)
Justin Ayala
6 posts
A student at Sonoma State University.
Creating skybox / cubemap textures programatically
ratchfreak beat me to it but here is a little longer expiation of the same processes

http://imgur.com/a/wG9EA
Jack Mott
110 posts
Web Developer by day, game hobbyist by night.
Creating skybox / cubemap textures programatically
Well, that turns out to be easier than expected!

Thanks to you both.
Mārtiņš Možeiko
2559 posts / 2 projects
Creating skybox / cubemap textures programatically
For more formal description, read the OpenGL spec how it projects cubemap texture.
See "Section 3.8.10 "Texture Application" in https://www.opengl.org/registry/specs/ARB/texture_cube_map.txt
Jack Mott
110 posts
Web Developer by day, game hobbyist by night.
Creating skybox / cubemap textures programatically
ratchetfreak
find the component with the highest absolute value and then project the coordinate onto the plane in that direction

aka if it's the x component and it is negative then the coordinates on the -x plane is (-y/x, -z/x)

(do double check how the order of coordinates works out)


Summoning this thread back up, now that I am actually doing this.
I assume that when I project onto the *positive* x plane it would be (y/x,z/x)?

And the y plane would be x/y,z/y

and the z plane would be x/z,y/z ?
Jack Mott
110 posts
Web Developer by day, game hobbyist by night.
Creating skybox / cubemap textures programatically
wooo, I haven't verified if the stars are really in the right positions, but I just spewed a ton of code and sure enough a nice starfield skybox appeared!

next up - do the same for close stars, but with some sort of bitmap and not just a white pixel
add some color based on star type
and then some sort of background glow for the galaxy based on stellar density



511 posts
Creating skybox / cubemap textures programatically
you can check the textures end up in the right place/orientation using a debug texture with colored lines crossing boundaries
Jack Mott
110 posts
Web Developer by day, game hobbyist by night.
Creating skybox / cubemap textures programatically
ratchetfreak
you can check the textures end up in the right place/orientation using a debug texture with colored lines crossing boundaries


good call.
I may need to also create a test galaxy sector where it is obvious if things are right or wrong. 4 stars on the left, 3 on the right, 2 on top, 1 on bottom or something.