Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #version 400
- layout ( location = 0 ) in vec3 vertex_position;
- layout ( location = 1 ) in vec3 vertex_normal;
- uniform mat4 ModelViewMatrix; //view*model
- uniform mat3 NormalMatrix; //transpose(inverse(modelviewmatrix))) //top 3x3 row of model*view
- uniform mat4 priv_mat; //projection*view*model
- out vec3 normal;
- out vec3 position;
- void main()
- {
- normal=normalize(NormalMatrix*vertex_normal);
- position=vec3(ModelViewMatrix*vec4(vertex_position,1.0));
- gl_Position=priv_mat*vec4(vertex_position,1.0);
- }
- #version 400
- in vec3 normal;
- in vec3 position;
- uniform vec4 LightPosition; // *needs to be in view-space* (view*lightpos)
- uniform vec3 LightIntensity;
- uniform vec3 Kd; // Diffuse reflectivity
- uniform vec3 Ka; // Ambient reflectivity
- uniform vec3 Ks; // Specular reflectivity
- uniform float Shininess; // Shininess
- vec3 ads( ){
- vec3 n = normal;
- vec3 s = normalize( vec3(LightPosition) - position );
- vec3 v = normalize( vec3(-position));
- vec3 r = reflect( -s, n );
- return
- LightIntensity *
- ( Ka +
- Kd * max( dot(s, n), 0.0 ) +
- Ks * pow( max( dot(r,v), 0.0 ), Shininess ) );
- }
- void main()
- {
- gl_FragColor = vec4(ads(), 1.0);
- }
Add Comment
Please, Sign In to add comment