Jump to content

Opengl Shader Color Fighting

AustinJ

I am passing color values to the shader through an buffer object in a vao. I intend for the color to be added to the texture color. What I am doing seems like it should work however it seems like I have z-fighting. The colors act as if there is z-fighting however the triangles are only being rendered once. The first image is what it looks like most of the time, however if I look down it looks like it should for the most part sometimes fighting when rotating the camera and such.

 

The game is made in C++ and OpenGL on Linux using the nVidia drivers. I am not sure what is causing this so if anybody has any ideas let me know.

 

Vertex Shader:

#version 450 layout (location = 0) in vec3 inVertex;layout (location = 1) in vec3 inCoords;layout (location = 2) in vec3 inNormal;layout (location = 3) in vec4 inColor; uniform mat4 projectionMatrix;uniform mat4 viewMatrix;uniform mat4 modelMatrix; out vec3 coords;out vec4 addedColor; void main(){gl_Position = projectionMatrix * viewMatrix * modelMatrix * vec4(inVertex, 1.0f);addedColor = inColor;coords = inCoords;}
 
Fragment Shader
#version 450#extension GL_EXT_texture_array : enable in vec3 coords;in vec4 addedColor; out vec4 out_colour;uniform sampler2DArray textures; void main(){ out_colour = clamp((addedColor + texture2DArray(textures, coords)), 0, 1);}
 

issue-01.png

 

issue-02.png

Link to comment
Share on other sites

Link to post
Share on other sites

Is inColor constant or are you calculating new colors every frame?

1474412270.2748842

Link to comment
Share on other sites

Link to post
Share on other sites

It is computed when the chunk updates its model, so it is relatively constant.

Link to comment
Share on other sites

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

×