printbed.fs 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. #version 100
  2. precision highp float;
  3. const vec3 back_color_dark = vec3(0.235, 0.235, 0.235);
  4. const vec3 back_color_light = vec3(0.365, 0.365, 0.365);
  5. uniform sampler2D texture;
  6. uniform bool transparent_background;
  7. uniform bool svg_source;
  8. varying vec2 tex_coord;
  9. vec4 svg_color()
  10. {
  11. // takes foreground from texture
  12. vec4 fore_color = texture2D(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 = texture2D(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. gl_FragColor = color;
  29. }