Depth to world position in a CompositorEffect producing depth isosurfaces

Version: Godot 4.3.stable, custom build (godot_voxel)

I’ve been trying to get world positions from the depth buffer (generated by the depth prepass) in a CompositorEffect. The issue is that whenever I use the world space positions to, say, produce some noise, I end up with these weird depth isosurfaces


the noise used was a trustworthy simplex, so it definetly should not look like that.
The compositor effect is supposed to run PRE_OPAQUE and use the buffer produced by the depth_prepass to find the world positions. The transformation matrices I use are:

extends CompositorEffect
# ...

        var cam_tr = render_scene_data.get_cam_transform()
        var cam_proj = render_scene_data.get_cam_projection()
// have also tried with render_scene_data.get_view_projection(0)

	var cma = PackedFloat32Array([
		cam_tr.basis.x.x, cam_tr.basis.x.y, cam_tr.basis.x.z, 0.0,
		cam_tr.basis.y.x, cam_tr.basis.y.y, cam_tr.basis.y.z, 0.0,
		cam_tr.basis.z.x, cam_tr.basis.z.y, cam_tr.basis.z.z, 0.0,
		cam_tr.origin.x, cam_tr.origin.y, cam_tr.origin.z, 1.0, 
	]).to_byte_array()  # INV_VIEW_MATRIX

	var vpa = PackedFloat32Array([
		cam_proj.x.x, cam_proj.x.y, cam_proj.x.z, 0.0, 
		cam_proj.y.x, cam_proj.y.y, cam_proj.y.z, 0.0, 
		cam_proj.z.x, cam_proj.z.y, cam_proj.z.z, 0.0, 
		cam_proj.w.x, cam_proj.w.y, cam_proj.w.z, 1.0, 
	]).to_byte_array()  # PROJECTION_MATRIX

# these are sent to a compute shader as uniforms
# ...

then I dispatch the compute shader

// ...
// finding the world position is pretty much identical 
// to VisualShaderNodeWorldPositionFromDepth
float depth = textureLod(depth_tex, screen_uv, 0.0).r;
vec4 clip_p = vec4( vec3(screen_uv , depth) * 2. - 1., 1.0);
vec4 view_p = inverse(mat.proj) * clip_p;
view_p.xyz /= view_p.w;
vec3 p = (mat.inv_view * view_p).xyz;
imageStore(noise_buff, uv, vec4(simplex(p / 13.).xxx, 1.0));

depth = pow(depth, 0.3);  // for visibility
imageStore(depth_copy, uv, vec4(vec3(depth), 1.0) );

noise_buff is depicted on the image above and depth_copy is:

The visual shader node mentioned above calls the depth buffer '__log_depth' so maybe that’s a clue, but I have tried messing with the depth, with no success.
Also, I am almost sure I build the matrices wrong because the noise moves when I move the camera.

Any ideas about why this is happening?

solution:

	var vpa = PackedFloat32Array([
		cam_proj.x.x, cam_proj.x.y, cam_proj.x.z, cam_proj.x.w, 
		cam_proj.y.x, cam_proj.y.y, cam_proj.y.z, cam_proj.y.w, 
		cam_proj.z.x, cam_proj.z.y, cam_proj.z.z, cam_proj.z.w, 
		cam_proj.w.x, cam_proj.w.y, cam_proj.w.z, cam_proj.w.w, 
	]).to_byte_array()  # PROJECTION_MATRIX