Search Unity

Question Is it possible to "freeze" or sample the data from the Position Node?

Discussion in 'Shader Graph' started by Zillus, Jul 18, 2020.

  1. Zillus

    Zillus

    Joined:
    May 31, 2017
    Posts:
    24
    Odd title, I know; I'll explain.

    I have spent a few days learning Shader Graph and putting together a fog-of-war prototype. One element of the system involves projecting a texture onto a flat plane from the point of view of the camera so that the angles look right (orthographic camera locked at 45 degrees relative to the plane). I achieve this by feeding a Postion(Space - View) node into the Sample Texture node's UV slot via a Tile and Offset Node. The flaw, completely obvious to me now, is that the projection moves with the camera, which breaks my system.

    So, my question is, is there a way to sample/freeze the initial value from the Position Node, and continue to project the texture from that angle, allowing me to move the camera without the texture following?

    I am not even sure what kind of data exactly the Position Node is feeding. Considering my camera is locked at a specific angle all the time can I just feed a hard-coded value into the UV without using that node at all; any idea how I would generate that value?

    It's an unlit graph in URP by the way, though I doubt that matters for this.

    I will be very, very sad if all the work I have done on this system can't be saved for the sake of this one issue - please help.

    Thanks!
     
  2. adamgolden

    adamgolden

    Joined:
    Jun 17, 2019
    Posts:
    1,555
    You could expose a "view offset" property and add it to your Position in the shader, call material SetVector("_viewOffset", currentViewOffset) whenever the camera position changes - there's probably a way to do it in the shader itself though.
     
    Zillus likes this.
  3. Zillus

    Zillus

    Joined:
    May 31, 2017
    Posts:
    24
    Oh, interest! What value would I feed, a vector representing the difference between the camera's original position and its current position? Or the inverse of that, I suppose?
     
  4. adamgolden

    adamgolden

    Joined:
    Jun 17, 2019
    Posts:
    1,555
    Yeah - just be sure that the difference you're passing is also in view space.
     
  5. Zillus

    Zillus

    Joined:
    May 31, 2017
    Posts:
    24
    adamgolden likes this.