Search Unity

UV Scrolling with HDRP Lit Shader

Discussion in 'General Graphics' started by ShadyAlien, Jun 27, 2018.

  1. ShadyAlien

    ShadyAlien

    Joined:
    Aug 28, 2009
    Posts:
    210
    I've been playing around with the HD Render Pipeline, and I've been trying to figure out how to do basic UV scrolling with the default lit shader. Specifically, I'm looking to scroll the normal map, but accessing "_NormalMap"'s UV offset does nothing. It doesn't return any errors, but it also doesn't seem to do anything (note: I'm using a script that worked with the Standard Shader in Unity 5). Since it seems that the UV offset/tiling is shared between all of the base maps in this shader, is there some universal property that needs to be changed that I'm missing?
     
  2. hippocoder

    hippocoder

    Digital Ape

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    Is this with shader graph?
     
  3. ShadyAlien

    ShadyAlien

    Joined:
    Aug 28, 2009
    Posts:
    210
    No, it's an external script based off of the old, old UV scroller script that used to be in the standard assets. Does shadergraph work with the HD render pipeline yet? That would solve all my problems if that were the case.
     
  4. hippocoder

    hippocoder

    Digital Ape

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    Yeah if you use package manager it automatically downloads behind the scenes. Just right click and create a new pbr shader and off you go.
     
  5. ShadyAlien

    ShadyAlien

    Joined:
    Aug 28, 2009
    Posts:
    210
    I haven't been able to get shader graph to work with the HD pipeline. I'm using Unity 2018.1 and anything I create in it shows up as pink (somewhere I read it was compatible with the HD pipeline in the 2018.2 beta but haven't been able to find that again, is this true?).

    However, I found the property I was looking for in my uv scroller script: _BaseColorMap. Scrolling that does the trick, at least until I can get shader graph working.


    Update: I installed the latest beta and everything works with shadergraph. Neat!
     
    Last edited: Jun 30, 2018
  6. Flindt

    Flindt

    Joined:
    Dec 28, 2016
    Posts:
    78
    @Ramandu - can you share what you wrote to actually offset the _BaseColorMap texture? Thanks a lot!
     
  7. ShadyAlien

    ShadyAlien

    Joined:
    Aug 28, 2009
    Posts:
    210
    Code (CSharp):
    1. public class CustomUVScroller : MonoBehaviour {
    2.     public int materialIndex = 0;
    3.     public Vector2 uvAnimationRate = new Vector2( 1.0f, 0.0f );
    4.     public string textureName = "_BaseColorMap";
    5.     public Renderer render;
    6.     Vector2 uvOffset = Vector2.zero;
    7.     void Update()
    8.     {
    9.         uvOffset = ( uvAnimationRate * Time.time );
    10.         if( render.enabled )
    11.         {
    12.             render.materials[ materialIndex ].SetTextureOffset( textureName, uvOffset );
    13.         }
    14.     }
    15. }
    I would recommend implementing a UV scroller in Shader Graph (or Amplify Shader Editor) instead, though, as that's a much more versatile (and better performing) solution. I no longer use the code above for that reason; it was merely a workaround until I got Shader Graph up and running.
     
  8. Flindt

    Flindt

    Joined:
    Dec 28, 2016
    Posts:
    78
    Thanks a lot. I will work on the shader graph also - i actually thought that it was not more optimized to use shader graph - compared to using the lit shader... - but that is great - because the shader graph is much more fun.