Search Unity

Shader graph: World to Object transform not working as I expected

Discussion in 'Graphics Experimental Previews' started by dgoyette, Nov 28, 2018.

  1. dgoyette

    dgoyette

    Joined:
    Jul 1, 2016
    Posts:
    1,997
    Hopefully this is simple, but the following two things are empirically not equivalent, and I don't understand why:

    upload_2018-11-28_15-8-12.png

    and

    upload_2018-11-28_15-8-37.png

    Is it incorrect to think that the Transform node will convert from a World position to Object position? If I plug these two different graphs into the Position output, they cause the object to be draw at very different places. Hopefully something simple I just don't get...
     
  2. dgoyette

    dgoyette

    Joined:
    Jul 1, 2016
    Posts:
    1,997
    I tried this again today under Shader Graph 4.6, and it still doesn't behave the way I'd expect. If I plug the above into the Position output of my graph, the object doesn't rendering at the correct place. So I assume this isn't a bug, and I just don't understand what the Transform node is doing..

    What am I missing? Does it not make sense to take the World position of a vertex, convert it to the object's local position, and then provide that to the Position output? Is that not equivalent to connecting the local position directly to the position output?
     
  3. Miguel-Herrero

    Miguel-Herrero

    Joined:
    Jan 19, 2015
    Posts:
    18
    Did you find what happened there? I've been trying shadergraph and the operation works if I manually multiply the position with the desired matrix, but if I use the transform node it works weirdly as you said.
     
  4. dgoyette

    dgoyette

    Joined:
    Jul 1, 2016
    Posts:
    1,997
    wyatttt provided some detail over in the Shader Graph thread:

    https://forum.unity.com/threads/feedback-wanted-shader-graph.511960/page-34#post-3998545

    You can see his reply to a few of my posts on this same issue. Turns out that camera position needs to be taken into account when trying to do this transformation. It's still not clear to me whether the HDRP team considers that to be a bug that will be fixed in the future, or just the way things are.
     
  5. SebLagarde

    SebLagarde

    Unity Technologies

    Joined:
    Dec 30, 2015
    Posts:
    450
  6. Miguel-Herrero

    Miguel-Herrero

    Joined:
    Jan 19, 2015
    Posts:
    18
    Yes, please. It should work "as expected" even if you later convert the positions to camera space. I spent quite some time wondering why was it working different than doing the matrix operations by myself :rolleyes:
     
  7. zhuchun

    zhuchun

    Joined:
    Aug 11, 2012
    Posts:
    385
    I'm having the same issue here, it's very confusing why the camera is involved in this process.
     
  8. KAJed

    KAJed

    Joined:
    Mar 15, 2013
    Posts:
    8
    Please fix this so that stuff like pixel snapping can be done properly.
     
  9. dgoyette

    dgoyette

    Joined:
    Jul 1, 2016
    Posts:
    1,997
    Just noting that this is still as issue in 2019.1 with HDRP 5.13. Not sure if this needs to be reported or if it's already tracked internally.

    In 2019.1, this still does not give the correct object position:

    upload_2019-5-15_15-45-54.png

    You still need to do something like this:

    upload_2019-5-15_15-46-26.png
     
  10. huwb

    huwb

    Joined:
    Oct 19, 2013
    Posts:
    11
    Seems to still be broken on 2019.2 / HDRP 6.7.1 (position with space set to WS gives RWS).
     
  11. fherbst

    fherbst

    Joined:
    Jun 24, 2012
    Posts:
    312
    Since nobody posted a case number here I reported this:

    (Case 1162188) [HDRP] wrong naming - "World Space" is now "Camera Relative Space" and Transform Node should get that as an option
     
    SKoptev likes this.
  12. SKoptev

    SKoptev

    Joined:
    Jan 15, 2019
    Posts:
    34
    Same problem!
    So, I cannot properly get object-space position of camera at all, or there is some trick?

    Upd.: yes, there is "how to get object-space camera position":
    upload_2019-7-9_20-23-35.png
     
    Last edited: Jul 9, 2019
  13. herrkjeldsen

    herrkjeldsen

    Joined:
    Nov 30, 2012
    Posts:
    7