@@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 ;-)
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.
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.
@@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?
@@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 🔍
@@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.
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
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. ^^
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)
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.
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!!!!
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
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?
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?
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.
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
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
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.
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?
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 :)
@@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.
excellent video, it reminded me of coding adventure at first but your explanation of the ray-sphere intersection is really clear! thanks!
Thanks! I love Sebastian's videos. Full of great info.
@@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 ;-)
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.
Thank you very much! Really appreciated :)
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.
@@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?
@@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 🔍
@@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.
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
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. ^^
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)
Really good, high-quality video!
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.
These videos are really helping me study for the graphics exam I'm trying to procrastinate on. Damn you Martin!
Outer Wilds was the best game I’ve ever played. Whatever you are doing, I need to stay updated!
This is really good, but something that would make it even better is casting the shadow of the planet onto the atmosphere.
That was an amazing explanation, thank you!
Man, it's excellent video, thx!
Brilliant work!
Amazing channel!! this is really necessary for godot!! Sugestion put some tags on video.
this looks like a lot of fun to impliment. Im going to try making it with Unity
Great video, as usual! Can't wait to leave the same comment again and again :)
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.
So... Are you telling me you are the new Sebastian League?
100%
I think I have found where Sebastian Lague gets his ideas from...
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!!!!
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
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?
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;
@@MartinDonald works wonderfully! thanks a lot!
Adding a sigmoid curve modifier from r=sr to r=2*sr would allow the atmosphere to blend into space
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?
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.
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
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
How did you get the atmosphere to render really far away when I do the atmosphere has black rings
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.
I suggest increasing the camera near plane when you are far away.
how can you use this im so lost
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?
I had the same issue when i tried to render the atmosphere with a sphere, you need to use a cube like he said
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 :)
you should decrease the density with altitude
Anyone know what is the equivalent of VIEW in unity?
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);
@@syuta9317 thank you
Godot brand Sebastian Lague
Having trouble when the atmosphere is scaled to large radius values like 600k and above
Does anyone know how to sample the depth texture in unity using hdrp?
Can you please do this in unity as well?
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
@@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.
right, I am trying to understand, just trying...
WHY ARE CIRCLES AND SPHERES SO HARD.
You need some work with your variable names. Nobody’s gonna know what “r”, “y”, “ndc”, “depth” (of what?), and “so”