Search Unity

Question UV Scrolling Shader Fails to Update UVs in Game View in Edit Mode

Discussion in 'General Graphics' started by PostMordernFragments, Jan 18, 2023.

  1. PostMordernFragments

    PostMordernFragments

    Joined:
    Sep 4, 2015
    Posts:
    3
    Hi, I created a lit shader graph with a simple UV scrolling function. The shader works fine in the scene view. But I found the texture doesn't scroll in the game view in edit mode. It only works in play mode for game view. It seems the shader graph itself is correct. I am using unity2021.3.14 and HDRP. Is there any way to refresh shader UVs in game view without entering play mode? Thanks!
     

    Attached Files:

  2. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,352
    No. Time doesn't advance in the game view unless you're in play mode. This is working as intended.
     
  3. PostMordernFragments

    PostMordernFragments

    Joined:
    Sep 4, 2015
    Posts:
    3
    Thank you very much! Yeah, it seems that's the case in HDRP. I tested a UV scrolling shader in URP and found that it could update in game view.

    And in HDRP, I created a shader as follows. _Time works again without play mode in game view. I am kind of confused.

    Shader "Unlit/Test"
    {
    Properties
    {
    _MainTex ("Texture", 2D) = "white" {}
    _Factor("Factor",Vector) = (1,1,0,0)
    }
    SubShader
    {
    Tags { "RenderType"="Opaque" }
    LOD 100

    Pass
    {
    CGPROGRAM
    #pragma vertex vert
    #pragma fragment frag

    #include "UnityCG.cginc"

    struct appdata
    {
    float4 vertex : POSITION;
    float2 uv : TEXCOORD0;
    };

    struct v2f
    {
    float2 uv : TEXCOORD0;
    float4 vertex : SV_POSITION;
    };

    sampler2D _MainTex;
    float4 _MainTex_ST;
    float4 _Factor;

    v2f vert (appdata v)
    {
    v2f o;
    o.vertex = UnityObjectToClipPos(v.vertex);
    o.uv = TRANSFORM_TEX(v.uv , _MainTex) + _Time.gg *_Factor.xy;
    return o;
    }

    fixed4 frag (v2f i) : SV_Target
    {
    fixed4 col = tex2D(_MainTex, i.uv);
    return col;
    }
    ENDCG
    }
    }
    }
     
  4. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,352
    The fact it works in the URP is a bug.
     
    PostMordernFragments likes this.
  5. PostMordernFragments

    PostMordernFragments

    Joined:
    Sep 4, 2015
    Posts:
    3
    Got it. Thanks again;)!
     
  6. TYTY_UNIT

    TYTY_UNIT

    Joined:
    Aug 19, 2023
    Posts:
    1

    If you check this option, you can preview it in scene view.
     

    Attached Files:

    nzhul likes this.
  7. nzhul

    nzhul

    Joined:
    Apr 29, 2015
    Posts:
    4
    Thank you very much!
    This is working for me!