diff --git a/shaders/agents_cs.glsl b/shaders/agents_cs.glsl index 0e3d986..a4ff041 100644 --- a/shaders/agents_cs.glsl +++ b/shaders/agents_cs.glsl @@ -12,7 +12,7 @@ layout(binding = 2) restrict buffer AgentBuffer { } agent_buffer; layout(push_constant, std430) uniform Params { - ivec2 texture_size; + vec2 texture_size; float sensor_angle; float sensor_distance; } params; @@ -24,13 +24,7 @@ float random(vec2 coords) { } vec2 loop_position(vec2 pos) { - int width = params.texture_size.x; - int height = params.texture_size.y; - if (pos.x > width) pos.x = mod(pos.x, width); - if (pos.y > height) pos.y = mod(pos.y, height); - if (pos.x < 0) pos.x = width + pos.x; - if (pos.y < 0) pos.y = height + pos.y; - return pos; + return mod(pos, params.texture_size); } void main() { @@ -39,6 +33,8 @@ void main() { vec2 position = agent_buffer.positions[id]; float heading = agent_buffer.headings[id]; + float current_v = imageLoad(current_trail, ivec2(position)).r; + float sa = params.sensor_angle; float left_heading = heading - sa; float right_heading = heading + sa; @@ -64,17 +60,26 @@ void main() { } else if (right > forward && right > left) { pos += right_detect_dir * SPEED; new_heading = right_heading; + } else if (forward < left && forward < right) { + // uuugh + float r = random(pos); + if (r < 0.5) { + pos += right_detect_dir * SPEED; + new_heading = right_heading; + } else { + pos += left_detect_dir * SPEED; + new_heading = left_heading; + } } else { pos += forward_detect_dir * SPEED; } - pos = loop_position(pos); + pos = mod(pos, params.texture_size); agent_buffer.positions[id] = pos; agent_buffer.headings[id] = new_heading; - float current_v = imageLoad(current_trail, ivec2(pos)).r; - float new_v = current_v + 0.3; + if (new_v > 1.0) new_v = 1.0; vec4 result = vec4(new_v, new_v, new_v, 1.0); imageStore(output_trail, ivec2(pos), result); diff --git a/shaders/decay_cs.glsl b/shaders/decay_cs.glsl index 77fe747..e23d320 100644 --- a/shaders/decay_cs.glsl +++ b/shaders/decay_cs.glsl @@ -21,14 +21,7 @@ float get_dissipation_from(ivec2 uv) { } ivec2 loop_position(ivec2 pos) { - int width = params.texture_size.x; - int height = params.texture_size.y; - vec2 looped = pos; - if (pos.x > width) looped.x = mod(pos.x, width); - if (pos.y > height) looped.y = mod(pos.y, height); - if (pos.x < 0) looped.x = width - pos.x; - if (pos.y < 0) looped.y = height - pos.y; - return ivec2(looped); + return pos % params.texture_size; } // The code we want to execute in each invocation diff --git a/slime_simulation.tscn b/slime_simulation.tscn index d93a605..036ac3e 100644 --- a/slime_simulation.tscn +++ b/slime_simulation.tscn @@ -18,7 +18,7 @@ texture_size = Vector2i(1920, 1080) decay_factor = 0.75 dissipation_factor = 0.06 sensor_angle = 7.0 -sensor_distance = 20.0 +sensor_distance = 10.0 rng_seed = 8008 [node name="MeshInstance2D" type="MeshInstance2D" parent="."]