Player Proximity Invisibility

To use this shader create a global shader in project settings, name it “player_pos” and set it to type vec3. Update the global shader to the player’s position every frame.

If using 3.x change MODEL_MATRIX to WORLD_MATRIX.

This shader will turn objects far away from the player invisible. 


Shader code
shader_type spatial;

uniform vec4 _color : source_color;
uniform float sphere_size = 3.0;
global uniform vec3 player_pos; 

varying vec3 world_vertex;

void vertex ()
	world_vertex = (MODEL_MATRIX * vec4(VERTEX, 1.0)).xyz;

void fragment() {
	float min_dist = min(length(player_pos - world_vertex), sphere_size);
	ALBEDO = _color.rgb;
	ALPHA = clamp(sphere_size - min_dist, 0.0, 1.0);
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.

Inline Feedbacks
View all comments