tested proper blurring of the trail

This commit is contained in:
2025-08-02 01:36:04 +03:00
parent 83bd1bf452
commit 93ea79937b
3 changed files with 21 additions and 22 deletions

View File

@@ -18,6 +18,8 @@ layout(push_constant, std430) uniform Params {
} params; } params;
const float SPEED = 1.0; const float SPEED = 1.0;
const float DEPOSIT = 0.5;
float random(vec2 coords) { float random(vec2 coords) {
return fract(sin(dot(coords.xy, vec2(12.9898,78.233))) * 43758.5453); 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.positions[id] = pos;
agent_buffer.headings[id] = new_heading; 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; if (new_v > 1.0) new_v = 1.0;
vec4 result = vec4(new_v, new_v, new_v, 1.0); vec4 result = vec4(new_v, new_v, new_v, 1.0);

View File

@@ -17,7 +17,8 @@ layout(push_constant, std430) uniform Params {
float get_dissipation_from(ivec2 uv) { float get_dissipation_from(ivec2 uv) {
float v = imageLoad(current_image, uv).r; float v = imageLoad(current_image, uv).r;
return v * params.dissipation_factor; // return v * params.dissipation_factor;
return v;
} }
ivec2 loop_position(ivec2 pos) { ivec2 loop_position(ivec2 pos) {
@@ -27,27 +28,20 @@ ivec2 loop_position(ivec2 pos) {
// The code we want to execute in each invocation // The code we want to execute in each invocation
void main() { void main() {
ivec2 size = ivec2(params.texture_size.x - 1, params.texture_size.y - 1);
ivec2 uv = ivec2(gl_GlobalInvocationID.xy); ivec2 uv = ivec2(gl_GlobalInvocationID.xy);
ivec2 tl = ivec2(0, 0); float current_sum = 0.0;
ivec2 up_uv = loop_position(uv - ivec2(0, 1)); for (int i = -1; i <= 1; i++) {
ivec2 down_uv = loop_position(uv + ivec2(0, 1)); for (int j = -1; j <= 1; j++) {
ivec2 left_uv = loop_position(uv - ivec2(1, 0)); ivec2 kuv = loop_position(uv + ivec2(i,j));
ivec2 right_uv = loop_position(uv + ivec2(1, 0)); current_sum += get_dissipation_from(kuv);
// Just in case the texture size is not divisable by 8.
if ((uv.x > size.x) || (uv.y > size.y)) {
return;
} }
}
// 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 // Kill very old trails completely
// if (new_v < 0.001) { // if (new_v < 0.001) {
@@ -56,7 +50,11 @@ void main() {
// new_v = clamp(new_v, 0, 1); // 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); imageStore(output_image, uv, result);

View File

@@ -15,8 +15,7 @@ size = Vector2(1920, 1080)
[node name="SlimeSimulation" type="Node2D"] [node name="SlimeSimulation" type="Node2D"]
script = ExtResource("1_pxe3a") script = ExtResource("1_pxe3a")
texture_size = Vector2i(1920, 1080) texture_size = Vector2i(1920, 1080)
decay_factor = 0.75 decay_factor = 0.8
dissipation_factor = 0.06
sensor_angle = 7.0 sensor_angle = 7.0
sensor_distance = 10.0 sensor_distance = 10.0
rng_seed = 8008 rng_seed = 8008