image_viewer.frag 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  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 texcoord;
  13. layout(binding = 0) uniform sampler2D in_texture;
  14. uniform vec4 minVal = vec4(0.0);
  15. uniform vec4 maxVal = vec4(1.0);
  16. uniform vec4 channels = vec4(1.0);
  17. layout(location = 0) out vec4 out_color;
  18. void main(void)
  19. {
  20. if(any(greaterThan(texcoord, vec2(1.0))) || any(lessThan(texcoord, vec2(0.0)))){
  21. discard;
  22. }
  23. vec4 col = texture(in_texture, texcoord);
  24. // Rescale.
  25. out_color = channels*(col - minVal)/(maxVal - minVal);
  26. // If only one channel is enabled, no alpha and B&W image.
  27. if(dot(channels, vec4(1.0)) == 1.0){
  28. float val = dot(out_color, channels);
  29. out_color.rgb = vec3(val);
  30. out_color.a = 1.0;
  31. }
  32. // Ensure visibility when alpha is disabled.
  33. if(channels[3] == 0.0f){
  34. out_color.a;
  35. }
  36. }