printbed.fs 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. #version 140
  2. const vec3 back_color_dark = vec3(0.235, 0.235, 0.235);
  3. const vec3 back_color_light = vec3(0.365, 0.365, 0.365);
  4. uniform sampler2D in_texture;
  5. uniform bool transparent_background;
  6. uniform bool svg_source;
  7. in vec2 tex_coord;
  8. out vec4 out_color;
  9. vec4 svg_color()
  10. {
  11. // takes foreground from texture
  12. vec4 fore_color = texture(in_texture, tex_coord);
  13. // calculates radial gradient
  14. vec3 back_color = vec3(mix(back_color_light, back_color_dark, smoothstep(0.0, 0.5, length(abs(tex_coord.xy) - vec2(0.5)))));
  15. // blends foreground with background
  16. return vec4(mix(back_color, fore_color.rgb, fore_color.a), transparent_background ? fore_color.a : 1.0);
  17. }
  18. vec4 non_svg_color()
  19. {
  20. // takes foreground from texture
  21. vec4 color = texture(in_texture, tex_coord);
  22. return vec4(color.rgb, transparent_background ? color.a * 0.25 : color.a);
  23. }
  24. void main()
  25. {
  26. vec4 color = svg_source ? svg_color() : non_svg_color();
  27. color.a = transparent_background ? color.a * 0.5 : color.a;
  28. out_color = color;
  29. }