toolpaths_lines.fs 1.1 KB

12345678910111213141516171819202122232425262728
  1. #version 110
  2. // normalized values for (-0.6/1.31, 0.6/1.31, 1./1.31)
  3. const vec3 LIGHT_TOP_DIR = vec3(-0.4574957, 0.4574957, 0.7624929);
  4. const vec3 LIGHT_FRONT_DIR = vec3(0.0, 0.0, 1.0);
  5. // x = ambient, y = top diffuse, z = front diffuse, w = global
  6. uniform vec4 light_intensity;
  7. uniform vec4 uniform_color;
  8. varying vec3 eye_normal;
  9. void main()
  10. {
  11. vec3 normal = normalize(eye_normal);
  12. // Compute the cos of the angle between the normal and lights direction. The light is directional so the direction is constant for every vertex.
  13. // Since these two are normalized the cosine is the dot product. Take the abs value to light the lines no matter in which direction the normal points.
  14. float NdotL = abs(dot(normal, LIGHT_TOP_DIR));
  15. float intensity = light_intensity.x + NdotL * light_intensity.y;
  16. // Perform the same lighting calculation for the 2nd light source.
  17. NdotL = abs(dot(normal, LIGHT_FRONT_DIR));
  18. intensity += NdotL * light_intensity.z;
  19. gl_FragColor = vec4(uniform_color.rgb * light_intensity.w * intensity, uniform_color.a);
  20. }