Unity Shader Graph Basics (Part 4 - The Depth Buffer)

แชร์
ฝัง
  • เผยแพร่เมื่อ 8 พ.ย. 2024
  • เกม

ความคิดเห็น • 28

  • @danielilett
    @danielilett  10 หลายเดือนก่อน +8

    A longer explanation of how the depth buffer actually stores values, since I cut a very long explanation of what the "non-linear relationship" is from the video, paraphrased from my shader book:
    Unity calculates the distance of a pixel from the camera, which we can call its z-value, hence "z-buffer". This value is between the near and far clip distances of your camera, because those are the minimum and maximum distances that actually get rendered.
    This z-value is changed into a depth value that we can store in the depth buffer by transforming the [near, far] range to a [0, 1] range. The depth buffer stores floating-point numbers between 0 and 1.
    If this mapping were linear, we could run into precision issues with close objects. Especially for small objects close together, we could feasibly end up with errors where objects end up rendered in the wrong order.
    To avoid that, we want to use as much precision as possible to represent close objects. The exact formula that is used for converting the z-value to a depth value is:
    depth = ( 1/z - 1/near ) / ( 1/far - 1/near )
    What you end up with is a curve. For the default Unity camera values where near = 0.3 and far = 1000, 70% of all information stored in the depth buffer represents objects up to a distance of one meter from the camera. Which is amazing when you consider the remaining 30% represents the other 999 meters!
    As mentioned in the video, those depth buffer values get copied to the depth texture, and then Shader Graph gives you the tools to decode this curve into two linear formats (Linear01, where values are linearized in the same 0-1 range, and Eye where values are just the original z-values - distances from the camera - that we started with).
    Hope that gives a bit more context!

  • @拉拉菲尔
    @拉拉菲尔 27 วันที่ผ่านมา +1

    Wow, this is the best introductory video I've ever seen, and it's for the latest version of Unity. It was a huge help. I sincerely hope you can keep updating.🥰

  • @semiterrestrial
    @semiterrestrial 10 หลายเดือนก่อน +3

    Great explanation, hope you keep making this series!

  • @richardaen4195
    @richardaen4195 10 หลายเดือนก่อน +2

    Such a brilliant and helpful series. Great stuff Daniel. (Not least because that 3 sec lerp explanation was the best and most concise i've seen)

    • @danielilett
      @danielilett  10 หลายเดือนก่อน

      Glad you liked the lerp explanation, I almost didn't even include it in the video! Sometimes it's pretty tricky to strike a balance between being concise and including all of the context.

  • @usercontent2112
    @usercontent2112 10 หลายเดือนก่อน +2

    Thank you, this series is helping me a lot to understand shader graph

  • @antonovivan3008
    @antonovivan3008 10 หลายเดือนก่อน +1

    Thank you. I've learned exactly what I was looking for last few days.

  • @christianschneider8516
    @christianschneider8516 10 หลายเดือนก่อน +1

    Once again nicely explained, thank you so much !

  • @ripmork
    @ripmork 2 หลายเดือนก่อน

    Great explanations of basics in your videos, thank you!

  • @lpfonseca
    @lpfonseca 10 หลายเดือนก่อน +1

    Great work! Looking forward for the vertex shader

  • @FarwalDev
    @FarwalDev 10 หลายเดือนก่อน +3

    These videos are helping me to better understand the ShaderGraphs, thx❤️

  • @dopinkus
    @dopinkus 10 หลายเดือนก่อน +1

    Like #100! Your tutorials are absolutely amazing. Please please keep going :)

  • @raysiberian4346
    @raysiberian4346 4 หลายเดือนก่อน

    Thx, pure gold explanation.

  • @Henry3dev
    @Henry3dev 10 หลายเดือนก่อน +1

    loving it thanks

  • @StressedProgrammer
    @StressedProgrammer 3 หลายเดือนก่อน

    Thanks for the tutorial, can i do this in Built In Pipeline?

  • @reedshingledecker3173
    @reedshingledecker3173 19 ชั่วโมงที่ผ่านมา

    Unreal has a pixel depth and scene depth node while Unity seems to only have scene depth. Would you know how to get the pixel depth?

  • @GameBit697
    @GameBit697 4 หลายเดือนก่อน

    What about hairs in URP, will it work for the same or could you cover "Hairs in URP" topic?

  • @hughCho-u9k
    @hughCho-u9k 9 หลายเดือนก่อน

    좋은 이야기 잘듣고 가요~~

  • @AlexLozanoAcerca
    @AlexLozanoAcerca 3 หลายเดือนก่อน

    Hi Daniel! I have a question. I dont know why, but, "Depth test 2:44 " only works for me if "Surface Type" is Transparent. I don't understand why it doesn't work when is opaque, like you

  • @rockclimbermaca
    @rockclimbermaca 8 หลายเดือนก่อน

    Thanks for this tutorial, it's awesome! I just have one tiny question: if I have a second camera in my scene that renders the scene to a RenderTexture with a Color Format of R8G8B8A8_UNORM and a Depth Stencil Format of D32_SFLOAT, and I pass that RenderTexture to a URP Shader Graph as a Texture2D, is there a way to read the depth values from the RenderTexture in the graph? I believe it is not possible, but just wanted to confirm. It's very odd, but it seems like it's impossible :(

  • @LuizMoratelli
    @LuizMoratelli 2 หลายเดือนก่อน

    I have this problem, that with a Canvas Group and some GO with Images, the images on top get transparent and the color of images behind mix with the color on front giving a bad result, there is a good way to fix it? I tried with stencil, but then the aliasing scream at your face haha.

  • @DaveRune
    @DaveRune 2 หลายเดือนก่อน

    Is there a way to sample a pixel of the depth texture here?

  • @anttiv7109
    @anttiv7109 6 หลายเดือนก่อน +1

    Has this been changed in Unity 6 or am I just blind? Cannot find Depth Texture setting.

    • @danielilett
      @danielilett  6 หลายเดือนก่อน +3

      Do you mean the part about 5 minutes in where you have to find the tickbox? I just checked out a new Unity 6 project and it looks like it's in basically the same place for me.
      If you started with a brand new Unity 6 URP project then your Assets folder should contain another folder called Settings. In there, there are a bunch of weird looking assets. You're looking for the ones named either "Mobile_RPAsset" or "PC_RPAsset". These are both Render Pipeline Assets which basically hold together a lot of URP's settings. The Depth Texture tickbox should be right at the top of the Inspector when you click on them.
      If you're still using 2022.3 or versions before that, then it's basically the same process except the assets you're looking for are called "UniversalRP-HighQuality", "UniversalRP-LowQuality", and "UniversalRP-MediumQuality".
      If you don't see what I'm seeing in Unity 6 then I'm not sure what's up and honestly maybe Unity just changed something randomly in one of the Unity 6 releases so far. They like doing that. For avoidance of doubt I'm using 6.0.0b11.

  • @nopepsi206
    @nopepsi206 9 หลายเดือนก่อน +1

    When is the next part going to release?

    • @danielilett
      @danielilett  9 หลายเดือนก่อน

      Not sure yet. I am working on the next part, but I also have a couple of other videos in production right now that are closer to completion. The next part will likely be sometime in February, but I hope it's towards the start.

    • @markroacing8237
      @markroacing8237 9 หลายเดือนก่อน

      And how many part it have?@@danielilett

  • @harshadjoshi3944
    @harshadjoshi3944 10 หลายเดือนก่อน

    Can you show this with Shadergraph in Built In Render Pipeline.