我有一個頂點着色器,出於某種原因,我無法獲得其中一個制服的位置。glGetActive統一報告統一存在,但glGetUniformLocation返回-1
我用glGetActiveUniform
得到所有可用的制服,我的制服在那裏(bones[0]
)。
但是,當我撥打glGetUniformLocation(shaderProgram_, "bones[0]");
時,它返回-1。
我也試過glGetUniformLocation(shaderProgram_, "bones");
,但它也返回-1。
這裏的着色器:
#version 330 core
uniform mat4 projectionMatrix;
uniform mat4 viewMatrix;
uniform mat4 modelMatrix;
uniform mat4 pvmMatrix;
uniform mat3 normalMatrix;
layout (std140) uniform Bones
{
mat4 bones[100];
};
layout (location = 0) in vec3 position;
layout (location = 1) in vec4 color;
layout (location = 2) in vec3 normal;
layout (location = 3) in vec2 textureCoordinate;
layout (location = 4) in ivec4 boneIds;
layout (location = 5) in vec4 boneWeights;
out vec4 ourColor;
out vec2 texCoord;
out vec3 normalDirection;
void main()
{
mat4 bones2[100];
for(int i=0;i<100;++i)
{
bones2[i] = mat4(1.0);
}
// Calculate the transformation on the vertex position based on the bone weightings
mat4 boneTransform = bones2[ boneIds[0] ] * boneWeights[0];
boneTransform += bones2[ boneIds[1] ] * boneWeights[1];
boneTransform += bones2[ boneIds[2] ] * boneWeights[2];
boneTransform += bones2[ boneIds[3] ] * boneWeights[3];
//mat4 tempM = mat4(1.0);
//boneTransform = tempM;
// This is for animating the model
vec4 tempPosition = boneTransform * vec4(position, 1.0);
gl_Position = pvmMatrix * tempPosition;
float sum = boneWeights[0] + boneWeights[1] + boneWeights[2] + boneWeights[3];
if (sum > 1.01f)
gl_Position = pvmMatrix * vec4(position, 1.0);
else if (sum < 0.99f)
gl_Position = pvmMatrix * vec4(position, 1.0);
/*
if (boneIds[0] > 99 || boneIds[0] < 0)
gl_Position = pvmMatrix * vec4(position, 1.0);
else if (boneIds[1] > 99 || boneIds[1] < 0)
gl_Position = pvmMatrix * vec4(position, 1.0);
else if (boneIds[2] > 99 || boneIds[2] < 0)
gl_Position = pvmMatrix * vec4(position, 1.0);
else if (boneIds[3] > 99 || boneIds[3] < 0)
gl_Position = pvmMatrix * vec4(position, 1.0);
*/
// Calculate normal
vec4 normalDirTemp = boneTransform * vec4(normal, 0.0);
normalDirection = normalize(normalMatrix * normalDirTemp.xyz);
//gl_Position = vec4(position, 1.0);
//gl_Position = pvmMatrix * vec4(position, 1.0);
ourColor = color;
texCoord = textureCoordinate;
for(int i=0;i<100;++i)
{
if (bones[1] == mat4(0.0))
ourColor = vec4(0.0, 0.0, 1.0, 1.0);
}
}
我也試過在我的着色器,其中做使用uniform mat4 bones[100];
給我統一位置(0),然而,所有的數據是mat4(0.0)
,即使我」將數據推送給制服。
任何人有任何想法?
啊,這很有道理!謝謝@NicolBolas。我改變了我的着色器,使用佈局(std140,binding = 0)uniform Bones',它現在一切正常(可以看到我的動畫)。奇怪的是,'統一的mat4骨骼;'如果我使用'glGetUniformLocation'和'glBindBufferBase'函數仍然不起作用。好吧。 – Jarrett
您不能將緩衝區綁定到非塊統一。 –