Reputation: 1824
I have an object from Blender rendered into my scene and the normals are loaded correctly. I´m using Gourrad Diffuse shading passing the ModelViewProjectionMatrix (CameraToClip * ModelToCamera) to the shader and a 3x3 version of the ModelToCameraMatrix to multiply with the normals.
However, When I'm setting the output color to DiffuseColor * Angle my entire object (a cube in my case) just dissapears (not even black lines, nothing shows up on my gray background). When I replace the coloroutput to
theColor = Vec4(1.0f, 1.0f, 1.0f, 1.0f);
it displays my obj in white without any shading. I am quite curious as to why I'm not seeing anything? Is there something wrong with my shader or with the way I pass my uniforms?
Vertex Shader:
#version 330
layout(location = 0) in vec4 position;
layout(location = 1) in vec3 normal;
smooth out vec4 theColor;
uniform mat4 modelViewProjectionMatrix;
uniform vec3 lightDir;
uniform mat3 normalModelToCameraMatrix;
void main()
{
gl_Position = modelViewProjectionMatrix * position;
vec3 normCamSpace = normalize(normalModelToCameraMatrix * normal);
vec4 diffuseColor = vec4(0.6f, 0.7f, 0.8f, 1.0f);
float angle = dot(normCamSpace, lightDir);
angle = clamp(angle, 0, 1);
theColor = diffuseColor * angle;
}
Render method:
stack.Translate(glm::vec3(0.0f, 0.0f, 3.0f));
glm::vec4 lightDirCameraSpace = stack.Top() * glm::vec4(1.5f, 1.0f, 0.0f, 0.0f);
glUniform3fv(lightDirUnif, 1, glm::value_ptr(lightDirCameraSpace));
glm::mat3 normalMatrix(stack.Top());
glUniformMatrix3fv(normalModelToCameraMatrixUnif, 1, GL_FALSE, glm::value_ptr(normalMatrix));
// Draw Blender object
glBindVertexArray(this->load.vertexArrayOBject);
glm::mat4 modelViewProjectionMatrix = cameraToClipMatrix * stack.Top();
glUniformMatrix4fv(modelViewProjectionMatrixUnif, 1, GL_FALSE, glm::value_ptr(modelViewProjectionMatrix));
glDrawElements(GL_TRIANGLES, this->load.indicesVec.size(), GL_UNSIGNED_INT, 0);
I can't see what's wrong with the shader nor the rendering part.
Upvotes: 0
Views: 600
Reputation: 18015
My guess is that you're:
angle
to the alpha channelSo alpha=0, the polygon is all transparent/alpha-tested.
What you should do first is make sure alpha is always 1.f, and only modulate the rgb. You could also turn off blending/alpha-test.
Then, fix the math that actually compute the angle variable as you want it.
Upvotes: 1