eyeToWindowCoordinates.glsl 1.2 KB

1234567891011121314151617181920212223242526272829303132
  1. /**
  2. * Transforms a position from eye to window coordinates. The transformation
  3. * from eye to clip coordinates is done using {@link czm_projection}.
  4. * The transform from normalized device coordinates to window coordinates is
  5. * done using {@link czm_viewportTransformation}, which assumes a depth range
  6. * of <code>near = 0</code> and <code>far = 1</code>.
  7. * <br /><br />
  8. * This transform is useful when there is a need to manipulate window coordinates
  9. * in a vertex shader as done by {@link BillboardCollection}.
  10. *
  11. * @name czm_eyeToWindowCoordinates
  12. * @glslFunction
  13. *
  14. * @param {vec4} position The position in eye coordinates to transform.
  15. *
  16. * @returns {vec4} The transformed position in window coordinates.
  17. *
  18. * @see czm_modelToWindowCoordinates
  19. * @see czm_projection
  20. * @see czm_viewportTransformation
  21. * @see BillboardCollection
  22. *
  23. * @example
  24. * vec4 positionWC = czm_eyeToWindowCoordinates(positionEC);
  25. */
  26. vec4 czm_eyeToWindowCoordinates(vec4 positionEC)
  27. {
  28. vec4 q = czm_projection * positionEC; // clip coordinates
  29. q.xyz /= q.w; // normalized device coordinates
  30. q.xyz = (czm_viewportTransformation * vec4(q.xyz, 1.0)).xyz; // window coordinates
  31. return q;
  32. }