Advertisement
Guest User

Untitled

a guest
Mar 20th, 2018
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /* === YOUR WORK HERE ===
  2.  * Fragment shader: you need to edit the code here!
  3.  * First, you need to understand the Java program,
  4.  * mainly understand how the variables in this shader program
  5.  * are associated with buffers and variables defined  in your Java program.
  6.  * Also you need to understand how data are passed from
  7.  * your vertex shader to the fragment shader.
  8.  * The changes you need to do here is
  9.  * (a) use the 'texture0' variable for applying a texture to the die
  10.  * (b) compute the ambient+diffuse shading term for each pixel. This will need
  11.  *     to be multiplied with the texture color
  12.  * (c) use the timer to further modulate the red and green channel of your pixels
  13. */
  14. #version 330
  15.  
  16. in vec2 uv_coordinates_raster;
  17. in vec3 normals_raster;
  18. in vec3 light0_vector_raster;
  19.  
  20. uniform sampler2D texture0;
  21. uniform float timer;
  22.  
  23. out vec4 glFragColor; // user-defined variable replacing gl_FragColor in latest GLSL versions
  24.  
  25. void main() {
  26.    
  27.     const vec3 diffuse_light_color = vec3(0.25, 0.25, 0.5);
  28.     const vec3 ambient_light_color = vec3(0.75, 0.75, 0.75);
  29.    
  30.     // you need to change the following lines (and use the above variables and constants)
  31.     glFragColor = texture(texture0, uv_coordinates_raster) * vec4(ambient_light_color + (diffuse_light_color * max(dot(normals_raster, light0_vector_raster), 0.0)), 0.0);
  32.     glFragColor += vec4(0.1 * cos(.01*timer), 0.1 * cos(.01*timer), 0.0, 1.0);
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement