vrs.glsl 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. #[vertex]
  2. #version 450
  3. #VERSION_DEFINES
  4. #ifdef MULTIVIEW
  5. #ifdef has_VK_KHR_multiview
  6. #extension GL_EXT_multiview : enable
  7. #define ViewIndex gl_ViewIndex
  8. #else // has_VK_KHR_multiview
  9. #define ViewIndex 0
  10. #endif // has_VK_KHR_multiview
  11. #endif //MULTIVIEW
  12. #ifdef MULTIVIEW
  13. layout(location = 0) out vec3 uv_interp;
  14. #else
  15. layout(location = 0) out vec2 uv_interp;
  16. #endif
  17. void main() {
  18. vec2 base_arr[4] = vec2[](vec2(0.0, 0.0), vec2(0.0, 1.0), vec2(1.0, 1.0), vec2(1.0, 0.0));
  19. uv_interp.xy = base_arr[gl_VertexIndex];
  20. #ifdef MULTIVIEW
  21. uv_interp.z = ViewIndex;
  22. #endif
  23. gl_Position = vec4(uv_interp.xy * 2.0 - 1.0, 0.0, 1.0);
  24. }
  25. #[fragment]
  26. #version 450
  27. #VERSION_DEFINES
  28. #ifdef MULTIVIEW
  29. #ifdef has_VK_KHR_multiview
  30. #extension GL_EXT_multiview : enable
  31. #define ViewIndex gl_ViewIndex
  32. #else // has_VK_KHR_multiview
  33. #define ViewIndex 0
  34. #endif // has_VK_KHR_multiview
  35. #endif //MULTIVIEW
  36. #ifdef MULTIVIEW
  37. layout(location = 0) in vec3 uv_interp;
  38. layout(set = 0, binding = 0) uniform sampler2DArray source_color;
  39. #else /* MULTIVIEW */
  40. layout(location = 0) in vec2 uv_interp;
  41. layout(set = 0, binding = 0) uniform sampler2D source_color;
  42. #endif /* MULTIVIEW */
  43. layout(location = 0) out uint frag_color;
  44. void main() {
  45. #ifdef MULTIVIEW
  46. vec3 uv = uv_interp;
  47. #else
  48. vec2 uv = uv_interp;
  49. #endif
  50. #ifdef MULTIVIEW
  51. vec4 color = textureLod(source_color, uv, 0.0);
  52. frag_color = uint(color.r * 255.0);
  53. #else /* MULTIVIEW */
  54. vec4 color = textureLod(source_color, uv, 0.0);
  55. // for user supplied VRS map we do a color mapping
  56. color.r *= 3.0;
  57. frag_color = int(color.r) << 2;
  58. color.g *= 3.0;
  59. frag_color += int(color.g);
  60. // note 1x4, 4x1, 1x8, 8x1, 2x8 and 8x2 are not supported
  61. // 4x8, 8x4 and 8x8 are only available on some GPUs
  62. #endif /* MULTIVIEW */
  63. }