I think it is in some kind of working state now
This commit is contained in:
@@ -12,7 +12,7 @@ extends Node2D
|
||||
@onready var mesh := $MeshInstance2D
|
||||
|
||||
## Needs to be changed from the shader as well
|
||||
const AGENTS: int = 4096
|
||||
const AGENTS: int = 1024
|
||||
|
||||
var texture: Texture2DRD
|
||||
var next_texture: int = 0
|
||||
@@ -31,7 +31,14 @@ func _process(_delta: float) -> void:
|
||||
texture.texture_rd_rid = texture_rds[next_texture]
|
||||
|
||||
RenderingServer.call_on_render_thread(
|
||||
_render_process.bind(next_texture, texture_size, decay_factor, dissipation_factor, sensor_angle, sensor_distance)
|
||||
_render_process.bind(
|
||||
next_texture,
|
||||
texture_size,
|
||||
decay_factor,
|
||||
dissipation_factor,
|
||||
sensor_angle,
|
||||
sensor_distance
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
@@ -96,9 +103,8 @@ func _initialize_compute_code(with_texture_size: Vector2i) -> void:
|
||||
var agent_angles := PackedFloat32Array()
|
||||
# This must match what is set in the shader, if fixed size
|
||||
for n in AGENTS:
|
||||
var new_position: Vector2 = Vector2(
|
||||
rng.randf_range(0, with_texture_size.x),
|
||||
rng.randf_range(0, with_texture_size.y)
|
||||
var new_position := Vector2(
|
||||
rng.randf_range(0, with_texture_size.x), rng.randf_range(0, with_texture_size.y)
|
||||
)
|
||||
agent_positions.push_back(new_position)
|
||||
agent_angles.push_back(rng.randf_range(0, TAU))
|
||||
@@ -106,8 +112,7 @@ func _initialize_compute_code(with_texture_size: Vector2i) -> void:
|
||||
var agent_data := PackedByteArray(agent_positions.to_byte_array())
|
||||
agent_data.append_array(agent_angles.to_byte_array())
|
||||
agent_buffer = rd.storage_buffer_create(
|
||||
agent_data.size(), agent_data, 0,
|
||||
RenderingDevice.BUFFER_CREATION_AS_STORAGE_BIT
|
||||
agent_data.size(), agent_data, 0, RenderingDevice.BUFFER_CREATION_AS_STORAGE_BIT
|
||||
)
|
||||
|
||||
# Create trail texture
|
||||
@@ -127,7 +132,6 @@ func _initialize_compute_code(with_texture_size: Vector2i) -> void:
|
||||
| RenderingDevice.TEXTURE_USAGE_CAN_COPY_TO_BIT
|
||||
)
|
||||
|
||||
|
||||
var agent_uniforms: Array[RDUniform] = []
|
||||
for i in 2:
|
||||
texture_rds[i] = rd.texture_create(tf, RDTextureView.new(), [])
|
||||
@@ -142,7 +146,7 @@ func _initialize_compute_code(with_texture_size: Vector2i) -> void:
|
||||
txtr_uniform_1.binding = 0
|
||||
txtr_uniform_1.add_id(texture_rds[0])
|
||||
agent_uniforms.append(txtr_uniform_1)
|
||||
|
||||
|
||||
var txtr_uniform_2 := RDUniform.new()
|
||||
txtr_uniform_2.uniform_type = RenderingDevice.UNIFORM_TYPE_IMAGE
|
||||
txtr_uniform_2.binding = 1
|
||||
@@ -153,11 +157,22 @@ func _initialize_compute_code(with_texture_size: Vector2i) -> void:
|
||||
uniform.uniform_type = RenderingDevice.UNIFORM_TYPE_STORAGE_BUFFER
|
||||
uniform.binding = 2
|
||||
uniform.add_id(agent_buffer)
|
||||
agent_sets[0] = rd.uniform_set_create([txtr_uniform_1, txtr_uniform_2, uniform], agent_shader, 0)
|
||||
agent_sets[1] = rd.uniform_set_create([txtr_uniform_2, txtr_uniform_1, uniform], agent_shader, 0)
|
||||
agent_sets[0] = rd.uniform_set_create(
|
||||
[txtr_uniform_1, txtr_uniform_2, uniform], agent_shader, 0
|
||||
)
|
||||
agent_sets[1] = rd.uniform_set_create(
|
||||
[txtr_uniform_2, txtr_uniform_1, uniform], agent_shader, 0
|
||||
)
|
||||
|
||||
|
||||
func _render_process(with_next_texture: int, tex_size: Vector2i, decay_fctr: float, dissipation_fctr: float, snsr_angle: float, snsr_distance: float) -> void:
|
||||
func _render_process(
|
||||
with_next_texture: int,
|
||||
tex_size: Vector2i,
|
||||
decay_fctr: float,
|
||||
dissipation_fctr: float,
|
||||
snsr_angle: float,
|
||||
snsr_distance: float
|
||||
) -> void:
|
||||
var next_set := texture_sets[with_next_texture]
|
||||
var current_set := texture_sets[(with_next_texture - 1) % 2]
|
||||
|
||||
@@ -168,7 +183,6 @@ func _render_process(with_next_texture: int, tex_size: Vector2i, decay_fctr: flo
|
||||
push_constant.push_back(snsr_angle)
|
||||
push_constant.push_back(snsr_distance)
|
||||
|
||||
|
||||
var agent_compute_list := rd.compute_list_begin()
|
||||
rd.compute_list_bind_compute_pipeline(agent_compute_list, agent_pipeline)
|
||||
rd.compute_list_bind_uniform_set(agent_compute_list, agent_sets[with_next_texture], 0)
|
||||
|
||||
Reference in New Issue
Block a user