Annotate gd script

This commit is contained in:
Garrett Gunnell 2025-02-25 23:12:24 -08:00
parent 90a26ff10a
commit f7b5dd7805

View file

@ -12,11 +12,13 @@ func _init():
effect_callback_type = EFFECT_CALLBACK_TYPE_POST_TRANSPARENT
rd = RenderingServer.get_rendering_device()
# To make use of an existing ACompute shader we use its filename to access it, in this case, the example compute shader file is 'exposure_example.acompute'
exposure_compute = ACompute.new('exposure_example')
func _notification(what):
if what == NOTIFICATION_PREDELETE:
# ACompute will handle the freeing of any resources attached to it
exposure_compute.free()
@ -44,15 +46,19 @@ func _render_callback(p_effect_callback_type, p_render_data):
var y_groups = (size.y - 1) / 8 + 1
var z_groups = 1
# Vulkan has a feature known as push constants which are like uniform sets but for very small amounts of data
var push_constant : PackedFloat32Array = PackedFloat32Array([size.x, size.y, 0.0, 0.0])
for view in range(render_scene_buffers.get_view_count()):
var input_image = render_scene_buffers.get_color_layer(view)
# Pack the exposure vector into a byte array
var uniform_array = PackedFloat32Array([exposure.x, exposure.y, exposure.z, exposure.w]).to_byte_array()
# ACompute handles uniform caching under the hood, as long as the exposure value doesn't change or the render target doesn't change, these functions will only do work once
exposure_compute.set_texture(0, input_image)
exposure_compute.set_uniform_buffer(1, uniform_array)
exposure_compute.set_push_constant(push_constant.to_byte_array())
# Dispatch the compute kernel
exposure_compute.dispatch(0, x_groups, y_groups, z_groups)