Godot 3D Shader Tutorial (2) : Using the depth buffer

Описание к видео Godot 3D Shader Tutorial (2) : Using the depth buffer

In this video we'll 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/...

Beers law:
https://en.wikipedia.org/wiki/Beer%E2...

Just for completeness (note I'm 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/shade...

Playlist:
   • Godot Shader Tutorial (1): Intro to S...  

Follow me on twitter:
  / mux213  

Комментарии

Информация по комментариям в разработке