depth to WorldSpacePosition(4.3+)

Get the world 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;
	vec4 worldSpacePosition = INV_VIEW_MATRIX * viewSpacePosition;
	ALBEDO = worldSpacePosition.rgb;
}
Tags
depth, depth_texture, position, position3D, view, view space, world-space
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

3D Pixelart Upscaler/Filter

Post Effect Outline Shader for GLES2

Mesh Blending with Alpha

Related shaders

Linear Depth/Depth Fog

Per object depth-based outline

linear depth (4.3+)

guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments