I'm writing a solar system simulation and some objects are either too far or too small to be rendered even to a single pixel. This behavior is expected but it's creating some artifacts. For small camera movements, the object alternates between being rendered to a single pixel and not being rendered at all, creating a "flickering" artifact.
Is it possible to enforce that an object is always rendered to at least 1 pixel? Or maybe any other technique to avoid this problem.
The issue persists when calling
glDepthFunc(GL_ALWAYS)
and the fartherst object is 4412 units away from the camera while the far plane is 10000 units away.
Objects rendered are spheres (planets) using the code from this answer with 36 sectors and 36 rings, the draw call for the spheres is
glDrawElements(GL_QUADS, m_Indices.size(), GL_UNSIGNED_SHORT, (void *)0)
and the shaders used are listed below:
Vertex Shader
#version 330 core
layout(location = 0) in vec3 in_Position;
layout(location = 1) in vec3 in_Normal;
layout(location = 2) in vec2 in_TexCoord;
uniform mat4 un_mvpMatrix;
out vec2 TexCoord;
void main() {
gl_Position = un_mvpMatrix * vec4(in_Position, 1.0);
TexCoord = in_TexCoord;
}
Fragment Shader
#version 330 core
in vec2 TexCoord;
uniform sampler2D in_Texture;
out vec4 FragColor;
void main() {
FragColor = texture(in_Texture, TexCoord);
}