Search Unity

Difference between ViewSpace, Screen Space and Clip Space.

Discussion in 'Shaders' started by DanVioletSagmiller, Dec 26, 2017.

  1. DanVioletSagmiller

    DanVioletSagmiller

    Joined:
    Aug 26, 2010
    Posts:
    204
    I'm watching this tutorial on shaders, and came across the function "UnityObjectToClipPos", which is described as doing a series of transformations, from LocalSpace to WorldSpace to ViewSpace to ClipSpace to Screen Space. I understand Local and world, but I'm having trouble understanding the differences between View, Clip and Screen. What are these?

    - Thanks!
     
  2. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,352
    This might be helpful.
    https://mobile.twitter.com/capnramses/status/936393671519494151/photo/1

    I wrote another post somewhere going into further detail that I can’t find. However the basics are view space (aka eye space) is the position in local camera space, like if you were to attach a game object as a child of a camera game object.

    Clip space is what you get when you apply the projection matrix. This gets a bit complicated, but basically it gets things ready for rasterization by putting what will appear on screen in -w to +w range.

    Screen space is clip space after rasterization, which is clipPos.xyz / clipPos.w (aka device space in that link), or that transformed into a 0.0 to 1.0 UV range (aka viewport space).
     
    Last edited: Dec 27, 2017
    atu93vn, Beauque, gaolei_nls and 4 others like this.
  3. Balikk

    Balikk

    Joined:
    Oct 23, 2014
    Posts:
    49
    Hi,

    If you want a bit more detail on how to go from one to another there was this article from cushycode (website at the bottom of the page, but it looks like it's down, not mine)
     
    raingame_ likes this.
  4. Przemyslaw_Zaworski

    Przemyslaw_Zaworski

    Joined:
    Jun 9, 2017
    Posts:
    328
    For more details about transformations, here is excel file with step-by-step calculations from object space to screen space (link to file is included in movie description)