printbed.fs 942 B

12345678910111213141516171819202122232425262728293031323334
  1. #version 110
  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 texture;
  5. uniform bool transparent_background;
  6. uniform bool svg_source;
  7. varying vec2 tex_coords;
  8. vec4 svg_color()
  9. {
  10. // takes foreground from texture
  11. vec4 fore_color = texture2D(texture, tex_coords);
  12. // calculates radial gradient
  13. vec3 back_color = vec3(mix(back_color_light, back_color_dark, smoothstep(0.0, 0.5, length(abs(tex_coords.xy) - vec2(0.5)))));
  14. // blends foreground with background
  15. return vec4(mix(back_color, fore_color.rgb, fore_color.a), transparent_background ? fore_color.a : 1.0);
  16. }
  17. vec4 non_svg_color()
  18. {
  19. // takes foreground from texture
  20. vec4 color = texture2D(texture, tex_coords);
  21. return vec4(color.rgb, transparent_background ? color.a * 0.25 : color.a);
  22. }
  23. void main()
  24. {
  25. gl_FragColor = svg_source ? svg_color() : non_svg_color();
  26. }