diff --git a/shaders/agents_cs.glsl b/shaders/agents_cs.glsl index a4ff041..98f7693 100644 --- a/shaders/agents_cs.glsl +++ b/shaders/agents_cs.glsl @@ -18,6 +18,8 @@ layout(push_constant, std430) uniform Params { } params; const float SPEED = 1.0; +const float DEPOSIT = 0.5; + float random(vec2 coords) { return fract(sin(dot(coords.xy, vec2(12.9898,78.233))) * 43758.5453); @@ -78,7 +80,7 @@ void main() { agent_buffer.positions[id] = pos; agent_buffer.headings[id] = new_heading; - float new_v = current_v + 0.3; + float new_v = current_v + DEPOSIT; if (new_v > 1.0) new_v = 1.0; vec4 result = vec4(new_v, new_v, new_v, 1.0); diff --git a/shaders/decay_cs.glsl b/shaders/decay_cs.glsl index e23d320..80170f3 100644 --- a/shaders/decay_cs.glsl +++ b/shaders/decay_cs.glsl @@ -17,7 +17,8 @@ layout(push_constant, std430) uniform Params { float get_dissipation_from(ivec2 uv) { float v = imageLoad(current_image, uv).r; - return v * params.dissipation_factor; + // return v * params.dissipation_factor; + return v; } ivec2 loop_position(ivec2 pos) { @@ -27,27 +28,20 @@ ivec2 loop_position(ivec2 pos) { // The code we want to execute in each invocation void main() { - ivec2 size = ivec2(params.texture_size.x - 1, params.texture_size.y - 1); ivec2 uv = ivec2(gl_GlobalInvocationID.xy); - ivec2 tl = ivec2(0, 0); - ivec2 up_uv = loop_position(uv - ivec2(0, 1)); - ivec2 down_uv = loop_position(uv + ivec2(0, 1)); - ivec2 left_uv = loop_position(uv - ivec2(1, 0)); - ivec2 right_uv = loop_position(uv + ivec2(1, 0)); - - // Just in case the texture size is not divisable by 8. - if ((uv.x > size.x) || (uv.y > size.y)) { - return; + float current_sum = 0.0; + for (int i = -1; i <= 1; i++) { + for (int j = -1; j <= 1; j++) { + ivec2 kuv = loop_position(uv + ivec2(i,j)); + current_sum += get_dissipation_from(kuv); + } } + // ivec2 up_uv = loop_position(uv - ivec2(0, 1)); + // ivec2 down_uv = loop_position(uv + ivec2(0, 1)); + // ivec2 left_uv = loop_position(uv - ivec2(1, 0)); + // ivec2 right_uv = loop_position(uv + ivec2(1, 0)); - float current_v = imageLoad(current_image, uv).r; - - float new_v = current_v * params.decay_factor; - new_v += get_dissipation_from(up_uv); - new_v += get_dissipation_from(down_uv); - new_v += get_dissipation_from(right_uv); - new_v += get_dissipation_from(left_uv); // Kill very old trails completely // if (new_v < 0.001) { @@ -56,7 +50,11 @@ void main() { // new_v = clamp(new_v, 0, 1); - vec4 result = vec4(new_v, new_v, new_v, 1.0); + // This is good when not using trail for showind as is. + // https://github.com/Bleuje/physarum-36p/blob/main/bin/data/shaders/computeshader_deposit.glsl + current_sum = current_sum / pow(3.0, 2.0); + + vec4 result = vec4(vec3(current_sum), 1.0); imageStore(output_image, uv, result); diff --git a/slime_simulation.tscn b/slime_simulation.tscn index 036ac3e..e47b452 100644 --- a/slime_simulation.tscn +++ b/slime_simulation.tscn @@ -15,8 +15,7 @@ size = Vector2(1920, 1080) [node name="SlimeSimulation" type="Node2D"] script = ExtResource("1_pxe3a") texture_size = Vector2i(1920, 1080) -decay_factor = 0.75 -dissipation_factor = 0.06 +decay_factor = 0.8 sensor_angle = 7.0 sensor_distance = 10.0 rng_seed = 8008