gouraud.fs 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. #version 110
  2. const vec3 ZERO = vec3(0.0, 0.0, 0.0);
  3. //BBS: add grey and orange
  4. //const vec3 GREY = vec3(0.9, 0.9, 0.9);
  5. const vec3 ORANGE = vec3(0.8, 0.4, 0.0);
  6. const float EPSILON = 0.0001;
  7. struct PrintVolumeDetection
  8. {
  9. // 0 = rectangle, 1 = circle, 2 = custom, 3 = invalid
  10. int type;
  11. // type = 0 (rectangle):
  12. // x = min.x, y = min.y, z = max.x, w = max.y
  13. // type = 1 (circle):
  14. // x = center.x, y = center.y, z = radius
  15. vec4 xy_data;
  16. // x = min z, y = max z
  17. vec2 z_data;
  18. };
  19. struct SlopeDetection
  20. {
  21. bool actived;
  22. float normal_z;
  23. mat3 volume_world_normal_matrix;
  24. };
  25. uniform vec4 uniform_color;
  26. uniform SlopeDetection slope;
  27. //BBS: add outline_color
  28. uniform bool is_outline;
  29. uniform bool offset_depth_buffer;
  30. #ifdef ENABLE_ENVIRONMENT_MAP
  31. uniform sampler2D environment_tex;
  32. uniform bool use_environment_tex;
  33. #endif // ENABLE_ENVIRONMENT_MAP
  34. varying vec3 clipping_planes_dots;
  35. // x = diffuse, y = specular;
  36. varying vec2 intensity;
  37. uniform PrintVolumeDetection print_volume;
  38. varying vec4 model_pos;
  39. varying vec4 world_pos;
  40. varying float world_normal_z;
  41. varying vec3 eye_normal;
  42. void main()
  43. {
  44. if (any(lessThan(clipping_planes_dots, ZERO)))
  45. discard;
  46. vec3 color = uniform_color.rgb;
  47. float alpha = uniform_color.a;
  48. if (slope.actived && world_normal_z < slope.normal_z - EPSILON) {
  49. //color = vec3(0.7, 0.7, 1.0);
  50. color = ORANGE;
  51. alpha = 1.0;
  52. }
  53. //BBS: add outline_color
  54. if (is_outline)
  55. gl_FragColor = uniform_color;
  56. #ifdef ENABLE_ENVIRONMENT_MAP
  57. else if (use_environment_tex)
  58. gl_FragColor = vec4(0.45 * texture2D(environment_tex, normalize(eye_normal).xy * 0.5 + 0.5).xyz + 0.8 * color * intensity.x, alpha);
  59. #endif
  60. else
  61. gl_FragColor = vec4(vec3(intensity.y) + color * intensity.x, alpha);
  62. // In the support painting gizmo and the seam painting gizmo are painted triangles rendered over the already
  63. // rendered object. To resolved z-fighting between previously rendered object and painted triangles, values
  64. // inside the depth buffer are offset by small epsilon for painted triangles inside those gizmos.
  65. gl_FragDepth = gl_FragCoord.z - (offset_depth_buffer ? EPSILON : 0.0);
  66. }