0 votes


I try to achieve the following effect :

I have a 3D floor (let's say a plane, but it could be any mesh) : F
I have a 3D point in space : A
I have a given radius : R

I would want the floor to be red where the distance to A is inferior to R.
The goal is to vizualize the distance to point A (which could be my character for instance) on the ground. Idealy the red zone is semi-transparent so I can see part of the real floor material (but I don't think this is the difficult part).

From what I understood, I think making a shader could be the answer , but I don't know how to set the color of the fragment depending on the distance to a 3D point. I would appreciate yout help on this one :-)

in Engine by (19 points)

1 Answer

+1 vote
Best answer

I would use a shader for that.
With this tutorial you can get the fragment world position. Then you need to check if the distance from the fragment to the player is less than R. This should be in the void fragment() function.

vec3 color = vec3(1., 0., 0.); // RED
if(distance(world_position, player_position) < R){
        ALBEDO = color + texture(SCREEN_TEXTURE, SCREEN_UV).xyz;
        ALPHA = 1.;
        ALPHA = 0.;

Since you want the ground to be visible, the screen texture should be added to the color (like in the example above). If you want to see the floor better, reduce the ALPHA value.
If you are new to shaders, I would suggest following the tutorials here first.

by (64 points)
selected by
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.