Help with shockwave shader

Godot Version

4.2.1

Question

Hi, I am new to godot and copied this shockwave shader from godotshaders. my goal is to have the center of the shockwave be directly under where my slime sprite lands. I attatched the shader to a ColorRect that covers the entire viewport, The center of the shader is a vector 2 that needs to be between 0 and 1. I am super close to getting it to line up but it is just off. Here is a video showing how https://imgur.com/a/tsIBZJo

Here is the code related to its position that is attached to the shockwave colorrect

extends ColorRect

@onready var camera = get_parent().get_node(“Player”).get_node(“maincam”)
var enemy_position = Vector2(0,0)

func _ready():

size = get_viewport_rect().size	
var camera_bottomright = camera.get_screen_center_position() + size/2	
var shockwave_position = enemy_position / camera_bottomright	
material.set_shader_parameter("center", shockwave_position) 

func _process(delta):

global_position = camera.get_screen_center_position() - size/2

func getPosition(start_position):
enemy_position = start_position

And here is the code in the slime that summons the shockwave

var slime_shockwave = shockwave.instantiate()
slime_shockwave.getPosition(global_position)
get_parent().add_child(slime_shockwave)

And just in case here is the entire shader code

shader_type canvas_item;

uniform float strength: hint_range(0.0, 0.1, 0.001) = 0.08;
uniform vec2 center = vec2(0.5, 0.5);
uniform float radius: hint_range(0.0, 1.0, 0.001) = 0.25;

uniform float aberration: hint_range(0.0, 1.0, 0.001) = 0.425;
uniform float width: hint_range(0.0, 0.1, 0.0001) = 0.04;
uniform float feather: hint_range(0.0, 1.0, 0.001) = 0.135;

uniform sampler2D SCREEN_TEXTURE : hint_screen_texture, filter_linear_mipmap;

void fragment() {
vec2 st = SCREEN_UV;
float aspect_ratio = SCREEN_PIXEL_SIZE.y/SCREEN_PIXEL_SIZE.x;
vec2 scaled_st = (st -vec2(0.0, 0.5)) / vec2(1.0, aspect_ratio) + vec2(0,0.5);
vec2 dist_center = scaled_st - center;
float mask = (1.0 - smoothstep(radius-feather, radius, length(dist_center))) * smoothstep(radius - width - feather, radius-width , length(dist_center));
vec2 offset = normalize(dist_center)strengthmask;
vec2 biased_st = scaled_st - offset;

vec2 abber_vec = offset*aberration*mask;

vec2 final_st = st*(1.0-mask) + biased_st*mask;

vec4 red = texture(SCREEN_TEXTURE, final_st + abber_vec);
vec4 blue = texture(SCREEN_TEXTURE, final_st - abber_vec);
vec4 ori = texture(SCREEN_TEXTURE, final_st);
COLOR = vec4(red.r, ori.g, blue.b, 1.0);

}

I think the shader center value is in relation to the screen size so I tried to get normalized values by dividing the slime global pos by the bottom right of the camera pos. I used print to check that all of the camera and slime positions were correct as well. There is just something that I am missing, any help would be much appreciated as I have been stuck on this for a while, thanks

I’m having a similar issue, did you have any luck in resolving this?

is the shockwave_position value going into the material a normalized value?

Seven months ago, I created a tutorial to build this kind of effect. Maybe it could be useful to you.

2 Likes