Search Unity

  1. Unity 2019.2 is now released.
    Dismiss Notice

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:
    1
    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!