saving what I've done
This commit is contained in:
@@ -7,8 +7,8 @@ layout(local_size_x = 64, local_size_y = 1, local_size_z = 1) in;
|
||||
layout(r32f, binding = 0) uniform restrict readonly image2D current_trail;
|
||||
layout(r32f, binding = 1) uniform restrict writeonly image2D output_trail;
|
||||
layout(binding = 2) restrict buffer AgentBuffer {
|
||||
vec2 positions[1024];
|
||||
float headings[1024];
|
||||
vec2 positions[1024 * 1024];
|
||||
float headings[1024 * 1024];
|
||||
} agent_buffer;
|
||||
|
||||
layout(push_constant, std430) uniform Params {
|
||||
@@ -19,13 +19,17 @@ layout(push_constant, std430) uniform Params {
|
||||
|
||||
const float SPEED = 1.0;
|
||||
|
||||
float random(vec2 coords) {
|
||||
return fract(sin(dot(coords.xy, vec2(12.9898,78.233))) * 43758.5453);
|
||||
}
|
||||
|
||||
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;
|
||||
if (pos.x < 0) pos.x = width + pos.x;
|
||||
if (pos.y < 0) pos.y = height + pos.y;
|
||||
return pos;
|
||||
}
|
||||
|
||||
|
||||
@@ -10,7 +10,7 @@ layout(r32f, set = 1, binding = 0) uniform restrict writeonly image2D output_ima
|
||||
|
||||
// PushConstants
|
||||
layout(push_constant, std430) uniform Params {
|
||||
vec2 texture_size;
|
||||
ivec2 texture_size;
|
||||
float decay_factor;
|
||||
float dissipation_factor;
|
||||
} params;
|
||||
@@ -20,11 +20,16 @@ float get_dissipation_from(ivec2 uv) {
|
||||
return v * params.dissipation_factor;
|
||||
}
|
||||
|
||||
// ivec2 loop_position(vec2 pos) {
|
||||
// int width = params.texture_size.x;
|
||||
// int height = params.texture_size.y;
|
||||
// return ivec2(mod(pos + params.texture_size, params.texture_size));
|
||||
// }
|
||||
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);
|
||||
}
|
||||
|
||||
// The code we want to execute in each invocation
|
||||
void main() {
|
||||
@@ -33,10 +38,10 @@ void main() {
|
||||
ivec2 uv = ivec2(gl_GlobalInvocationID.xy);
|
||||
|
||||
ivec2 tl = ivec2(0, 0);
|
||||
ivec2 up_uv = clamp(uv - ivec2(0, 1), tl, size);
|
||||
ivec2 down_uv = clamp(uv + ivec2(0, 1), tl, size);
|
||||
ivec2 left_uv = clamp(uv - ivec2(1, 0), tl, size);
|
||||
ivec2 right_uv = clamp(uv + ivec2(1, 0), tl, size);
|
||||
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)) {
|
||||
@@ -51,6 +56,10 @@ void main() {
|
||||
new_v += get_dissipation_from(right_uv);
|
||||
new_v += get_dissipation_from(left_uv);
|
||||
|
||||
// Kill very old trails completely
|
||||
// if (new_v < 0.001) {
|
||||
// new_v = 0;
|
||||
// }
|
||||
|
||||
// new_v = clamp(new_v, 0, 1);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user