@@ -17,6 +17,7 @@ the compositor. To get started, create a new compositor on the appropriate node:
1717.. image :: img/new_compositor.webp
1818
1919.. note ::
20+
2021 The compositor is currently a feature that is only supported by
2122 the Mobile and Forward+ renderers.
2223
@@ -55,7 +56,8 @@ This is the boilerplate code that makes our compute shader work.
5556
5657.. code-block :: gdscript
5758
58- const template_shader : String = "#version 450
59+ const template_shader: String = """
60+ #version 450
5961
6062 // Invocations in the (x, y, z) dimension
6163 layout(local_size_x = 8, local_size_y = 8, local_size_z = 1) in;
@@ -82,7 +84,8 @@ This is the boilerplate code that makes our compute shader work.
8284 #COMPUTE_CODE
8385
8486 imageStore(color_image, uv, color);
85- }"
87+ }
88+ """
8689
8790 For more information on how compute shaders work,
8891please check :ref: `Using compute shaders <doc_compute_shaders >`.
@@ -99,19 +102,19 @@ We'll also define a few script variables we'll be using:
99102
100103.. code-block :: gdscript
101104
102- @export_multiline var shader_code : String = "":
105+ @export_multiline var shader_code: String = "":
103106 set(value):
104107 mutex.lock()
105108 shader_code = value
106109 shader_is_dirty = true
107110 mutex.unlock()
108111
109- var rd : RenderingDevice
110- var shader : RID
111- var pipeline : RID
112+ var rd: RenderingDevice
113+ var shader: RID
114+ var pipeline: RID
112115
113- var mutex : Mutex = Mutex.new()
114- var shader_is_dirty : bool = true
116+ var mutex: Mutex = Mutex.new()
117+ var shader_is_dirty: bool = true
115118
116119
117120 Note the use of a :ref: `Mutex <class_Mutex >` in our code.
@@ -176,7 +179,7 @@ code was changed.
176179 if not rd:
177180 return false
178181
179- var new_shader_code : String = ""
182+ var new_shader_code: String = ""
180183
181184 # Check if our shader is dirty.
182185 mutex.lock()
@@ -199,10 +202,10 @@ code was changed.
199202 pipeline = RID()
200203
201204 # In with the new.
202- var shader_source : RDShaderSource = RDShaderSource.new()
205+ var shader_source: RDShaderSource = RDShaderSource.new()
203206 shader_source.language = RenderingDevice.SHADER_LANGUAGE_GLSL
204207 shader_source.source_compute = new_shader_code
205- var shader_spirv : RDShaderSPIRV = rd.shader_compile_spirv_from_source(shader_source)
208+ var shader_spirv: RDShaderSPIRV = rd.shader_compile_spirv_from_source(shader_source)
206209
207210 if shader_spirv.compile_error_compute != "":
208211 push_error(shader_spirv.compile_error_compute)
@@ -247,20 +250,20 @@ this at the right stage of rendering.
247250 if rd and p_effect_callback_type == EFFECT_CALLBACK_TYPE_POST_TRANSPARENT and _check_shader():
248251 # Get our render scene buffers object, this gives us access to our render buffers.
249252 # Note that implementation differs per renderer hence the need for the cast.
250- var render_scene_buffers : RenderSceneBuffersRD = p_render_data.get_render_scene_buffers()
253+ var render_scene_buffers: RenderSceneBuffersRD = p_render_data.get_render_scene_buffers()
251254 if render_scene_buffers:
252255 # Get our render size, this is the 3D render resolution!
253256 var size = render_scene_buffers.get_internal_size()
254257 if size.x == 0 and size.y == 0:
255258 return
256259
257- # We can use a compute shader here
260+ # We can use a compute shader here.
258261 var x_groups = (size.x - 1) / 8 + 1
259262 var y_groups = (size.y - 1) / 8 + 1
260263 var z_groups = 1
261264
262- # Push constant
263- var push_constant : PackedFloat32Array = PackedFloat32Array()
265+ # Push constant.
266+ var push_constant: PackedFloat32Array = PackedFloat32Array()
264267 push_constant.push_back(size.x)
265268 push_constant.push_back(size.y)
266269 push_constant.push_back(0.0)
@@ -272,15 +275,16 @@ this at the right stage of rendering.
272275 # Get the RID for our color image, we will be reading from and writing to it.
273276 var input_image = render_scene_buffers.get_color_layer(view)
274277
275- # Create a uniform set, this will be cached, the cache will be cleared if our viewports configuration is changed.
276- var uniform : RDUniform = RDUniform.new()
278+ # Create a uniform set.
279+ # This will be cached; the cache will be cleared if our viewport's configuration is changed.
280+ var uniform: RDUniform = RDUniform.new()
277281 uniform.uniform_type = RenderingDevice.UNIFORM_TYPE_IMAGE
278282 uniform.binding = 0
279283 uniform.add_id(input_image)
280284 var uniform_set = UniformSetCacheRD.get_cache(shader, 0, [ uniform ])
281285
282286 # Run our compute shader.
283- var compute_list := rd.compute_list_begin()
287+ var compute_list:= rd.compute_list_begin()
284288 rd.compute_list_bind_compute_pipeline(compute_list, pipeline)
285289 rd.compute_list_bind_uniform_set(compute_list, uniform_set, 0)
286290 rd.compute_list_set_push_constant(compute_list, push_constant.to_byte_array(), push_constant.size() * 4)
0 commit comments