Sobel filter leaves strange artifacts

Godot Version

4.2.2.stable.mono

Question

Hi!
I am using a Sobel operator to detect edges on my normal texture and depth texture, but it is leaving strange artifacts.
sobel
Does anyone know what could be causing this?

Here is the shader code:
outline.gdshader:

shader_type spatial;
render_mode unshaded, cull_disabled;
uniform sampler2D normal_texture : hint_normal_roughness_texture;
uniform sampler2D depth_texture : hint_depth_texture;
uniform sampler2D screen_texture : hint_screen_texture;

uniform float depth_intensity : hint_range(0.0, 5.0, 0.01) = 1.0;
uniform float normal_intensity : hint_range(0.0, 5.0, 0.01) = 1.0;

uniform sampler2D color;
uniform sampler2D edge_mix_strength;

uniform float edge_size = 1.;

#include "Utils/average.gdshaderinc"
#include "EdgeDetection/sobel.gdshaderinc"

void fragment() {
	vec4 original_color = texture(screen_texture, SCREEN_UV);
	
	vec2 viewport_size = VIEWPORT_SIZE / edge_size;
	
	// find edges
	float sobel_normal = edge_strength(normal_texture, SCREEN_UV, viewport_size);
	sobel_normal = clamp(sobel_normal * normal_intensity, 0.0, 1.0);
	float sobel_depth = edge_strength(normal_texture, SCREEN_UV, viewport_size);
	sobel_depth = clamp(sobel_depth * depth_intensity, 0.0, 1.0);
	float edge_intensity = (sobel_normal + sobel_depth) / 2.0;
	
	// sample edge mix
	float edge_mix = texture(edge_mix_strength, vec2(edge_intensity, 0)).r;
	
	// adjust edge to how dark the original color
	vec4 edge_color = texture(color, vec2(vec3_average(original_color.rgb), 0));
	vec4 mixed_color = mix(original_color, edge_color, edge_mix);
	ALBEDO = mixed_color.rgb;
	ALPHA = mixed_color.a;
}

sobel.gdasherinc:

#include "res://Assets/Shaders/Utils/average.gdshaderinc"

void make_kernel(inout vec4 n[9], sampler2D tex, vec2 coord, vec2 size)
{
	float w = 1.0 / size.x;
	float h = 1.0 / size.y;

	n[0] = texture(tex, coord + vec2( -w, -h));
	n[1] = texture(tex, coord + vec2(0.0, -h));
	n[2] = texture(tex, coord + vec2(  w, -h));
	n[3] = texture(tex, coord + vec2( -w, 0.0));
	n[4] = texture(tex, coord);
	n[5] = texture(tex, coord + vec2(  w, 0.0));
	n[6] = texture(tex, coord + vec2( -w, h));
	n[7] = texture(tex, coord + vec2(0.0, h));
	n[8] = texture(tex, coord + vec2(  w, h));
}

vec4 sobel_calculations(vec4 n[9]) {
	vec4 sobel_edge_h = n[2] + (2.0*n[5]) + n[8] - (n[0] + (2.0*n[3]) + n[6]);
  	vec4 sobel_edge_v = n[0] + (2.0*n[1]) + n[2] - (n[6] + (2.0*n[7]) + n[8]);
	vec4 sobel = sqrt((sobel_edge_h * sobel_edge_h) + (sobel_edge_v * sobel_edge_v));
	return sobel;
}

vec4 sobel(sampler2D tex, vec2 uv, vec2 viewport_size) {
	vec4 n[9];
	make_kernel( n, tex, uv, viewport_size );
	return sobel_calculations(n);
}

float edge_strength(sampler2D tex, vec2 uv, vec2 viewport_size) {
	return vec4_average(sobel(tex, uv, viewport_size));
}

average.gdshaderinc

 float vec4_average(vec4 input) {
	return (input.r + input.g + input.b + input.a) / 4.0;
}

float vec3_average(vec3 input) {
	return (input.r + input.g + input.b) / 3.0;
}

Thanks!