I am working on a shader shader and for some reason my program cannot find the same locations.
Vertex Shader Code:
const int MAX_JOINTS = 30;
const int MAX_WEIGHTS = 3;
in vec3 position;
in vec2 textureCoords;
in vec3 normal;
in ivec3 boneIndices;
in vec3 weights;
out vec4 fragPos;
out vec3 n;
out vec2 texCoords;
out vec4 mcolor;
uniform mat4 modelMatrix;
uniform mat4 projectionMatrix;
uniform mat4 viewMatrix;
uniform mat4 normalMatrix;
uniform mat4[MAX_JOINTS] boneTransforms;
void main() {
vec4 totalLocalPos = vec4(0.0);
vec4 totalNormal = vec4(0.0);
for(int i = 0; i < 3; i++){
mat4 boneTransform = boneTransforms[boneIndices[i]];
vec4 posePosition = boneTransform * vec4(position, 1);
totalLocalPos += posePosition * weights[i];
vec4 worldNormal = boneTransform * vec4(normal, 1);
totalNormal += worldNormal * weights[i];
}
texCoords = textureCoords;
fragPos = modelMatrix * vec4(position,1);
n = totalNormal.xyz;
gl_Position = projectionMatrix * viewMatrix * modelMatrix * totalLocalPos;
}
The unit of bone shape does not appear to be correct; if I request an active form with
GLint uniforms;
glGetProgramiv(shaderProgramID, GL_ACTIVE_UNIFORMS, &uniforms);
for (int i = 0; i < uniforms; i++){
int name_len = -1, num = -1;
GLenum type = GL_ZERO;
char name[100];
glGetActiveUniform(shaderProgramID, GLuint(i), sizeof(name) - 1,
&name_len, &num, &type, name);
name[name_len] = 0;
}
i always gets zero; However, if I just set gl_Position = projectionMatrix * viewMatrix * modelMatrix * vec4 (position, 1), I get the expected result (correct rendering without any skins for the vertices), so the other transformations seem to work even though do they tell me they don't exist? EDIT: this is sometimes the case, sometimes I get the model at position (0,0,0), but otherwise it processes it correctly.
, / , boneTransforms totalLocalPos gl_Positions, .
vector<glm::mat4> boneTransforms = model.getBoneTransforms();
int location = glGetUniformLocation(shaderProgramID, "boneTransforms");
glUniformMatrix4fv(location, boneTransforms.size(), false, (GLfloat*)&boneTransforms);
-1.
- , , ?
EDIT2: , , ( ) . , .
EDIT3: , . , .
EDIT: , .