FbVtxShader.glsl 730 B

12345678910111213141516171819202122232425262728
  1. #version 330 core
  2. precision highp float;
  3. uniform mat2 transform;
  4. uniform vec2 window_size;
  5. uniform vec2 offset;
  6. layout(location = 0) in vec2 in_position;
  7. layout(location = 1) in vec2 in_tex_coord;
  8. out vec2 tex_coord;
  9. // Have a fixed aspect ratio, fit the image within the available space.
  10. vec2 get_scale_ratio(void) {
  11. vec2 native_size = vec2(1280, 720);
  12. vec2 ratio = vec2(
  13. (window_size.y * native_size.x) / (native_size.y * window_size.x),
  14. (window_size.x * native_size.y) / (native_size.x * window_size.y)
  15. );
  16. return min(ratio, 1);
  17. }
  18. void main(void) {
  19. tex_coord = in_tex_coord;
  20. vec2 t_pos = (transform * in_position) + offset;
  21. gl_Position = vec4(t_pos * get_scale_ratio(), 0, 1);
  22. }