Search Unity

Shader property issue with Single Pass Instanced

Discussion in 'AR/VR (XR) Discussion' started by Kronnect, Dec 12, 2017.

  1. Kronnect

    Kronnect

    Joined:
    Nov 16, 2014
    Posts:
    2,905
    Hi!

    I have a question related to the Single Pass Instanced mode and setting material texture properties.

    I have a property in a shader defined like this:

    _OverlayTex ("Overlay (RGB)", 2D) = "black" {}

    The uniform itself is defined properly as
    UNITY_DECLARE_SCREENSPACE_TEXTURE(_OverlayTex);

    However when going into play mode, I got a console error:
    "Error assigning 2D texture to texarray texture property '_OverlayTex': Dimensions must match"

    It works fine though and if I remove the property declaration (and keep just the uniform), the console error goes away as well. However we prefer to declare the property otherwise Unity loses the reference and the effect when the script gets initialized do not look properly in Editor.

    If a change the property to:

    _OverlayTex ("Overlay (RGB)", 2DArray) = "black" {}

    then it works fine, no errors, but it fails in other VR rendering path non-VR mode.

    So to the question: is there any way to declare a property either 2D or 2DArray so it does not depend on the active VR mode? Thanks.
     
  2. BrandonFogerty

    BrandonFogerty

    Joined:
    Jan 29, 2016
    Posts:
    83
    Hi @Thrawn75!

    You are running into this issue because single-pass instancing uses texture arrays whereas single-pass and multi-pass use a single texture.

    Try the following

    Code (CSharp):
    1. _OverlayTex ("Overlay (RGB)", any) = "" {}
    I hope that helps.
     
    Kronnect likes this.
  3. Kronnect

    Kronnect

    Joined:
    Nov 16, 2014
    Posts:
    2,905
    Yep, helps a lot, it works. Thank you!

    btw, regarding Single Pass Instanced rendering, I have noticed that simple Blit operations between TwoEye flagged render textures do not honour this setting:

    Code (CSharp):
    1. RenderTexture rt1, rt2; // both are TwoEye flagged
    2. Graphics.Blit (r1, rt2); // <-- do not work
    But using a simple vertex/frag shader that uses the appropriate macros for instancing and sampling texture works.
     
  4. jjxtra

    jjxtra

    Joined:
    Aug 30, 2013
    Posts:
    1,464
    Trying to do this on line 40 of a shader. Single pass stereo instanced. multi_compile instanced pragma.

    UNITY_DECLARE_SCREENSPACE_TEXTURE(_ReflectionTex);

    Shader error:

    Shader error in ...: Unexpected token ';'. Expected one of: typedef const void inline uniform nointerpolation extern shared static volatile row_major column_major struct or a user-defined type at line 40

    Any ideas?

    This is Unity 2018.2.2
     
  5. BrandonFogerty

    BrandonFogerty

    Joined:
    Jan 29, 2016
    Posts:
    83
    Hi @Thrawn75,

    The Graphics.Blit() issue is now fixed in 2018.2.
     
    Kronnect likes this.
  6. BrandonFogerty

    BrandonFogerty

    Joined:
    Jan 29, 2016
    Posts:
    83
    Hi @jjxtra,

    Is it possible for you to post your shader? Thanks!