SHARE
TWEET

Untitled

a guest Mar 20th, 2017 54 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #version 400
  2. layout ( location = 0 ) in vec3 vertex_position;
  3. layout ( location = 1 ) in vec3 vertex_normal;
  4.  
  5. uniform mat4 ModelViewMatrix; //view*model
  6. uniform mat3 NormalMatrix; //transpose(inverse(model)))
  7. uniform mat4 priv_mat; //projection*view*model
  8.  
  9. out vec3 normal;
  10. out vec3 position;
  11.  
  12. void main()
  13. {
  14.   normal=normalize(NormalMatrix*vertex_normal);
  15.   position=vec3(ModelViewMatrix*vec4(vertex_position,1.0));
  16.   gl_Position=priv_mat*vec4(vertex_position,1.0);
  17. }
  18.    
  19. #version 400
  20. in vec3 normal;
  21. in vec3 position;
  22.  
  23. uniform vec4 LightPosition; // light position: vec4(0,0,0,1);
  24. uniform vec3 LightIntensity;
  25.  
  26. uniform vec3 Kd;            // Diffuse reflectivity
  27. uniform vec3 Ka;            // Ambient reflectivity
  28. uniform vec3 Ks;            // Specular reflectivity
  29. uniform float Shininess;    // Shininess
  30.  
  31. vec3 ads( ){
  32.     vec3 n = normal;
  33.     vec3 s = normalize( vec3(LightPosition) - position );
  34.     vec3 v = normalize( vec3(-position));
  35.     vec3 r = reflect( -s, n );
  36. return
  37.     LightIntensity *
  38.     ( Ka +
  39.     Kd * max( dot(s, n), 0.0 ) +  
  40.     Ks * pow( max( dot(r,v), 0.0 ), Shininess ) );
  41. }
  42.  
  43. void main()
  44. {
  45.      gl_FragColor = vec4(ads(), 1.0);
  46. }
RAW Paste Data
Top