When I try to pass a uniform uint to a fragment shader from a vertex shader, it changes the value. I have confirmed that the value is 1 in the vertex shader by changing the position if the value is not 1. If the value is 1 in the fragment shader, it shows the diffuse texture instead of the diffuse colour. The code is as follows. Also, I have tries passing it as a value within a uniform vec2, but this did not work either.
Vertex Shader:
#version 410
// Layouts
layout(location = 0) in vec3 position;
layout(location = 1) in vec2 texCoord;
// Uniforms (matrices)
uniform mat4 model, view, proj;
// Uniforms (texture)
uniform uint useDiffuseTexture;
// Uniforms (shininess)
uniform float shininess;
uniform float shininessStrength;
// Uniforms (colour)
uniform vec3 diffuseColour;
uniform vec3 specularColour;
// Outputs (texture)
out uint UseDiffuseTexture;
out vec2 TexCoord;
// Outputs (colour)
out vec3 DiffuseColour;
out vec3 SpecularColour;
// Outputs (shininess)
out float Shininess;
out float ShininessStrength;
void main() {
UseDiffuseTexture = useDiffuseTexture;
TexCoord = texCoord;
if(useDiffuseTexture == 1)
gl_Position = proj * view * model * vec4(position, 1.0);
else
gl_Position = vec4(position, 1.0);
}
Fragment Shader:
#version 410
// Inputs (texture)
in vec2 TexCoord;
uniform sampler2D diffuseTexture;
// Uniforms (texture)
uniform uint UseDiffuseTexture;
// Uniforms (colour)
uniform vec3 DiffuseColour;
uniform vec3 SpecularColour;
// Uniforms (shininess)
uniform float Shininess;
uniform float ShininessStrength;
// Output
out vec4 fragColour;
void main() {
vec4 texColour = vec4(DiffuseColour, 1.0);;
if(UseDiffuseTexture == 1)
texColour = texture(diffuseTexture, TexCoord);
if(texColour.a < 0.2)
discard;
fragColour = texColour;
}