Search Unity

Single Pass Stereo Rendering is not supported by LWRP Terrain shader

Discussion in 'VR' started by kivinm, May 8, 2019.

  1. kivinm

    kivinm

    Joined:
    Apr 5, 2019
    Posts:
    7
    Hi, it seams Unity team forgot to support Single Pass Stereo Rendering for LWRP TerrainLit shader. Other LWRP shaders have it, even some "internal" shaders of Terrain shader (like WavingGrass) have support for Single Pass Stereo.

    If you want to reproduce - use LWRP VR template, put a terrain and any 3D model on scene and run on device - right eye picture will have some kind of "shadow object" behind 3D model in the part where model overlaps terrain (at least on GearVR). Sorry for terminology, I'm totally new to Unity, shaders, 3D modelling etc...

    So I made a fix based on this Unity doc (check Custom shaders section) and code from other Lit shaders inside LWRP package.

    You need to add one line to struct Varyings in TerrainDetailLit.shader file:
    UNITY_VERTEX_INPUT_INSTANCE_ID
    and several lines to file TerrainLitPasses.hlsl:
    1. Two lines to struct Varyings
    UNITY_VERTEX_INPUT_INSTANCE_ID
    UNITY_VERTEX_OUTPUT_STEREO
    2. Two lines
    UNITY_TRANSFER_INSTANCE_ID(v, o);
    UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o);
    to method Varyings SplatmapVert(Attributes v) right after line
    UNITY_SETUP_INSTANCE_ID(v);
    3. Two lines
    UNITY_SETUP_INSTANCE_ID(IN);
    UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(IN);
    in the very beginning of method half4 SplatmapFragment(Varyings IN) : SV_TARGET

    This totally solved the issue for me.
    Attached are modified files for your convenience. Replace corresponding files in <<PathToYourProject>>\Library\PackageCache\com.unity.render-pipelines.lightweight@5.13.0\Shaders\Terrain\ folder.
     

    Attached Files:

  2. KatanaSim

    KatanaSim

    Joined:
    Oct 25, 2009
    Posts:
    105
    Thanks kivinm, that was very helpful!
     
  3. martin-kucer

    martin-kucer

    Joined:
    Sep 29, 2016
    Posts:
    3
    Is there a permanent fix for this issue? Because Libary folder gets regenerated every time Unity is launched and you need to repeat shader replacement process every time....
     
    ROBYER1 likes this.
  4. pdq72

    pdq72

    Joined:
    Sep 29, 2013
    Posts:
    43
    Sort of fixes it. Baked shadows are rendered in one eye, but not the other.
    Anyone know if there is a permanent fix yet?
     
  5. ROBYER1

    ROBYER1

    Joined:
    Oct 9, 2015
    Posts:
    1,454
    Would be interested to see this, never had this issue myself but is worth reporting as a bug
     
  6. KingKRoecks

    KingKRoecks

    Joined:
    Jul 28, 2013
    Posts:
    155
    This is still an issue with the latest 2019.3.0f5 and Universal RP 7.1.7
     
    ROBYER1 likes this.
  7. HQF

    HQF

    Joined:
    Aug 28, 2015
    Posts:
    40
    its fixed in 7.2 version of URP
     
    ROBYER1 likes this.
  8. ROBYER1

    ROBYER1

    Joined:
    Oct 9, 2015
    Posts:
    1,454
    com.unity.render-pipelines.universal\Runtime\Materials\TerrainLit

    ^ that's the one you need when using 7.2
     
    enhawk likes this.