Why don't people use tetrahedra for skyscrapers?

When rendering a fixed-texture sky in 3D games, people often create 6 textures in a cube map and then render the cube around the camera. In GLSL, you can access pixels in textures with a normal rather than a texture coordinate, and you can easily get it normal by normalizing the position of the fragment relative to the camera. However, this process can be performed with any shape that surrounds the camera, because when you normalize each position, it will always have a sphere. Now I wonder: why is it always a cube and not a tetrahedron? Rendering a cube occupies 12 triangles, just four tetrahedra 4. And, as I said, any shape surrounding the camera works. So tetrahedrons take up less VRAM and process faster without any flaws? Why not use them?

+6
source share
2 answers

You do not need environment geometry at all. All you have to do is draw a full-screen square and just calculate the correct texture coordinates for it. Now with modern GL, we don’t even need to provide vertex data for this, we can use attribute rendering:

Vertex Shader:

#version 330 core out vec3 dir; uniform mat4 invPV; void main() { vec2 pos = vec2( (gl_VertexID & 2)>>1, 1 - (gl_VertexID & 1)) * 2.0 - 1.0; vec4 front= invPV * vec4(pos, -1.0, 1.0); vec4 back = invPV * vec4(pos, 1.0, 1.0); dir=back.xyz / back.w - front.xyz / front.w; gl_Position = vec4(pos,1.0,1.0); } 

where invPV is inverse(Projection*View) , so it takes into account the orientation of your camera as well as the projection. This, in principle, can be further simplified, depending on how many restrictions you can impose on the projection matrix.

Fragment Shader:

 #version 330 core in vec3 dir; out color; uniform samplerCube uTexEnv; void main() { color=texture(uTexEnv, dir); } 

To use this, you just need to bind the empty VAO and your texture, load your invPV matrix and call glDrawArrays(GL_TRIANGLE_STRIP, 0, 4) .

This approach, of course, could be used for spherical display of textures instead of cubic maps

+5
source
  • it is about the depth and form of presentation

    the best shape of a skybox is (half) a sphere, because its visualized surface is projected onto the camera space with almost no distortion. If you use any other shape, then projection artifacts will occur, especially in the corners, for example, most applications / games use the skybox cube. Look at the sun with a finite radius (and not just one point) and rotate the view so that the sun falls from the middle towards the view. Then usually the sun is distorted from a circular / disk shape to an elliptical / oval shape:

    cube distortion exampleenter image description here

    this is due to a change in the distance between the skybox and the camera . If you compare it to the direct star displayed:

    rendered sky (no skybox)

    then you can see the difference. The first image is the first corresponding image found by google (from some game), the second is a screenshot created by cosmonauts, who, it seems to me, the latter are displayed by my astrological application, see

    So, the larger the form is far from the sphere, the more distortion you get.

    using a 4-sided pyramid is even worse than a cube because the angles between the sides deteriorate, creating even larger artifacts. Another problem is that you need to increase the size of the pyramid in order to cover the same space. If you use Depth Buffer for any purpose while rendering skybox , you can significantly affect accuracy by increasing the Z_far plane.

  • Overhead

    the difference between 6 and 4 polygons is not so much, because the skybox is huge (covering the whole view), the speed is determined mainly by the number of pixels / texels filed on the screen, and not by the number of vertices. Thus, a pyramid can be even slower than a cube because it must have larger faces (more interpolation iterations are required). But if you want to use a spherical skybox , you will also need a spherical texture, because if you use the standard texture of the cube, the distortion will still be present, and it will be more difficult to save them ... and this is why cubes are more used.

  • Spherical Skyscrapers

    they need a different type of texture. The hemispherical texture looks like this:

    hemisphericall texture

+6
source

Source: https://habr.com/ru/post/986448/


All Articles