0

Before implementing a shader cubemap I tried to make a skybox manually with six textures around it, but I get distortion while rotating.

In GL 3.3 using cubemap uniforms, is there some added math magic behind the scenes (that counteracts distortion), versus creating six flat faces and applying a texture to each side manually ?

Example
Here is a skymap using six individual textures. You can see the distortion at the cube corner as the scene rotates frame 1 frame 2 frame 3

Thomas An
  • 503
  • 2
  • 7
  • 17

2 Answers2

0

Of course, cube maps can only be created with a 90° fov (at least if the camera is positioned in the cube's center). Otherwise, you would not get a cube. If you decrease the fov, you will get empty spaces around the edges. If you increase it, you will get overlapping areas. You could also create a cuboid from non-90° fovs, but that wouldn't be worth the effort.

The addressing mode of cube maps in OpenGL is different than the one used for ordinary 2D textures. You access 2D textures with a 2D texture coordinate. Cube maps are accessed via a 3D direction vector. OpenGL then uses this direction vector to calculate the sub texture to use and the texture coordinate for this sub texture.

A skybox can also be easily implemented with six plain textures. In fact, the advanced addressing mode may even turn out to be a disadvantage in this case. It would be different if you used a different sky carrier object (e.g. I once used a sky tetrahedron). If there were distortions, there must have been some mistakes in your code. The basic principle works.

Nico Schertler
  • 32,049
  • 4
  • 39
  • 70
0

After setting it up on a 3D modeling app and doing some experimentation, I feel I can answer my own question.

Cubemaps work ONLY with first person perspective. It is important the eye/camera sits exactly at the center of the cube and the camera target orbits around. For example: Eye at center

In the reverse scenario where the target is exactly at center and the eye orbits around it (like in a 3D modeling app) then a cubemap becomes useless by distortion. For example: target at center

So ... to answer this question. No, there is no magic behind the GLSL cubemapping that keeps distortion from happening. It is all a matter of how the application handles its camera system.

Community
  • 1
  • 1
Thomas An
  • 503
  • 2
  • 7
  • 17
  • Well, that's partly true. The key thing here is that the cube faces should conceptually lie at _infinite_ distance. Then, movement of the camera doesn't matter. With the programmable pipeline, things become much easier, though. All one needs to do nowadays is drawing a full-screen quad, and using the direction vector from the camera position to each fragment as the cube map tex coords, which exactly has the effect of sampling the cube map as if it were at infinity, as outlined [here](http://stackoverflow.com/questions/30015940/why-dont-people-use-tetrahedrons-for-skyboxes/30038392#30038392). – derhass Sep 15 '15 at 22:41