Portal Shader (Swirling Vortex)
A round portal on one quad, with a dark centre, bright arms spiralling into it and a glowing rim that wobbles a little.
Put it on a QuadMesh of about 2 x 2 as Material Override and stand it in a doorway or an arch. Animate open from 0 to 1 and it opens from the middle out. arms and twist change how the spiral winds and swirl_speed sets how fast it turns. The first version had a seam on one side where the angle wraps around. Sampling the noise on a rotated copy of the plane got rid of it.
Turn Glow on, rim_energy goes above 1. No textures, and it looked the same on Forward+, Mobile and Compatibility in 4.4 and 4.7.
The code was written with the help of an AI coding assistant.
I wrote this as a small take on the gates in my Portal, Teleport & Spawn VFX pack for Godot 4, which also has warp and arrival effects.
https://gennai.itch.io/portal-teleport-spawn-vfx-godot-4?utm_source=godotshaders&utm_medium=referral&utm_campaign=portal
Shader code
// Swirling Portal Disc for Godot 4
// MIT License. Copyright (c) 2026 gennai (https://gennai.itch.io)
//
// A round portal on one quad: a dark centre, bright arms that spiral into it and a glowing,
// wobbling rim. Put it on a MeshInstance3D with a QuadMesh (for example 2 x 2) as
// Geometry > Material Override and stand the quad up in your doorway or archway. The quad
// has to stay flat; scale the node to change the size.
//
// Animate open from 0 to 1 to open the portal from the centre outward, and back to 0
// to close it. swirl_speed sets how fast it turns, arms how many spiral arms there are
// and twist how tightly they wind. The rim, the arms and the centre have their own colours.
// Values above 1 in rim_energy bloom when Glow is on in the WorldEnvironment.
// No textures: the pattern is computed in the shader with sin-free hashes, so it looks
// the same on every renderer.
shader_type spatial;
render_mode unshaded, blend_mix, depth_draw_never, cull_disabled, shadows_disabled, fog_disabled;
group_uniforms portal;
// 0 = closed, 1 = fully open. Animate this to open and close the portal.
uniform float open : hint_range(0.0, 1.0) = 1.0;
// Turning speed of the swirl.
uniform float swirl_speed : hint_range(-4.0, 4.0) = 0.8;
// Number of spiral arms.
uniform float arms : hint_range(1.0, 8.0) = 3.0;
// How tightly the arms wind towards the centre.
uniform float twist : hint_range(0.0, 12.0) = 5.0;
// How much the rim wobbles.
uniform float rim_wobble : hint_range(0.0, 0.1) = 0.03;
// Changes the pattern.
uniform float seed : hint_range(0.0, 100.0) = 0.0;
group_uniforms look;
// Colour of the dark centre.
uniform vec4 core_color : source_color = vec4(0.02, 0.0, 0.08, 1.0);
// Colour of the swirl arms.
uniform vec4 arm_color : source_color = vec4(0.35, 0.2, 1.0, 1.0);
// Colour of the glowing rim.
uniform vec4 rim_color : source_color = vec4(0.6, 0.9, 1.0, 1.0);
// Brightness of the rim. Values above 1 bloom when glow is on.
uniform float rim_energy : hint_range(0.0, 8.0) = 2.4;
// Brightness of the arms.
uniform float arm_energy : hint_range(0.0, 4.0) = 1.6;
float pd_hash(vec2 p) {
vec3 p3 = fract(vec3(p.xyx) * 0.1031);
p3 += dot(p3, p3.yzx + 33.33);
return fract((p3.x + p3.y) * p3.z);
}
float pd_noise(vec2 p) {
vec2 i = floor(p);
vec2 f = fract(p);
f = f * f * (3.0 - 2.0 * f);
return mix(mix(pd_hash(i), pd_hash(i + vec2(1.0, 0.0)), f.x),
mix(pd_hash(i + vec2(0.0, 1.0)), pd_hash(i + vec2(1.0, 1.0)), f.x), f.y);
}
float pd_fbm(vec2 p) {
float s = 0.0;
float a = 0.5;
for (int o = 0; o < 4; o++) {
s += pd_noise(p) * a;
p = p * 2.03 + 13.7;
a *= 0.5;
}
return s / 0.9375;
}
void fragment() {
vec2 p = (UV - 0.5) * 2.0;
float r = length(p);
float ang = atan(p.y, p.x);
float t = TIME * swirl_speed;
// The disc grows from the centre while it opens.
float R = 0.7 * smoothstep(0.0, 0.7, open);
float wob = (pd_noise(vec2(ang * 1.6 + t * 0.5 + seed, 1.0)) - 0.5) + (pd_noise(vec2(ang * 4.0 - t, 7.0 + seed)) - 0.5) * 0.5;
float Rw = R * (1.0 + wob * rim_wobble * 6.0);
float rn = r / max(Rw, 0.001);
// spiral arms: the angle is shifted by the radius, so the arms wind into the centre
float swirl = twist * 0.5 * log(max(rn, 0.02)) - t;
float sp = ang * arms / TAU + swirl;
// the noise is sampled in a rotated copy of the plane, so it has no seam
float ra = swirl * TAU / arms;
vec2 q = vec2(cos(ra) * p.x - sin(ra) * p.y, sin(ra) * p.x + cos(ra) * p.y);
float noise_w = pd_fbm(q * 2.5 + seed) - 0.5;
float band = 0.5 + 0.5 * cos((sp + noise_w * 0.8) * TAU);
band = smoothstep(0.35, 1.0, band);
float fine = pd_fbm(q * 5.0 + 5.0);
float arm = band * (0.55 + 0.7 * fine);
arm *= smoothstep(0.0, 0.25, rn);
// rim: a bright ring on the outer edge with a soft glow outside and inside
float rim_core = exp(-pow((rn - 0.96) * 14.0, 2.0));
float rim_glow = exp(-pow((rn - 0.96) * 5.0, 2.0)) * 0.45;
float inside = 1.0 - smoothstep(0.96, 1.02, rn);
float centre = (1.0 - smoothstep(0.0, 0.55, rn));
vec3 body = mix(arm_color.rgb * arm * arm_energy, core_color.rgb, centre * 0.7);
body = mix(body, core_color.rgb, centre * centre * 0.6);
vec3 col = body * inside + rim_color.rgb * rim_energy * (rim_core + rim_glow * 0.5);
// a pale glint at the very heart of the portal
col += rim_color.rgb * 0.4 * exp(-rn * rn * 90.0);
float a = clamp(inside + rim_core + rim_glow * 0.6, 0.0, 1.0) * step(0.001, R);
// soft fade at the outer edge of the quad so the glow never hits the border
a *= 1.0 - smoothstep(0.78, 0.95, r);
ALBEDO = col;
ALPHA = a;
}



Comments 0
No comments yet.