Search Unity

  1. Unity Asset Manager is now available in public beta. Try it out now and join the conversation here in the forums.
    Dismiss Notice

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:
    4,195
    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:
    4,195
    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. SoyUnBonus

    SoyUnBonus

    Joined:
    Jan 19, 2015
    Posts:
    43
    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:
    4,195
    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:
    934
  6. SoyUnBonus

    SoyUnBonus

    Joined:
    Jan 19, 2015
    Posts:
    43
    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:
    433
    I'm having the same issue here, it's very confusing why the camera is involved in this process.
     
    easycardgame likes this.
  8. KAJed

    KAJed

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

    dgoyette

    Joined:
    Jul 1, 2016
    Posts:
    4,195
    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:
    24
    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:
    802
    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:
    37
    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
    Unity_DA1 likes this.
  13. herrkjeldsen

    herrkjeldsen

    Joined:
    Nov 30, 2012
    Posts:
    9
  14. Andresmonte

    Andresmonte

    Joined:
    Nov 22, 2014
    Posts:
    37
    thx i fixed my problem using GetCameraRelativePositionWS() before TransformWorldToObject()
    i wonder if this apply to directions as well. ej: normal and tangent
     
  15. H-Alex

    H-Alex

    Joined:
    Oct 2, 2012
    Posts:
    26
    Hey, anything new on that topic? I feel like it is still not "solved" nor clear how the transform works when the camera relative rendering is enabled. @dgoyette