Colored Tunnel Shader

A shader to produce the effect of objects disapearing into a solid color/ portal.

Shader code
shader_type spatial;
render_mode unshaded;

uniform sampler2D depth_texture : hint_depth_texture;

uniform vec3 color : source_color;
uniform float hole_depth : hint_range(0.1, 10.0, 0.1) = 1.0;

void fragment() {
	// sample our depth buffer
	float depth = texture(depth_texture, SCREEN_UV).r;
	
	float linear_depth = 1.0 / (depth * INV_PROJECTION_MATRIX[2].w + INV_PROJECTION_MATRIX[3].w);
	
	linear_depth = linear_depth + VERTEX.z;
	
	ALBEDO = color;
	
	ALPHA = 1.-clamp(1.-(linear_depth / hole_depth), 0., 1.);
}
Live Preview
Tags
colorhole portal depth hole
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 ShulkerShader

Related shaders

guest

0 Comments
Oldest
Newest Most Voted