Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

Resolved Accessing screen position after vertex position change?

Discussion in 'Shader Graph' started by dansitnick, May 7, 2019.

  1. dansitnick

    dansitnick

    Joined:
    Jun 9, 2016
    Posts:
    14
    I'm manipulating the vertex position in my shader, but when setting the color, the Screen Position node seems to pass me the data from before the vertex shader is applied. I'm looking to do screen-space effects without positional distortions, which would require an up-to-date screen position.

    I may have one potential workaround (grabbing the world position, transforming it to view space, and converting that to screen position) but I can't figure out how to go from view to screen position.

    Any help would be much appreciated!
     
  2. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,256
    You’ll need to convert the Vector3 view space position into a Vector4 with w set to 1. Then use the Transform Matrix node to get the projection matrix and multiply the Vector4 view position and the matrix together (with the matrix going into A).

    After that divide the resulting value’s XY by the W * 2 and add 0.5. You now have the 0.0 to 1.0 normalized screen position.
     
  3. dansitnick

    dansitnick

    Joined:
    Jun 9, 2016
    Posts:
    14
    Incredible, thank you! I had missed the Transformation Matrix node completely, and your descriptiveness and detail will really save me a lot of trial and error. Thanks again!
     
  4. Jwako

    Jwako

    Joined:
    May 22, 2019
    Posts:
    8
    Hate to resurrect an old thread, but any chance to get a screenshot of the node setup for this? Cant find anyone else who discussed this and it's not working for me.
     
    Last edited: Jun 28, 2019
  5. MatiasAvilesOcteto

    MatiasAvilesOcteto

    Joined:
    Dec 12, 2022
    Posts:
    1
    In case anyone ever needs it

    upload_2023-1-23_18-22-35.png
     
    Jwako likes this.