modelToWindowCoordinates.glsl 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. /**
  2. * Transforms a position from model to window coordinates. The transformation
  3. * from model to clip coordinates is done using {@link czm_modelViewProjection}.
  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. * <br /><br />
  11. * This function should not be confused with {@link czm_viewportOrthographic},
  12. * which is an orthographic projection matrix that transforms from window
  13. * coordinates to clip coordinates.
  14. *
  15. * @name czm_modelToWindowCoordinates
  16. * @glslFunction
  17. *
  18. * @param {vec4} position The position in model coordinates to transform.
  19. *
  20. * @returns {vec4} The transformed position in window coordinates.
  21. *
  22. * @see czm_eyeToWindowCoordinates
  23. * @see czm_modelViewProjection
  24. * @see czm_viewportTransformation
  25. * @see czm_viewportOrthographic
  26. * @see BillboardCollection
  27. *
  28. * @example
  29. * vec4 positionWC = czm_modelToWindowCoordinates(positionMC);
  30. */
  31. vec4 czm_modelToWindowCoordinates(vec4 position)
  32. {
  33. vec4 q = czm_modelViewProjection * position; // clip coordinates
  34. q.xyz /= q.w; // normalized device coordinates
  35. q.xyz = (czm_viewportTransformation * vec4(q.xyz, 1.0)).xyz; // window coordinates
  36. return q;
  37. }