camera_depth.shader 558 B

123456789101112131415
  1. shader_type spatial;
  2. render_mode blend_mix,depth_draw_never,depth_test_disable,cull_back,unshaded;
  3. void fragment() {
  4. //depth, I do not know other way to get viewport depth texture in Godot
  5. float depth = texture(DEPTH_TEXTURE, SCREEN_UV).r;
  6. depth = depth * 2.0 - 1.0;
  7. float z = -PROJECTION_MATRIX[3][2] / (depth + PROJECTION_MATRIX[2][2]);
  8. //float x = (SCREEN_UV.x * 2.0 - 1.0) * z / PROJECTION_MATRIX[0][0];
  9. //float y = (SCREEN_UV.y * 2.0 - 1.0) * z / PROJECTION_MATRIX[1][1];
  10. z*=0.1;
  11. depth=1.+z;
  12. depth=1.-clamp(depth,0.,1.);
  13. ALBEDO=vec3(depth);
  14. }