Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Question Scene Depth to Vertex position not compatible

Discussion in 'Shader Graph' started by Kamikaze31, Mar 29, 2022.

  1. Kamikaze31

    Kamikaze31

    Joined:
    Jul 2, 2020
    Posts:
    6
    Not sure how this is done, but I have a wave (ocean) shader graph and would like to tone down the wave heights when near islands. I'm already using refraction with scene depth to get clear water in shallow water, figured I could use the same scene depth to tone down my waves but the scene depth node isn't compatible with the vertex position. What do I need to do?
     
  2. SamFZGames

    SamFZGames

    Joined:
    Mar 2, 2014
    Posts:
    52
    Could you get the nodes you used to make the water clearer in shallow areas to divide your values before outputting to vertex position? So like, whatever gradient noise or sine wave or whatever you used for the waves, divide them by that first?
     
  3. Kamikaze31

    Kamikaze31

    Joined:
    Jul 2, 2020
    Posts:
    6

    It doesn't matter where I use the scene depth, if scene depth is used I can't plug the results into vertex position...or maybe I don't understand what your asking
     
  4. SamFZGames

    SamFZGames

    Joined:
    Mar 2, 2014
    Posts:
    52
    Oh I see, actually IIRC the vertex stuff is calculated before depth so they can't be used together, though there might now be an option to change that, see if anybody from Unity weighs in...
     
  5. Kamikaze31

    Kamikaze31

    Joined:
    Jul 2, 2020
    Posts:
    6
    Awesome, thanks for chiming in and the info...i'll wait patiently
     
  6. Qriva

    Qriva

    Joined:
    Jun 30, 2019
    Posts:
    1,108
    If you meant shader graph dev then I don't believe they exist :p

    I have not enough experience with that, so everything I'm gonna say might be completely wrong, but in forward renderer if you enable depth texture and depth priming (or even without it in transparents)? it should be available in theory, so you could use sample texture lod on _CameraDepthTexture for screen position uv and you would get depth. This depth would be raw, so it must be also converted for example to eye space. You must do research in this topic, but Scene Depth Node for sure can't be used in fragment stage.
     
  7. Kamikaze31

    Kamikaze31

    Joined:
    Jul 2, 2020
    Posts:
    6

    Ahh, I didn't know about this, I tried to access the _CameraDepthTexture but you cannot access it directly. You get a redefinition error if you do. Not sure how to access the depth texture via the shader graph, if someone could enlighten me?
     
  8. Qriva

    Qriva

    Joined:
    Jun 30, 2019
    Posts:
    1,108
    Why you get redefinition, create texture graph property and make it not exposed in the inspector.
     
  9. Kamikaze31

    Kamikaze31

    Joined:
    Jul 2, 2020
    Posts:
    6
    Btw, I am working in HDRP but unless I'm doing something wrong, thats the error i'm getting when I assign a property ref ID to _CameraDepthTexture

    upload_2022-3-30_12-16-29.png

    upload_2022-3-30_12-16-57.png
     
  10. Qriva

    Qriva

    Joined:
    Jun 30, 2019
    Posts:
    1,108
    Ah, sorry I have no experience with HDRP shaders.
     
  11. Kamikaze31

    Kamikaze31

    Joined:
    Jul 2, 2020
    Posts:
    6
    :( thxs for the assist though!