PDA

View Full Version : Question on Cube Map

Lee_Jennifer_82
01-31-2016, 12:47 PM
I've a very simple question on Cube Mapping. In cube map, I found six images corresponding to the six sides of a cube. Why the images are set together? What is the difference if six different images are uploaded for six sides? And how to manually generate six images in one image? Do I need some special skills in Photoshop for that? Also when six images corresponding to six different sides are placed in one image, the convention followed by OpenGL to map the images corresponding to different sides of the cube I also don 't understand.

Any clarification will be appreciated.
Thank you!

Agent D
02-05-2016, 02:37 AM
I've a very simple question on Cube Mapping. In cube map, I found six images corresponding to the six sides of a cube. Why the images are set together? What is the difference if six different images are uploaded for six sides?
As you already mentioned, the images corespond to six different spacial direction. Cube maps are typically used for reflections of the sourounding environment, or shadow maps
of point lights.

For reflections, for each fragment of a rendered model, the vector pointing from the surface of the object to the camera is computed, the reflected vector specific to the surface normal
is computed and from that vector, the hardware determines what side of the cubemap to sample from and what specific location on that side.

And how to manually generate six images in one image? Do I need some special skills in Photoshop for that? Also when six images corresponding to six different sides are placed in one image, the convention followed by OpenGL to map the images corresponding to different sides of the cube I also don 't understand.

A cubemap texture is a special kind of texture object that has six targets (GL_TEXTURE_CUBE_MAP_{POSITIVE|NEGATIVE}_{X|Y|Z}) that you can upload images to with glTextureImage2D.

You can bind it like any other texture.

For the fixed function pipeline, there used to be a special texturing feature where you tell the GL to compute cubemap based reflections. For a shader based rendering pipeline, you can
compute the reflection vector in the shader and directly use this vector that points into a direction in 3D to sample a color value from the cubemap sampler.

You can generate the images for a cubemap texture either programmatically, or you can go outside and phtograph some place. AFAIK this is done by taking multiple photographs of
a metal sphere on a tripod and stitching them together.

here are some examples for Creative Commons licensed cubemaps of various places with a WebGL preview (http://humus.name/index.php?page=Textures)