当我尝试将均匀uint从顶点着色器传递给片段着色器时,它会更改该值。我已经确认,如果值不是1,则通过更改位置在顶点着色器中值为1.如果片段着色器中的值为1,则显示漫反射纹理而不是漫反射颜色。代码如下。此外,我尝试将其作为统一vec2中的值传递,但这也不起作用。
顶点着色器:
#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;
}
答案 0 :(得分:0)
在片段着色器中,您声明uniform uint UseDiffuseTexture
。如果您希望它是来自顶点着色器的值,则它必须是in uint UseDiffuseTexture
修改
由于输入是unsigned int,因此必须使用“flat”:flat in uint UseDiffuseTexture
答案 1 :(得分:0)
老兄,错误的定义:D。变化
uniform uint UseDiffuseTexture;
uniform vec3 DiffuseColour;
uniform vec3 SpecularColour;
带有的片段着色器中的
in uint UseDiffuseTexture;
in vec3 DiffuseColour;
in vec3 SpecularColour;
只是因为你通过顶点着色器传递它而你的片段着色器需要4个IN,因为你的顶点着色器有4个OUT ...