In OpenGL, how do I make my skybox not cover any of my entities?

I am working on an OpenGL game in Java with LWJGL (ThinMatrix tutorials at the moment) and I just added my skybox. However, as can be seen from the figure, it cuts trees and covers everything that is beyond a certain point.

Here is my rendering code for skybox:

public void render(Camera camera, float r, float g, float b) {
    shader.start();
    shader.loadViewMatrix(camera);
    shader.loadFogColor(r, g, b);
    GL30.glBindVertexArray(cube.getVaoID());
    GL20.glEnableVertexAttribArray(0);
    bindTextures();
    GL11.glDrawArrays(GL11.GL_TRIANGLES, 0, cube.getVertexCount());
    GL30.glBindVertexArray(0);
    shader.stop();
}

private void bindTextures() {
    GL13.glActiveTexture(GL13.GL_TEXTURE0);
    GL11.glBindTexture(GL13.GL_TEXTURE_CUBE_MAP, texture);
    GL13.glActiveTexture(GL13.GL_TEXTURE1);
    GL11.glBindTexture(GL13.GL_TEXTURE_CUBE_MAP, nightTexture);
    shader.loadBlendFactor(getBlendFactor());
}

also, if necessary, here is my code for my rendering wizard:

public void render(List<Light> lights, Camera camera){
    prepare();
    shader.start();
    shader.loadSkyColor(RED, GREEN, BLUE);
    shader.loadLights(lights);
    shader.loadViewMatrix(camera);
    renderer.render(entities);
    shader.stop();
    terrainShader.start();
    terrainShader.loadSkyColor(RED, GREEN, BLUE);
    terrainShader.loadLight(lights);
    terrainShader.loadViewMatrix(camera);
    terrainRenderer.render(terrains);
    terrainShader.stop();
    skyboxRenderer.render(camera, RED, GREEN, BLUE);
    terrains.clear();
    entities.clear();
}

Image

+4
source share
4 answers

There are two things you can do.

If you draw your skybox first, you can turn off your depth test glDisable(GL_DEPTH_TEST)or write your depth glDepthMask(false). This will prevent your skybox from drawing depth values ​​and the skybox will never be before what is drawn later.

skybox , , w - 0. (x y z 0) , (x y z). , glEnable(GL_DEPTH_CLAMP), OpenGl Skybox, , skybox , .

. , , OpenGL skybox, . skyboxes , .

+4

, (zfar/gluPerspective), openGL ? , skybox .

, , skybox. ; skybox, .

+1

skybox , , skybox, .

skybox, skybox, .

, , , ( ). . , skybox.

skybox , transformMatrix. 4x4 , . TerrainRenderer.java, loadModelMatrix. . , , .

+1

I am not familiar with LWJGL, are you all ready to write a shader? In simple opengl, you don’t have to worry about the size of the skybox cube, it can be {1.0, 1.0, 1.0}if you want. You need to first place the camera on {0.0, 0.0, 0.0}and do a Skybox scan depth test against everything in your scene, you can achieve this by making the skybox value zin the normalized coordinate of the device 1.0.

Do it in your vertex shader

gl_Position = (mvp_mat * vec4(xyz, 1.0)).xyww;

after dividing the perspective by w, zwill be w / wor 1.0.

+1
source

All Articles