gouraud.fs 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. #version 110
  2. const vec3 ZERO = vec3(0.0, 0.0, 0.0);
  3. const vec3 GREEN = vec3(0.0, 0.7, 0.0);
  4. const vec3 YELLOW = vec3(0.5, 0.7, 0.0);
  5. const vec3 RED = vec3(0.7, 0.0, 0.0);
  6. const float EPSILON = 0.0001;
  7. struct SlopeDetection
  8. {
  9. bool actived;
  10. // x = yellow, y = red
  11. vec2 z_range;
  12. mat3 volume_world_normal_matrix;
  13. };
  14. uniform vec4 uniform_color;
  15. uniform SlopeDetection slope;
  16. varying vec3 clipping_planes_dots;
  17. // x = tainted, y = specular;
  18. varying vec2 intensity;
  19. varying vec3 delta_box_min;
  20. varying vec3 delta_box_max;
  21. varying float world_normal_z;
  22. vec3 slope_color()
  23. {
  24. float gradient_range = slope.z_range.x - slope.z_range.y;
  25. return (world_normal_z > slope.z_range.x - EPSILON) ? GREEN : ((gradient_range == 0.0) ? RED : mix(RED, YELLOW, clamp((world_normal_z - slope.z_range.y) / gradient_range, 0.0, 1.0)));
  26. }
  27. void main()
  28. {
  29. if (any(lessThan(clipping_planes_dots, ZERO)))
  30. discard;
  31. vec3 color = slope.actived ? slope_color() : uniform_color.rgb;
  32. // if the fragment is outside the print volume -> use darker color
  33. color = (any(lessThan(delta_box_min, ZERO)) || any(greaterThan(delta_box_max, ZERO))) ? mix(color, ZERO, 0.3333) : color;
  34. gl_FragColor = vec4(vec3(intensity.y, intensity.y, intensity.y) + color * intensity.x, uniform_color.a);
  35. }