Uploaded May 2026 | Updated September 2026, 6 days ago
In this stream we'll have a look at recent updates, and do a bit of experimenting
Follow me for updates: https://mastodon.gamedev.place/@mux213 https://bsky.app/profile/mux213.bsky.social
Join my discord: discord.gg/E7qT8YPu8a
Consider supporting me by subscribing to my channel or becoming a member if you enjoy the content.
youtube.com/channel/UCrbLJYzJjDf2p-vJC011lYw/join
In this stream we'll have a look at recent updates, and do a bit of experimenting
Follow me for updates: https://mastodon.gamedev.place/@mux213 https://bsky.app/profile/mux213.bsky.social
Join my discord: discord.gg/E7qT8YPu8a
Consider supporting me by subscribing to my channel or becoming a member if you enjoy the content.
youtube.com/channel/UCrbLJYzJjDf2p-vJC011lYw/join


![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)







