common.h 895 B

1234567891011121314151617181920212223242526272829303132333435
  1. // SPDX-License-Identifier: Unlicense OR MIT
  2. struct m3x2 {
  3. vec3 r0;
  4. vec3 r1;
  5. };
  6. // fboTransform is the transformation that cancels the implied transformation
  7. // between the clip space and the framebuffer. Only two rows are returned. The
  8. // last is implied to be [0, 0, 1].
  9. const m3x2 fboTransform = m3x2(
  10. #if defined(LANG_HLSL) || defined(LANG_MSL) || defined(LANG_MSLIOS)
  11. vec3(1.0, 0.0, 0.0),
  12. vec3(0.0, -1.0, 0.0)
  13. #else
  14. vec3(1.0, 0.0, 0.0),
  15. vec3(0.0, 1.0, 0.0)
  16. #endif
  17. );
  18. // windowTransform is the transformation that cancels the implied transformation
  19. // between framebuffer space and window system coordinates.
  20. const m3x2 windowTransform = m3x2(
  21. #if defined(LANG_VULKAN)
  22. vec3(1.0, 0.0, 0.0),
  23. vec3(0.0, 1.0, 0.0)
  24. #else
  25. vec3(1.0, 0.0, 0.0),
  26. vec3(0.0, -1.0, 0.0)
  27. #endif
  28. );
  29. vec3 transform3x2(m3x2 t, vec3 v) {
  30. return vec3(dot(t.r0, v), dot(t.r1, v), dot(vec3(0.0, 0.0, 1.0), v));
  31. }