Search Unity

  1. If you have experience with import & exporting custom (.unitypackage) packages, please help complete a survey (open until May 15, 2024).
    Dismiss Notice
  2. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice

Question Skybox clearing or Writing depth in a Shader Graph

Discussion in 'Universal Render Pipeline' started by Jesus, Apr 20, 2024.

  1. Jesus

    Jesus

    Joined:
    Jul 12, 2010
    Posts:
    504
    Info: Unity 2023.2.11f1, URP 16.0.5 (copied to local Packages folder).

    I'm looking to write in a shader graph. This will be an unlit shader graph suitable for skybox rendering (and assigned as skybox in the Light/Environment tab. However, if a general solution is available, that'd be great.

    The camera has a massive (0.01 near plane, >1e16 far plane) view frustum that can't really be changed.
    On some cards, the result is flicking skybox, like it's not clearing itself or auto-failing the depth test. Looks like when you win at solitaire.

    background fail.png Note that in this second pic, the camera is looking to the left in the scene view, so it should be seeing the green of the background skybox.
    camera is amiling to the left.png


    At this range, shader graph vertex position precision does kinda break down.

    For example, plugging a Position node into the Vertex Position slot (both Object space) works fine. Doing ANYTHING to that position value, even transforming it from Object to Object space, which in theory should do nothing, can break things horribly. Best case scenario, skybox goes black. This kinda rules out vertex transforms as part of the solution I think?

    Is there a custom function script that can 'inject' some depth information? ie:

    // output depth

    #if UNITY_REVERSED_Z
    OUT.depth = 0;
    #else
    OUT.depth = 1;
    #endif

    Or is there another solution here?