Planet atmospheres, ray-sphere intersections.

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

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

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

    excellent video, it reminded me of coding adventure at first but your explanation of the ray-sphere intersection is really clear! thanks!

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

      Thanks! I love Sebastian's videos. Full of great info.

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

      @@MartinDonald not sure if it would be in your interest, but i am currently struggling with cone/cylinder intersections for my ray tracer, so if you ever get ideas for videos about rays and intersections i have your bell turned on ;-)

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

    I'm currently programming a procedural solar system and was looking for approaches for the atmo. And instead I find this. In Godot no less. Just bought you a pint on patreon. Thank you man.

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

      Thank you very much! Really appreciated :)

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

      I implemented this and had an odd issue. When looking directly down toward the planet there's a completely unshaded square front and centre between the camera and the planet. When looking side on I've got a nice atmo so I'm not far from the answer hopefully. I've literally just copied the shader so far and haven't gone through it properly yet but I was wondering if you have any ideas where I'm going wrong?
      EDIT: missed your reply, oh you're very welcome! I'm grateful to you for doing this, it's exactly what I needed explained in beautiful detail.

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

      @@MartinDonald This is bizarre. I thought it might be the camera as mine has gimbals and zooms and all sorts so I added a new vanilla one and made that current. Same bug. Thought it might be my implementation of the shader (I'm instancing the meshes procedurally in code including the CubeMesh), so I did it that way on a fresh scene and that worked perfectly, no weird box, just not on my actual project...
      So it's not the shader code and it's not the camera. Grr. It's the same whether you're above the atmo or below, so it's not the neg culling. It's just like there's a "so not shade here" plane a metre from the camera...
      What else could it possibly be?

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

      @@davidmurphy563 hmm sorry, I'm not sure what the problem could be, if you're rendering to a mesh cube as I do in the video then perhaps your sphere radius is too large and it's clipping with the cube? Since you're a patron you can also download my project files for this video and see if there are any clues in there 🔍

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

      @@MartinDonald Yeah, I'm baffled by it too. Like I say, I got it going perfectly on another quick mockup project, just not my game... My radius is 10k but the CubeMesh is bigger and anyway, it's the opposite of that: the unshaded diamond shaped region is on the local -y axis between the camera and the world. Just like if there were an unshading plane as a child of the camera positioned on a tangent in the direction of the world removing the shade. There isn't such a plane obvs, that's just how it looks.
      Very frustrating. Anyway, sorry to pester, I'll keep plugging away. I'll try deleting the shader and making a new one, see if that fixes it.

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

    brother this is amazing, I remember watching Sebastian lague's atmosphere video and having no idea where to start, this seems like a much more manageable approach, and you explained it wonderfully

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

    Great video! Good to see more people doing shaders for Godot. From there it's not a big step towards clouds and atmospherics. I went this entire pathway inside of shadertoy. ^^

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

    Realy Realy good tutorial tysm. I will use this to try to find the position where the second buggy of a train wagon should be on a path (the train tracks in this case)

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

    Really good, high-quality video!

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

    It looks like the atmosphere has the same density at all heights, until it cuts off at some point. Maybe the easiest hacky way of making it look like the atmosphere thins out at higher altitudes; is to not just look at the thickness ΔT, but first raise it to some power. So thickness = c * ΔT ^ e.

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

    These videos are really helping me study for the graphics exam I'm trying to procrastinate on. Damn you Martin!

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

    Outer Wilds was the best game I’ve ever played. Whatever you are doing, I need to stay updated!

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

    This is really good, but something that would make it even better is casting the shadow of the planet onto the atmosphere.

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

    That was an amazing explanation, thank you!

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

    Man, it's excellent video, thx!

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

    Brilliant work!

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

    Amazing channel!! this is really necessary for godot!! Sugestion put some tags on video.

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

    this looks like a lot of fun to impliment. Im going to try making it with Unity

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

    Great video, as usual! Can't wait to leave the same comment again and again :)

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

    This is exactly what I'm thinking about lately after watching those video that put GoPro camera on a balloon and let it fly to space.

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

    So... Are you telling me you are the new Sebastian League?

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

    I think I have found where Sebastian Lague gets his ideas from...

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

    i know it has been a while but I am stuck in UE4 trying to decipher what the is equivalent to this line:
    vec4 view = INV_PROJECTION_MATRIX * vec4(ndc, 1.0);
    specifically, what is INV_PROJECTION_MATRIX for hlsl or in ue4 nodes. Great tutorial btw!!!!

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

    im doing a assignment where i gotta write a research on something in games and i chose atmospheres after seeing sebastian lagues one. my specific research is how are modern techniques optimising for realtime apps compared to raw ray marching

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

    hei man, amazing work both at explaining and coding!
    just a question: while calculating the light interaction, i noticed that using a global vector for light direction is not working as I should use the relative direction to camera (otherwise the illuminated area always face the same direction of the screen)
    I would do some math to calculate the relative light direction starting from the global, but i'm a noob with shader and dont know the code the extrapolate the camera direction.
    Since you havent mentioned it in the video, how did you solve it?

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

      Thanks! You're absolutely right, you just need to multiply it by your cam matrix like so: vec4(light_dir.xyz, 1.0) * CAMERA_MATRIX;

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

      @@MartinDonald works wonderfully! thanks a lot!

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

    Adding a sigmoid curve modifier from r=sr to r=2*sr would allow the atmosphere to blend into space

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

    How do you get the sun to light all the planets? I've been having troubles with that in Unity URP because they don't support real time point lights. Is there a better way to make the sun the main light source?

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

    I'm sure you don't have time to answer such a dumb question but I was wondering how did you keep the player upright when on the planet. I've tried a bunch of stuff but once the planet starts moving I cant get anything to work.

    • @MartinDonald
      @MartinDonald  4 ปีที่แล้ว

      Not a dumb question at all! 3D transforms are a nightmare. Check out this page in the godot docs, particularly the part about quaternion rotations at the end: docs.godotengine.org/en/stable/tutorials/3d/using_transforms.html

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

    Works great, only have one issue (th-cam.com/video/OCZTVpfMSys/w-d-xo.html):
    for whatever reason:
    float t2 = min(t+x, max_depth*1.8); //gives accurate looking results
    float t2 = min(t+x, max_depth); //planet still shows up in front

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

    How did you get the atmosphere to render really far away when I do the atmosphere has black rings

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

      This is probably due to the depth buffer becoming less accurate at really long distances. You can try offsetting the depth test in the shader when the planet is really far away? Or maybe you could look into swapping your planet for a simple sprite for seriously long distances.

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

      I suggest increasing the camera near plane when you are far away.

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

    how can you use this im so lost

  • @thelifeoftheepie7643
    @thelifeoftheepie7643 3 ปีที่แล้ว

    How did u get the lit side to properly render? In my case the lit side disappears completely when looking at the unlit side and looks like the color/light is only hitting the very top/surface of the atmosphere and not the inside. How can I fix this?

    • @jpsilver3510
      @jpsilver3510 3 ปีที่แล้ว

      I had the same issue when i tried to render the atmosphere with a sphere, you need to use a cube like he said

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

    Fantastic video - you really helped me grasp this concept so much better than I otherwise would've. I'll give your channel a shout in the credits of our indie game, if it ever releases :)

  • @HarryLarsson-b2n
    @HarryLarsson-b2n 8 วันที่ผ่านมา

    you should decrease the density with altitude

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

    Anyone know what is the equivalent of VIEW in unity?

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

      that worked for me:
      struct v2f
      {
      float2 uv : TEXCOORD0;
      float3 view : TEXCOORD1;
      float4 vertex : SV_POSITION;
      };
      v2f vert (appdata v)
      {
      v2f o;
      o.vertex = UnityObjectToClipPos(v.vertex);
      o.uv = v.uv;
      o.view = mul(unity_ObjectToWorld, v.vertex);
      return o;
      }
      in fragment shader:
      float3 VIEW= normalize(i.view - _WorldSpaceCameraPos);

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

      @@syuta9317 thank you

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

    Godot brand Sebastian Lague

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

    Having trouble when the atmosphere is scaled to large radius values like 600k and above

  • @jpsilver3510
    @jpsilver3510 3 ปีที่แล้ว

    Does anyone know how to sample the depth texture in unity using hdrp?

  • @jpsilver3510
    @jpsilver3510 3 ปีที่แล้ว

    Can you please do this in unity as well?

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

      I probably can't, but I can recommend Sebastian Lague's video on planet atmospheres, which is done in Unity: th-cam.com/video/DxfEbulyFcY/w-d-xo.html

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

      @@MartinDonald thank you! I have seen it but he doesn't really go in too much depth, as far as i know he only mentions the rsi, but thank you for this video. Im really close to getting it in unity hdrp, just having issues with sampling the depth texture. For some reason the screen position does not get interpolated so only the bottom left corner gets all the depth of the entire depth map. Please do keep on keeping on, im loving your videos. I understood this the first time you explained it.

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

    right, I am trying to understand, just trying...

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

    WHY ARE CIRCLES AND SPHERES SO HARD.

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

    You need some work with your variable names. Nobody’s gonna know what “r”, “y”, “ndc”, “depth” (of what?), and “so”