Radar Scanner

Creates a radar scanner and trail (Part of a pack of 3 shaders)

Note: only draws the line, the background must be provided (like in a TextureRect)

Implementation:
I used a ColorRect in the size that I wanted the scanner to be

Uniforms:
Speed: How fast the scanner moves

Line Color: The color of the scan line

Trail Color: The color of the trail
Trail Length: How long the trail fade should be

Shader code
shader_type canvas_item;

// --- Constants --- //
const float TWO_PI = 6.28318530718;

// --- Uniforms --- //
uniform float speed: hint_range(0.0, 10.0, 0.1) = 2.0;
group_uniforms line;
uniform vec4 line_color: source_color = vec4(0.0, 1.0, 1.0, 0.85);
group_uniforms trail;
uniform vec4 trail_color: source_color = vec4(0.0, 1.0, 1.0, 0.20);
uniform float trail_length: hint_range(0.0, 1.0, 0.1) = 0.10;

// --- Functions --- //
vec2 rotate(vec2 _pos, float _angle) {
	return vec2(_pos.x * cos(_angle) - _pos.y * sin(_angle), _pos.x * sin(_angle) + _pos.y * cos(_angle));
}

void fragment() {
	vec2 pos = rotate(UV - 0.5, -TIME * speed);
	
	float angle = (atan(pos.y, pos.x) + PI) / TWO_PI;
	float len = step(0.5, 1.0 - distance(pos, vec2(0.0)));
	COLOR *= trail_color;
	COLOR.a *= smoothstep(1.0 - trail_length, 1.0, angle);
	COLOR = mix(COLOR, line_color, step(0.998, angle));
	COLOR *= len;
}
Tags
animated, radar, radar scanner
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 KingToot

Sine Morphing

Burn/Dissolve

Invert Color

Related shaders

Radar Scanning Effect Shader

Radar with trace blip

Radar Blip Ring

Subscribe
Notify of
guest

1 Comment
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
LordBoots
LordBoots
6 months ago

This one’s a beaut.