vrs_texture.gdshader 1.0 KB

123456789101112131415161718192021222324252627282930
  1. shader_type canvas_item;
  2. void fragment() {
  3. float vrs = texture(TEXTURE, UV).r * 255.0;
  4. // Map valid entries to human-visible colors.
  5. // This is only used if using the red channel colors between 0.0/255 and 10.0/255,
  6. // rather than relying on Godot to aliases the output colors below to variable shading rates.
  7. //
  8. // `vrs_texture.png` in this project already uses the aliased colors for convenience,
  9. // but `vrs_texture_original.png` does not.
  10. // The output shading rate from those two textures is identical.
  11. if (vrs == 0.0) { // 1x1
  12. COLOR = vec4(0.0, 0.0, 0.0, 1.0);
  13. } else if (vrs == 1.0) { // 1x2
  14. COLOR = vec4(0.0, 0.5, 0.0, 1.0);
  15. } else if (vrs == 4.0) { // 2x1
  16. COLOR = vec4(0.5, 0.0, 0.0, 1.0);
  17. } else if (vrs == 5.0) { // 2x2
  18. COLOR = vec4(0.5, 0.5, 0.0, 1.0);
  19. } else if (vrs == 6.0) { // 2x4
  20. COLOR = vec4(0.5, 1.0, 0.0, 1.0);
  21. } else if (vrs == 9.0) { // 4x2
  22. COLOR = vec4(1.0, 0.5, 0.0, 1.0);
  23. } else if (vrs == 10.0) { // 4x4
  24. COLOR = vec4(1.0, 1.0, 0.0, 1.0);
  25. } else {
  26. COLOR = vec4(1.0, 0.5, 1.0, 1.0);
  27. }
  28. }