hey guys I´m reading opengl 4.0 shading cook book to get a feeling for shaders and learn the basics but I fail with my first simple diffuse shader example. thats my code:
Vertex
#version 400
layout (location = 0) in vec3 VertexPosition;
layout (location = 1) in vec3 VertexNormal;
out vec3 LightIntensity;
uniform vec4 LightPosition; // Light position in eye coords.
uniform vec3 Kd; // Diffuse reflectivity
uniform vec3 Ld; // Light source intensity
uniform mat4 ModelViewMatrix;
uniform mat3 NormalMatrix;
uniform mat4 ProjectionMatrix;
uniform mat4 MVP; // Projection * ModelView
void main(){
// Convert normal and position to eye coords
vec3 tnorm = normalize( NormalMatrix * VertexNormal);
vec4 eyeCoords = ModelViewMatrix * vec4(VertexPosition,1.0);
vec3 s = normalize(vec3(LightPosition - eyeCoords));
// The diffuse shading equation
LightIntensity = Ld * Kd * max( dot( s, tnorm ), 0.0 );
// Convert position to clip coordinates and pass along
gl_Position = MVP * vec4(VertexPosition,1.0);
}
Fragment
#version 400
in vec3 LightIntensity;
layout( location = 0 ) out vec4 FragColor;
void main()
{
FragColor = vec4(LightIntensity, 1.0);
}
I attached the shader to a material and to a ground but it is still invisible and the screen is black.