lenia: normalize time
This commit is contained in:
parent
dce6916eb1
commit
111f4a21af
3 changed files with 7 additions and 23 deletions
|
@ -74,8 +74,6 @@
|
||||||
return exp(-((u-mu) * (u-mu)) / (2 * sigma * sigma)) * 2.0 - 1.0;
|
return exp(-((u-mu) * (u-mu)) / (2 * sigma * sigma)) * 2.0 - 1.0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
inline half value(float2 center, float x, float y) {
|
inline half value(float2 center, float x, float y) {
|
||||||
return tex2D(_LastFrame, center + float2(x, y)).r;
|
return tex2D(_LastFrame, center + float2(x, y)).r;
|
||||||
}
|
}
|
||||||
|
@ -86,14 +84,14 @@
|
||||||
|
|
||||||
const float resolution = 512.0;
|
const float resolution = 512.0;
|
||||||
const float d = 1.0 / resolution;
|
const float d = 1.0 / resolution;
|
||||||
// Defines RADIUS Radius Kernel total_max
|
// Defines RADIUS Kernel total_max
|
||||||
#include "lenia_generated_kernel.cginc"
|
#include "lenia_generated_kernel.cginc"
|
||||||
|
|
||||||
float total = 0.0;
|
float total = 0.0;
|
||||||
[unroll(RADIUS)]
|
[unroll(RADIUS)]
|
||||||
for (int y = 0; y < Radius; y++) {
|
for (int y = 0; y < RADIUS; y++) {
|
||||||
[unroll(RADIUS)]
|
[unroll(RADIUS)]
|
||||||
for (int x = 1; x <= Radius; x++) {
|
for (int x = 1; x <= RADIUS; x++) {
|
||||||
const float xx = (float)x * d;
|
const float xx = (float)x * d;
|
||||||
const float yy = (float)y * d;
|
const float yy = (float)y * d;
|
||||||
total += value(i.uv, xx, yy) * Kernel[y][x-1];
|
total += value(i.uv, xx, yy) * Kernel[y][x-1];
|
||||||
|
@ -102,23 +100,11 @@
|
||||||
total += value(i.uv, yy, -xx) * Kernel[y][x-1];
|
total += value(i.uv, yy, -xx) * Kernel[y][x-1];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// */
|
|
||||||
/*
|
|
||||||
float total_max = 0;
|
|
||||||
float total = 0;
|
|
||||||
for (int x = -Radius; x <= Radius; x++) {
|
|
||||||
for (int y = -Radius; y <= Radius; y++) {
|
|
||||||
float dist = sqrt(x*x+y*y);
|
|
||||||
float kval = kernel(dist);
|
|
||||||
total_max += kval;
|
|
||||||
total += value(i.uv, x*d, y*d) * kval;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// */
|
|
||||||
float old_state = value(i.uv, 0.0, 0.0) ;
|
float old_state = value(i.uv, 0.0, 0.0) ;
|
||||||
float count = total / total_max;
|
float count = total / total_max;
|
||||||
|
|
||||||
float state = activation(count) * _Speed + old_state;
|
const float step = _Speed / _Time.x;
|
||||||
|
float state = activation(count) * step + old_state;
|
||||||
state = clamp(state, 0, 1);
|
state = clamp(state, 0, 1);
|
||||||
|
|
||||||
// kernel visualization: lookup table (SLOW)
|
// kernel visualization: lookup table (SLOW)
|
||||||
|
@ -139,10 +125,10 @@
|
||||||
|
|
||||||
// kernel visualisation: real size
|
// kernel visualisation: real size
|
||||||
// float2 p = (i.uv - 0.5) * resolution;
|
// float2 p = (i.uv - 0.5) * resolution;
|
||||||
// float k = kernel(length(p)) * (max(abs(p.x), abs(p.y)) <= _Radius);
|
// float k = kernel(length(p)) * (max(abs(p.x), abs(p.y)) <= RADIUS);
|
||||||
|
|
||||||
// kernel visualisation: fill square
|
// kernel visualisation: fill square
|
||||||
// float k = kernel(length(i.uv - 0.5) * _Radius * 2);
|
// float k = kernel(length(i.uv - 0.5) * RADIUS * 2);
|
||||||
|
|
||||||
// float a = activation(i.uv.x);
|
// float a = activation(i.uv.x);
|
||||||
// float4 col = float4(state, k, a, 1);
|
// float4 col = float4(state, k, a, 1);
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
// generated by the rust program
|
// generated by the rust program
|
||||||
const int Radius = 20;
|
|
||||||
#define RADIUS 20
|
#define RADIUS 20
|
||||||
const half Kernel[21][20] = {
|
const half Kernel[21][20] = {
|
||||||
{0.00, 0.04, 0.10, 0.20, 0.38, 0.60, 0.80, 0.96, 0.98, 0.88, 0.68, 0.46, 0.26, 0.12, 0.06, 0.02, 0.00, 0.00, 0.00, 0.00, },
|
{0.00, 0.04, 0.10, 0.20, 0.38, 0.60, 0.80, 0.96, 0.98, 0.88, 0.68, 0.46, 0.26, 0.12, 0.06, 0.02, 0.00, 0.00, 0.00, 0.00, },
|
||||||
|
|
|
@ -15,7 +15,6 @@ fn main() {
|
||||||
|
|
||||||
let mut total_max = 0.0;
|
let mut total_max = 0.0;
|
||||||
println!("// generated by the rust program");
|
println!("// generated by the rust program");
|
||||||
println!("const int Radius = {};", radius);
|
|
||||||
println!("#define RADIUS {}", radius);
|
println!("#define RADIUS {}", radius);
|
||||||
println!("const half Kernel[{}][{}] = {{", radius + 1, radius);
|
println!("const half Kernel[{}][{}] = {{", radius + 1, radius);
|
||||||
for y in 0..=radius {
|
for y in 0..=radius {
|
||||||
|
|
Loading…
Reference in a new issue