Simple Fog In Unity

แชร์
ฝัง
  • เผยแพร่เมื่อ 12 ธ.ค. 2024

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

  • @KevinDrongowskiSmart
    @KevinDrongowskiSmart 2 ปีที่แล้ว +215

    Your channel is a hidden gem.

    • @qscherry4922
      @qscherry4922 2 ปีที่แล้ว +2

      Literally Homie =C

    • @Marc142000
      @Marc142000 ปีที่แล้ว +3

      I just discovered it I'm amazed

  • @KingBobXVI
    @KingBobXVI 2 ปีที่แล้ว +73

    The animations on the cardboard cutout were absolutely top-notch, lol.

  • @luna010
    @luna010 2 ปีที่แล้ว +70

    3:47 slight error, exponential squared fog doesn’t actually reach zero, it just approaches zero faster than non-squared exponential fog.

  • @spore124
    @spore124 2 ปีที่แล้ว +80

    Math sticklers will point out that neither the exponential nor exponential square methods actually reach zero. They approach zero at different rates which, for the case of rounding from floating point numbers, allows the squared function to reach the smallest possible value much more rapidly. The exponential version will also eventually reach that point. Mathematically they're both forever above zero though. From these methods, only linear actually makes it.

    • @Cyberfishofant
      @Cyberfishofant 2 ปีที่แล้ว +3

      you are probably right, but you could just define a very small cutoff

    • @LtPulsar
      @LtPulsar ปีที่แล้ว +6

      @@Cyberfishofant The mathematician in me says that step functions are for cowards. The physicist in me says things like "the Dirac delta function is the derivative of the Heaviside step function".

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

      if (fogFactor < 0.00000000001f) {fogFactor = 0.0f;}

  • @obanxMolly1991
    @obanxMolly1991 2 ปีที่แล้ว +14

    Just found this bc I couldnt figure out how to implement some decent looking fog- Really love your video/editing style, have my sub.
    Also: Nice choice of music, I see you are a man of culture

    • @Acerola_t
      @Acerola_t  2 ปีที่แล้ว +2

      Thanks so much!

  • @xanderlinhares
    @xanderlinhares ปีที่แล้ว +5

    After learning about what gets drawn to the camera depth texture problem you describe, I thought “why not just get access to the actual depth buffer”. Serious rabbit hole but it turns out that it is possible. You just have to set the render target data with your own buffers (and maybe blit a copy before it gets cleared). That should give you access to your grass depth.

    • @Acerola_t
      @Acerola_t  ปีที่แล้ว +5

      Yeah I figured this out about a year later it was nearly impossible to figure out how to properly generate your own depth tex with Unity's API since no one has ever asked the question and whoever does never gets a response lol
      But yes you're right! It's possible and it's pretty great.

  • @candygonemad
    @candygonemad 2 ปีที่แล้ว +6

    For people who are using URP and struggling
    I was following along with the source code provided, however I realized after I made it all, that this doesn't work in URP. I finally got it working, and I used these sources to get there:
    Ned Makes Games's "Intro to Render Features Unity URP" tutorial on how to make a desaturate effect
    SamDriver's blog on Scriptable Render Features
    CyanGameDev's blog on shader terminology because this was my first shader
    I also converted the shader code into a shader graph myself.
    URP is very different in its architecture for shaders and rendering compared to whats shown in this video. In fact I believe that render features are not a thing in the standard render pipeline? Might be wrong about that.
    Hope this helps people.

    • @candygonemad
      @candygonemad 2 ปีที่แล้ว +2

      For example the OnRenderImage is not used, I set the materials properties (for the shader) in the Execute method of the render pass
      Also Graphics Blit is not used, rather the Blit method can be called and you pass in a CommandBuffer.
      From the Ned Makes Games video, he has a line thats like m_ScriptablePass renderPassEvent = RenderPassEvent something.
      To make it appear on the skybox set it equal to RenderPassEvent AfterRenderingSkybox.
      (cant add dots because scam protection)

    • @Acerola_t
      @Acerola_t  2 ปีที่แล้ว +4

      Yeah this is why I use the built in pipeline, URP doesnt feel production ready lol

    • @candygonemad
      @candygonemad 2 ปีที่แล้ว +3

      @@Acerola_t it's tough because there are some very useful things that come with URP that I would hate to live without, especially on the 2d side, such as the 2d lights. But when documentation for some stuff sparse it really hurts to use URP

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

      I've got everything else but the shader graph working now. Which nodes do I need to use to get the distance of objects to the camera?

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

      @@wasdMash you can use the scene south node if you are just wanting the depth pass, or if you want like actual positions, your can get the world position of the object and then create a vector 3 variable that you can set to be the camera position in a script. Then use the distance node with those two

  • @ObviousDev
    @ObviousDev 2 ปีที่แล้ว +3

    Just discovered your channel and it's been a blast watching through all your tech art related videos so far. Really good stuff! I love educational but also entertaining content. Keep it up

  • @vylax836
    @vylax836 2 ปีที่แล้ว +3

    this is gold, Great video !

  • @bartholemumk1437
    @bartholemumk1437 2 ปีที่แล้ว +9

    thicc fog incoming in 2022

  • @putala
    @putala 26 วันที่ผ่านมา +1

    Hi, is there any way to use Fog in a VR project in URP? I'm trying your solution, but this only works for SRP.

  • @MarcosPS8
    @MarcosPS8 2 ปีที่แล้ว +17

    Greetings Acerola! I'm game artist and I wanted to let you know that I really find so so interesting your videos. They are totally amazing and helped me understand some mistakes I've been seeing during my career. I just wanted to ask you if you plan to make soon more complex videos about art/optimization in Unity/Unreal. Also, if possible, I'll like to learn (if you know some titles/webpages) from some free/paid mid/advanced tutorials/resources about art in games, optimization, engines, shaders... Thank you in advance, you are awesome! 🌻

    • @Acerola_t
      @Acerola_t  2 ปีที่แล้ว +11

      Yeah! As time goes on I'll make more complex videos, got to talk about the simple stuff first.
      The only tutorial series I really recommend is catlikecoding, which ranges from beginner to advanced.

  • @efenty6235
    @efenty6235 2 ปีที่แล้ว +13

    "not computationally feasible"
    ⠀⠀⠀⠀⠀⠀⠀⣠⡀⠀⠀⠀⠀⠀⠀⠀⠀⢰⠤⠤⣄⣀⡀⠀⠀⠀⠀⠀⠀⠀
    ⠀⠀⠀⠀⠀⢀⣾⣟⠳⢦⡀⠀⠀⠀⠀⠀⠀⢸⠀⠀⠀⠀⠉⠉⠉⠉⠉⠒⣲⡄
    ⠀⠀⠀⠀⠀⣿⣿⣿⡇⡇⡱⠲⢤⣀⠀⠀⠀⢸⠀⠀⠀1984⠀⣠⠴⠊⢹⠁
    ⠀⠀⠀⠀⠀⠘⢻⠓⠀⠉⣥⣀⣠⠞⠀⠀⠀⢸⠀⠀⠀⠀⢀⡴⠋⠀⠀⠀⢸⠀
    ⠀⠀⠀⠀⢀⣀⡾⣄⠀⠀⢳⠀⠀⠀⠀⠀⠀⢸⢠⡄⢀⡴⠁⠀⠀⠀⠀⠀⡞⠀
    ⠀⠀⠀⣠⢎⡉⢦⡀⠀⠀⡸⠀⠀⠀⠀⠀⢀⡼⣣⠧⡼⠀⠀⠀⠀⠀⠀⢠⠇⠀
    ⠀⢀⡔⠁⠀⠙⠢⢭⣢⡚⢣⠀⠀⠀⠀⠀⢀⣇⠁⢸⠁⠀⠀⠀⠀⠀⠀⢸⠀⠀
    ⠀⡞⠀⠀⠀⠀⠀⠀⠈⢫⡉⠀⠀⠀⠀⢠⢮⠈⡦⠋⠀⠀⠀⠀⠀⠀⠀⣸⠀⠀
    ⢀⠇⠀⠀⠀⠀⠀⠀⠀⠀⠙⢦⡀⣀⡴⠃⠀⡷⡇⢀⡴⠋⠉⠉⠙⠓⠒⠃⠀⠀
    ⢸⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠈⠁⠀⠀⡼⠀⣷⠋⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
    ⡞⠀⠀⠀⠀⠀⠀⠀⣄⠀⠀⠀⠀⠀⠀⡰⠁⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
    ⢧⠀⠀⠀⠀⠀⠀⠀⠈⠣⣀⠀⠀⡰⠋⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀

    • @Acerola_t
      @Acerola_t  2 ปีที่แล้ว +6

      This is the funniest comment I've received thanks

  • @RetroMMO
    @RetroMMO 2 ปีที่แล้ว +8

    nice grass at 4:03 you should make a video about grass some time

    • @Acerola_t
      @Acerola_t  2 ปีที่แล้ว +3

      That's a great idea ty

  • @felixisntmyname
    @felixisntmyname 2 ปีที่แล้ว +2

    It's the best video about fog out there

  • @Soundy777
    @Soundy777 2 ปีที่แล้ว +6

    Loving this content! More please

    • @Acerola_t
      @Acerola_t  2 ปีที่แล้ว +4

      Thanks! new vids every 2 weeks :)

  • @Luiz-iy5ci
    @Luiz-iy5ci 2 ปีที่แล้ว +1

    I'm a computer science student and thanks to your videos I'm now understanding why I've to study so much math, thx man 🤯🤯

  • @JohnnyOlBoy
    @JohnnyOlBoy ปีที่แล้ว +3

    in unity go to window> rendering> environment and turn on fog

    • @Acerola_t
      @Acerola_t  ปีที่แล้ว +4

      that's crazy man this is about how that fog actually works tho

    • @JohnnyOlBoy
      @JohnnyOlBoy ปีที่แล้ว

      @@Acerola_t yeah i know I was just kidding

  • @t0xangames207
    @t0xangames207 ปีที่แล้ว +1

    Thanks for shader and code❤

  • @TheBreadPirate
    @TheBreadPirate 11 หลายเดือนก่อน

    Grass and fog are cool.

  • @nguyenhoangminhtrung2779
    @nguyenhoangminhtrung2779 2 ปีที่แล้ว

    Thank you, I slowly knows more now!

  • @csxcatgirl9896
    @csxcatgirl9896 2 ปีที่แล้ว +4

    1. grass
    2. fog
    3. ???
    4. PROFIT

  • @xXBlackWorkXx
    @xXBlackWorkXx 2 ปีที่แล้ว +4

    Dude, I just found your Video and it’s literally the exact fog like fog I need for my project. Is it possible that you could upload your project / fog files for download? I tried to understand your video and copy it but I am just not talented enough for „coding“ this kind of stuff…

    • @Acerola_t
      @Acerola_t  2 ปีที่แล้ว +3

      The reference code is in the description! It's for Unity's built in pipeline though unfortunately.

    • @xXBlackWorkXx
      @xXBlackWorkXx 2 ปีที่แล้ว +2

      @@Acerola_t yes I saw that! But yesterday the link was another one, or am I getting crazy?😂 now there are the files, thank you very much! I like your editing style for such videos. But what did you mean exactly by saying „it’s for unitys built in pipeline“, is that a bad thing?

    • @PotatosDispenser
      @PotatosDispenser 2 ปีที่แล้ว +3

      @@xXBlackWorkXx If you don't know about it, it should not be a problem. Unity allows devs to specify how the graphics should be rendered. There are 4 modes : Built-in, URP, HDRP and Custom. It changes how lights and shaders work (among other stuff). So a shader written for built-in pipeline will not work if your project is setup with URP or others.
      By default, Unity Projects use built-in pipeline, so if you did not modify the graphics settings, this fog shader should work for you.

    • @Acerola_t
      @Acerola_t  2 ปีที่แล้ว +4

      @@xXBlackWorkXx The fog shader files were in the old link but I changed it to the exact link after you commented lol
      Unity has several rendering pipelines, I like to use the built-in pipeline while others like to use URP or HDRP. It's not a bad thing, writing shaders for URP/HDRP is a bit different though but the concepts remain the same.

  • @Sky-iv8zm
    @Sky-iv8zm 2 ปีที่แล้ว +1

    would absolutely love this video but for HDRP/URP using shadergraph or Amplify shader editor.
    Built-in has been on bug-fixes only for a few years now

    • @Acerola_t
      @Acerola_t  2 ปีที่แล้ว +3

      The same concepts apply, I enjoy writing shader code over node based shader authoring so my videos will continue to be focused on that.

  • @davidj_bergman
    @davidj_bergman 2 ปีที่แล้ว

    I love the vibe in this video! But unfortunately I still have no clue how to use this new knowledge...

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

    How much does the standard Unity fog impact performance for mobile games?

  • @puntangerslx2772
    @puntangerslx2772 8 หลายเดือนก่อน +1

    fog cannot convert from shader to UnityEngine.shader

  • @rudyramadhana4127
    @rudyramadhana4127 2 ปีที่แล้ว

    persona 3 dorm vibes lets gooooo

  • @TheRealGameCompany
    @TheRealGameCompany 2 ปีที่แล้ว

    So Ive been working on this fog problem for a while, which rendering pipeline did you use for this, i couldnt get your script and shader working in urp

    • @Acerola_t
      @Acerola_t  2 ปีที่แล้ว

      it's for built in so not compatible with urp

  • @Aragubas
    @Aragubas 2 ปีที่แล้ว +4

    I wonder if that's applicable for Godot Game Engine

    • @Acerola_t
      @Acerola_t  2 ปีที่แล้ว +5

      The theory is universal

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

    Is there any good reason to not use unity’s built in fog system though?

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

      there is plenty of value in having your own extendable system, also if you write any of your own shaders they are incompatible with unity's fog system unless you use their fog shader functions which good luck finding info for

  • @ShwetaSharma-su3il
    @ShwetaSharma-su3il ปีที่แล้ว

    Hi I want to apply blit fog effects to a specific object not on the whole screen how can i do that?

    • @Acerola_t
      @Acerola_t  ปีที่แล้ว

      do it in the fragment shader as i demonstrated

    • @ShwetaSharma-su3il
      @ShwetaSharma-su3il ปีที่แล้ว

      @@Acerola_t I want to apply fog on object only.

  • @Tenzordk
    @Tenzordk 2 ปีที่แล้ว

    Was wanting to add this to my small VR project, but sadly cannot be used without some fiddeling.. And I am not up to the task :D

    • @Acerola_t
      @Acerola_t  2 ปีที่แล้ว +1

      I mean, this is about as simple as post processing shaders get, but I understand!

    • @Tenzordk
      @Tenzordk 2 ปีที่แล้ว

      @@Acerola_t I just have not looked at shader.. As in at all 😊

  • @kirillbrodski
    @kirillbrodski 2 ปีที่แล้ว

    Heya bud, just dropping in to say great vid and channel. Hope you can take a break and focus on your mental health. Looking forward to crediting you and your content when my megahit game releases!

  • @Reca-x3y
    @Reca-x3y 5 หลายเดือนก่อน

    What "volumetric fog" means?

  • @CaveJohnson376
    @CaveJohnson376 ปีที่แล้ว +2

    welp, the way unity does depth processing is indeed cringe. for comparison, godot does shadowcasting passes only if they are actually needed and, furthermore, you can make it so certain selected objects don't cast shadows at all. oh, and all the opaque objects are rendered in same pass, and all of them write depth values to depth texture, without requiring to write separate shader function for shadowcasting pass. all simple, nice and easy.

    • @Acerola_t
      @Acerola_t  ปีที่แล้ว

      That's cool, Unity also does all of those things!

  • @JustSomeGameDev
    @JustSomeGameDev ปีที่แล้ว

    my depression 😭💀

  • @Lam0rak
    @Lam0rak 2 ปีที่แล้ว

    As an Unreal dev this video is archaic

    • @Acerola_t
      @Acerola_t  2 ปีที่แล้ว +4

      unity has fog built in, this isn't really a video about engine specific implementations rather how a simple distance fog shader would work regardless of engine.

  • @Jamesfart123
    @Jamesfart123 2 ปีที่แล้ว

    acerola are you ok?