depth to ViewSpacePosition(4.3+)

Get the view space position from the DEPTH_TEXTURE (4.3+).

Apply this shader to a quad, which is attached to the camera.

 

Shader code
shader_type spatial;
render_mode unshaded, depth_draw_never;

uniform sampler2D DEPTH_TEXTURE: hint_depth_texture;

void fragment() {
	vec4 clipSpacePosition = vec4(SCREEN_UV * 2.0 - 1.0, texture(DEPTH_TEXTURE, SCREEN_UV).r, 1.0);
	vec4 viewSpacePosition = INV_PROJECTION_MATRIX * clipSpacePosition;
	viewSpacePosition /= viewSpacePosition.w;
	ALBEDO = viewSpacePosition.rgb;
}
Tags
depth, depth_texture, position, position3D, view, viewspace
The shader code and all code snippets in this post are under CC0 license and can be used freely without the author's permission. Images and videos, and assets depicted in those, do not fall under this license. For more info, see our License terms.

More from Firerabbit

depth to WorldSpacePosition(4.3+)

Vector Sprite Upscaling Mix Colors

Toon Shader for Godot 4

Related shaders

Linear Depth/Depth Fog

Skyward Sword Pointillism (with depth)

Depth based Tilt-shift

Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments