Jump to content
  • Advertisement
WhiskyAndCode

OpenGL Opengl error drawing vertex (far)

Recommended Posts

Hello everyone

I was studying opengl and everything was okay until I raised the terrain size to 5000 (glm :: scale (model, glm :: vec3 (5000, 5000, 5000))). After that the faces began to bug to render, as the video below. Can anyone help me?
In the 500 scale it is normal, but when it is too far away the faces will flash. If I get close it gets normal.

My depth config is glEnable(GL_DEPTH_TEST); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 

Thank you.

 

Share this post


Link to post
Share on other sites
Advertisement

Please provide more information: how do you create your terrain, are you doing some LOD ? What are the parameters of your perspective view ? Maybe something else that you could think is pertinent ?

Share this post


Link to post
Share on other sites
Posted (edited)

Hello _Silence_, sorry :)

I made my terrain in max 3d and exported to .obj (300x300 vertex) and I cared for ASSIMP. No LOD. if I do not scale it works correct.
my perspective view setting is:

glm::perspective(glm::radians(camera.Zoom), (float)SCR_WIDTH / (float)SCR_HEIGHT, 0.1f, drawDistance);

SCR_WIDTH = 1365;
SCR_HEIGHT = 768;

drawDistance = 600000.00f; (test)

 

 

 

Edited by WhiskyAndCode

Share this post


Link to post
Share on other sites

It looks like it might be a depth buffer precision issue. You can try a 32 bit float format for the depth buffer if you are not already doing so. If it doesn't solve the problem, you can also try using the reversed depth buffer technique with floating point depth buffer in which you map your depth buffer to use 1.0f value for near plane, and 0.0f value for far plane. Combined with a floating point depth buffer, you will get close to linear distribution in precision and it is possible to support large viewing distances. You can read more here: https://outerra.blogspot.com/2012/11/maximizing-depth-buffer-range-and.html

Share this post


Link to post
Share on other sites

It's definitely a depth buffer issue.  Part of the problem is that your far plane is at 600,000 and your near plane at 0.1.  This is a very large range, even with a 32bit floating point depth buffer.  I'd leave your near plane at 0.1 , but I'd pull your far plane back to 10,000 or closer (I'm assuming all distances are meters here). 

 

cheers,

 

Bob

Share this post


Link to post
Share on other sites

I would rather scale the model itself (vertices) rather than using scaling matrix, and yes far plane is a bit too big

Try this instead (works for me ;0)

0.1f, 100000.0f

Share this post


Link to post
Share on other sites

Hello guys, thanks for replys.

How i change my bit float format for the depth buffer ?

I am creating my depth framebuffer:
 

glGenRenderbuffers(1, &_textureDepth);
glBindRenderbuffer(GL_RENDERBUFFER, _textureDepth);

glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT, SCR_WIDTH, SCR_HEIGHT);
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, _textureDepth);

 

 

Share this post


Link to post
Share on other sites

Try to fit your far plane to the max distance of your terrain (this might work depending on your terrain max size). And try to make your near plane less close (something around 1). If none of this works, you'll have to do what turanszkij told. But before, maybe just extend to a 32-bit depth buffer (instead of 24).

Also, any reasons why you want to scale your terrain that much ?

Some links that could help:

https://learnopengl.com/Advanced-OpenGL/Depth-testing

https://www.khronos.org/opengl/wiki/Depth_Buffer_Precision

4 hours ago, WhiskyAndCode said:

How i change my bit float format for the depth buffer ?

Use texture attachments. Use GL_DEPTH_COMPONENT24 for 24 bits or GL_DEPTH_COMPONENT32 for 32 bits. Use GL_UNSIGNED_INT or GL_FLOAT for the type.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!