number.fp 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. /*
  2. * Copyright (C) 2020, Inria
  3. * GRAPHDECO research group, https://team.inria.fr/graphdeco
  4. * All rights reserved.
  5. *
  6. * This software is free for non-commercial, research and evaluation use
  7. * under the terms of the LICENSE.md file.
  8. *
  9. * For inquiries contact sibr@inria.fr and/or George.Drettakis@inria.fr
  10. */
  11. #version 420
  12. in vec2 uv_coord;
  13. uniform float value;
  14. uniform int count;
  15. out vec4 out_color;
  16. const float digits[10] = float[](0x69996,0x26222,0x6924F,0x69396,0x99F11,0xF861E,0x68E96,0xF1248,0x69696,0x69716);
  17. float printDigit(int digit, vec2 position){
  18. // Margin scaling/shift
  19. position *= 1.4;
  20. position -= 0.2;
  21. // Early discard.
  22. if(position.x < 0.0 || position.x > 1.0 || position.y < 0.0 || position.y > 1.0){
  23. return 0.0;
  24. }
  25. // [0,1] -> discrete[0,4]x[0,5]
  26. vec2 newPos = floor(vec2(4.0-4.0*position.x,5.0*position.y));
  27. // -> corresponding bit
  28. float index = 4*newPos.y + newPos.x;
  29. // -> get the index-th bit
  30. float isIn = mod(floor(digits[digit]/pow(2.0,index)),2.0);
  31. return isIn;
  32. }
  33. float printPoint(vec2 position){
  34. position *= 1.4;
  35. position -= 0.02;
  36. if(position.x < 0.0 || position.x > 1.0 || position.y < 0.0 || position.y > 1.0){
  37. return 0.0;
  38. }
  39. return length(position - vec2(0.2, 0.4)) < 0.182 ? 1.0 : 0.0;
  40. }
  41. void main(void) {
  42. float deca = printDigit(int(mod(value/10,10)), uv_coord);
  43. float unit = printDigit(int(mod(value,10)), uv_coord-vec2(1.0,0.0));
  44. float deci = printDigit(int(mod(value*10,10)), uv_coord-vec2(2.5,0.0));
  45. float centi = printDigit(int(mod(value*100,10)), uv_coord-vec2(3.5,0.0));
  46. float point = printPoint(uv_coord-vec2(2.0,0.0));
  47. float color = clamp(deca+unit+deci+centi+point,0.0,1.0);
  48. out_color = vec4(color,color, color, 1.0);
  49. }