Volumetric Light Beam , Radiation

The shader works in Godot and includes settings; it can be used in any project, and there is no requirement to credit the creator.

Shader code
shader_type spatial;
render_mode blend_add, cull_disabled, depth_draw_never, shadows_disabled, unshaded, fog_disabled;

uniform vec4  light_color    : source_color = vec4(1.0, 0.86, 0.62, 1.0);
uniform float intensity     : hint_range(0.0, 20.0, 0.05) = 3.0;
uniform float beam_length   : hint_range(0.1, 60.0, 0.1)  = 8.0;   // = CylinderMesh.height
uniform float source_radius : hint_range(0.005, 10.0, 0.005) = 0.35; // top_radius
uniform float end_radius    : hint_range(0.005, 20.0, 0.005) = 3.0;  // bottom_radius
uniform float edge_softness : hint_range(0.05, 6.0, 0.05)   = 1.4;
uniform int   ray_count     : hint_range(1, 64, 1)   = 12;  // عدد الأشعة
uniform float ray_sharpness : hint_range(0.5, 24.0, 0.1) = 6.0;
uniform float ray_strength  : hint_range(0.0, 1.0, 0.01)  = 0.8;
uniform float noise_scale   : hint_range(0.05, 20.0, 0.05) = 1.2;
uniform float noise_strength: hint_range(0.0, 2.0, 0.01)  = 0.35;
uniform float flow_speed    : hint_range(0.0, 5.0, 0.01)  = 0.5;
uniform float length_falloff: hint_range(0.0, 8.0, 0.05)  = 0.8;
uniform float tip_fade      : hint_range(0.001, 1.0, 0.001) = 0.05;
uniform float distance_fade : hint_range(0.0, 2.0, 0.01)  = 0.0;

varying vec3 local_pos;
varying vec3 view_pos;

float hash13(vec3 p) {
	p = fract(p * 0.1031);
	p += dot(p, p.zyx + 31.32);
	return fract((p.x + p.y) * p.z);
}

float vnoise(vec3 x) {
	vec3 i = floor(x); vec3 f = fract(x);
	f = f * f * (3.0 - 2.0 * f);
	float n000 = hash13(i);
	float n100 = hash13(i + vec3(1.0, 0.0, 0.0));
	float n010 = hash13(i + vec3(0.0, 1.0, 0.0));
	float n110 = hash13(i + vec3(1.0, 1.0, 0.0));
	float n001 = hash13(i + vec3(0.0, 0.0, 1.0));
	float n101 = hash13(i + vec3(1.0, 0.0, 1.0));
	float n011 = hash13(i + vec3(0.0, 1.0, 1.0));
	float n111 = hash13(i + vec3(1.0, 1.0, 1.0));
	return mix(mix(mix(n000, n100, f.x), mix(n010, n110, f.x), f.y),
			   mix(mix(n001, n101, f.x), mix(n011, n111, f.x), f.y), f.z);
}

float fbm(vec3 p) {
	float value = 0.0; float amplitude = 0.5;
	for (int i = 0; i < 4; i++) {
		value += amplitude * vnoise(p);
		p = p * 2.02 + vec3(11.3, 7.7, 5.1);
		amplitude *= 0.5;
	}
	return value;
}

void vertex() {
	local_pos = VERTEX;
	view_pos = (VIEW_MATRIX * MODEL_MATRIX * vec4(VERTEX, 1.0)).xyz;
}

void fragment() {
	// 0 عند نهاية الشعاع، 1 عند المصدر
	float t = clamp((local_pos.y + beam_length * 0.5) / max(beam_length, 0.001), 0.0, 1.0);
	float from_source = 1.0 - t;
	float radius_here = mix(source_radius, end_radius, from_source);

	// سماكة حجم تقريبية (طول الوتر داخل المخروط)
	float rn = clamp(length(local_pos.xz) / max(radius_here, 0.0001), 0.0, 1.0);
	float thickness = pow(sqrt(max(1.0 - rn * rn, 0.0)), max(edge_softness, 0.01));

	// ضوضاء متحركة (تموّج + غبار)
	vec3 noise_pos = local_pos * noise_scale + vec3(0.0, -TIME * flow_speed, 0.0);
	float n1 = fbm(noise_pos);
	float n2 = fbm(noise_pos * 2.7 + vec3(TIME * flow_speed * 0.5, 0.0, 0.0));

	// الأشعة حول المحور
	float angle = atan(local_pos.z, local_pos.x);
	float phase = (n1 - 0.5) * 6.0 + TIME * flow_speed * 0.6;
	float spokes = pow(0.5 + 0.5 * sin(angle * float(ray_count) + phase), max(ray_sharpness, 0.5));
	float rays = mix(1.0, 0.25 + 0.75 * spokes, ray_strength);

	float along = exp(-from_source * length_falloff);
	along *= smoothstep(0.0, tip_fade, from_source);
	float dust = mix(1.0, 0.65 + 0.7 * n2, clamp(noise_strength, 0.0, 1.0));

	float amount = thickness * along * rays * dust;

	if (distance_fade > 0.0) {
		vec3 cam_world  = (INV_VIEW_MATRIX * vec4(0.0, 0.0, 0.0, 1.0)).xyz;
		vec3 frag_world = (INV_VIEW_MATRIX * vec4(view_pos, 1.0)).xyz;
		amount *= exp(-length(frag_world - cam_world) * distance_fade);
	}

	ALBEDO = light_color.rgb * light_color.a * intensity * amount;
	ALPHA  = 1.0;
}
Live Preview
Tags
Radiation
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.

Related shaders

Comments 0

No comments yet.