Compositor problems

Godot Version

4.3

Question

Hi all, I’ve been trying to implement an advanced post-processing effect (volumetric fog, a couple image filters), and I’ve run into an issue with the way that the compositor passes uniforms to the compute shader. I’m not all that familiar with the rendering pipeline and how compute shaders work, so it might be an easy fix.

Basically, I need to pass the inverse view matrix, inverse projection matrix, and the camera position to the compute shader (the .glsl file), in order to reconstruct the world position of each pixel. I’ve tried passing them in the push constants, but they’re too large.

I really can’t achieve the post-processing effects that I want without this, and I don’t know the technical details to ask this question in a clearer way. I can’t use old-school post processing (full screen quad or canvas item shader), because I need to access the depth texture after transparent objects have been drawn, which is impossible as far as I know.

If anyone can help I’d greatly appreciate it.

Hello ,

You can use uniform buffers, that way :

var render_scene_data = p_render_data.get_render_scene_data()
				
				var cam_tr = render_scene_data.get_cam_transform()
				var view_proj = render_scene_data.get_view_projection(view)
				
				
				var cam_mat = [
					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, 
				]
				
				var proj_mat = [
					view_proj.x.x, view_proj.x.y, view_proj.x.z, 0.0, 
					view_proj.y.x, view_proj.y.y, view_proj.y.z, 0.0, 
					view_proj.z.x, view_proj.z.y, view_proj.z.z, 0.0, 
					view_proj.w.x, view_proj.w.y, view_proj.w.z, 1.0, 
				]
				

				var cma = PackedFloat32Array(cam_mat).to_byte_array()
				var vpa = PackedFloat32Array(proj_mat).to_byte_array()
				
				var pb = PackedByteArray()
				pb.append_array(cma)
				pb.append_array(vpa)
				
				var mat_buffer : RID =  rd.uniform_buffer_create(128, pb)
				
				var matrices_uniform : RDUniform = RDUniform.new()
				matrices_uniform.uniform_type = RenderingDevice.UNIFORM_TYPE_UNIFORM_BUFFER
				matrices_uniform.binding = 0
				matrices_uniform.add_id(mat_buffer)
				var matrices_uniform_set: RID = UniformSetCacheRD.get_cache(shader, 2, [  matrices_uniform ])

And in the shader :

layout(set=2, binding=0) uniform uniformBuffer {
	mat4 view;
	mat4 proj;
	} mat;

Here i create the buffer with a size of 128, because i use 2 matrices. With 3 matrices, that would be 192