Uploaded July 2020 | Updated September 2026, 1 week ago
We started this stream an hour earlier, let me know in the comments if this time works as I may change the streams to this time from now on.
Tonight we started with a recap of the changes, sorry that the first few minutes I had forgotten to switch to the screen captured view so you may want to fast forward to about 9 minutes into the video.
We look at the shield system and the changes so we can actually destroy the ships.
Then we implemented a simple missile that we could fire, first just flying in a straight line and after that adding a simple AI that attempts to steer the missile to its target. We had to go through a few attempts before getting a good result.
We started this stream an hour earlier, let me know in the comments if this time works as I may change the streams to this time from now on.
Tonight we started with a recap of the changes, sorry that the first few minutes I had forgotten to switch to the screen captured view so you may want to fast forward to about 9 minutes into the video.
We look at the shield system and the changes so we can actually destroy the ships.
Then we implemented a simple missile that we could fire, first just flying in a straight line and after that adding a simple AI that attempts to steer the missile to its target. We had to go through a few attempts before getting a good result.

![Godot 3D Shader Tutorial (2) : Using the depth buffer
In this video well have a look at how we can use the depth buffer to find out how much distance there is between the surface of the water and the walls of the pool behind it. Then we use that to darken the water the higher that distance is.
Info about reconstructing positions from depth buffer:
http://www.derschmale.com/2014/01/26/reconstructing-positions-from-the-depth-buffer/
Beers law:
https://en.wikipedia.org/wiki/Beer%E2%80%93Lambert_law
Just for completeness (note Im leaving z as negative):
float depth = texture(DEPTH_TEXTURE, SCREEN_UV).r;
depth = depth * 2.0 - 1.0;
float z = -PROJECTION_MATRIX[3][2] / (depth + PROJECTION_MATRIX[2][2]);
float x = (SCREEN_UV.x * 2.0 - 1.0) * z / PROJECTION_MATRIX[0][0];
float y = (SCREEN_UV.y * 2.0 - 1.0) * z / PROJECTION_MATRIX[1][1];
or alternatively:
float depth = texture(DEPTH_TEXTURE, SCREEN_UV).r;
vec4 unproject = INV_PROJECTION_MATRIX * vec4(SCREEN_UV * 2.0 - 1.0, depth * 2.0 - 1.0, 1.0);
vec3 view_vertex = unproject.xyz / unproject.w;
Source code on github:
https://github.com/BastiaanOlij/shader_tutorial
Playlist:
https://www.youtube.com/watch?v=xoyk_A0RSpI&list=PLhqJJNjsQ7KHqNMYmTwtsYTeTrqrRP_fP
Follow me on twitter:
https://twitter.com/mux213 Godot 3D Shader Tutorial (2) : Using the depth buffer](https://i.ytimg.com/vi/Jq3he9Lbj7M/mqdefault.jpg)








