Positioned Shockwave

Based on the shockwave shader tutorial by Nolkaloid: https://www.youtube.com/watch?v=SCHdglr35pk

The shader itself is the same, but now you can pass the [global position of the object – global position of the camera] to the global_position uniform of the shader to make the shockwave emit from the object.

Shader code
shader_type canvas_item;

uniform vec2 global_position;
uniform vec2 screen_size;
uniform float force;
uniform float size;
uniform float thickness;

void fragment(){
	vec2 center = global_position;
	float ratio = SCREEN_PIXEL_SIZE.x / SCREEN_PIXEL_SIZE.y;
	center.x = center.x / screen_size.x;
	center.x = (center.x - 0.5) / ratio + 0.5;
	center.y = (screen_size.y - center.y) / screen_size.y;
	vec2 scaledUV = (SCREEN_UV - vec2(0.5, 0.0) ) / vec2(ratio, 1.0) + vec2(0.5, 0.0);
	float mask = (1.0 - smoothstep(size-0.1, size, length(scaledUV - center))) * smoothstep(size-thickness-0.1, size-thickness, length(scaledUV - center));
	vec2 disp = normalize(SCREEN_UV - center) * force * mask;
	COLOR = texture(SCREEN_TEXTURE, SCREEN_UV - disp);
}
Tags
explosion, shockwave
The shader code and all code snippets in this post are under MIT license and can be used freely. Images and videos, and assets depicted in those, do not fall under this license. For more info, see our License terms.

Related shaders

Distortion/Shockwave Shader

guest

4 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
snesmocha
snesmocha
1 year ago

um, we posted the same shader………

snesmocha
snesmocha
1 year ago
Reply to  pekopekorhino

huh didn’t realize that

Pandemic
Pandemic
7 months ago

Will this shader work in a 3D scene? I would like the shockwave appear to emanate from a 3D node.