OpenGL skybox Skybox realizes that the sky box is not fully displayed (the sky box part is truncated)

question:

When implementing the OpenGL skybox, under the premise that the Shader and vertex data are correct, the rendered picture will always be unable to be displayed completely. There will be some parts that have no pixel color and display the color set by glClearColor. Rotation, texture sampling, and view matrix are all correct. Since it is difficult to describe, it is also inconvenient to check the search problem, so I will record the troubleshooting process.

Insert image description here
Insert image description here

Troubleshooting process

  1. Make sure that the input vertex data is correct: When the sampling results are correct, some vertex images are not sampled. The first thing to consider is that the node data is wrong, which causes some vertices to be drawn incorrectly when the vertex Shader is processed, so I first use Enter the wireframe mode and confirm whether there is a problem with the drawing of the vertices. The results are as follows:
    Insert image description here
    There is obviously a problem with such a picture. Normally, after VP conversion, the rectangular wireframe does not appear in such a shape, so it is suspected that it is the vertices. There is a problem with the data. Because I have encapsulated a vertex data processing class myself, I suspect that there is an error in the processing process.
    However, when using the same data to use the "wooden box" Shader in the picture, the result is correct and the correct shape can be drawn, so the problem of the vertex data is basically eliminated.
  2. Make sure that the passed values ​​of Vert and Frag's Shader are correct: It is easy to determine that it is not a problem with Frag. First, the image is sampled correctly (at least in the visible part), and then I only let Frag output a fixed solid color. The result Only the sampled part can be displayed, so it is basically ruled out that it is a Frag problem. Then the problem can only be a problem with Vert, and nothing else is interfering with the drawing of vertices.
  3. Check the input of Vert Shader: The Skybox Shader does not input the model matrix, only the View and Projection matrices. I first added a model matrix to confirm that there was no problem with my operation and that the object could be drawn correctly. So the problem is very vague at this point, because the same matrix data and the same Shader draw different results when drawing with and without model objects. The skybox should not be associated with the model.
  4. Create a normal box and observe inside: Because the skybox is also a box, so when I create a box and observe inside it, it should have the same effect. So I created a normal box using the vertex data of the skybox, and then moved the lens Move inside to observe. I found that the performance was normal before entering the interior. After entering the interior, a situation similar to the sky box began to appear. Using wireframe mode, I found that the vertex drawing line was indeed cut off, just like when the lens and model are too close in Unity. phenomenon, so determine the direction again and check the view and projection.
  5. Check the incoming view and projection matrices again: in the end, the only way to solve the problem is to see if the values ​​of view and projection are passed incorrectly at some stage. Comparing it with the standard answer, I found that the value of the near plane of the projection was set to 1, while the standard answer was 0.1. At this point, I suddenly realized that due to the near plane relationship, part of the content was cropped, which is consistent with the phenomenon I observed. , after modifying the value of the near plane, the result is correct
    Insert image description here

Insert image description here

Summarize

When drawing the sky box and calculating the projection, the value of the near plane used cannot be too large.

Guess you like

Origin blog.csdn.net/qq_37421018/article/details/126159289
sky