Lenia: replace kernel with one from the paper, replace glider with a new life form

This commit is contained in:
Crispy 2023-07-30 18:40:00 +02:00
parent 481a12ecee
commit 05e0789077
9 changed files with 71 additions and 73 deletions

View file

@ -38,7 +38,7 @@ RenderSettings:
m_ReflectionIntensity: 1
m_CustomReflection: {fileID: 0}
m_Sun: {fileID: 0}
m_IndirectSpecularColor: {r: 0.17288938, g: 0.21605867, b: 0.2980182, a: 1}
m_IndirectSpecularColor: {r: 0.12732331, g: 0.1341519, b: 0.12107962, a: 1}
m_UseRadianceAmbientProbe: 0
--- !u!157 &3
LightmapSettings:
@ -149,7 +149,7 @@ Light:
serializedVersion: 10
m_Type: 1
m_Shape: 0
m_Color: {r: 1, g: 0.95686275, b: 0.8392157, a: 1}
m_Color: {r: 1, g: 1, b: 1, a: 1}
m_Intensity: 1
m_Range: 10
m_SpotAngle: 30
@ -206,13 +206,13 @@ Transform:
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 88997009}
m_LocalRotation: {x: 0.7321534, y: -0.01281865, z: 0.00015350126, w: 0.68101907}
m_LocalRotation: {x: 0, y: 1, z: 0, w: 0}
m_LocalPosition: {x: 0, y: 3, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 1
m_LocalEulerAnglesHint: {x: 85.73, y: -166.615, z: -165.563}
m_LocalEulerAnglesHint: {x: 0, y: 180, z: 0}
--- !u!1 &128608326
GameObject:
m_ObjectHideFlags: 0
@ -830,7 +830,7 @@ Transform:
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 336599934}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: -8.069, y: 0.308, z: -0.419}
m_LocalPosition: {x: -4.62, y: 0.628, z: -0.16}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 0}
@ -1241,7 +1241,7 @@ GameObject:
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
m_IsActive: 0
--- !u!4 &1144161807
Transform:
m_ObjectHideFlags: 0
@ -1273,6 +1273,7 @@ MonoBehaviour:
m_EditorClassIdentifier:
type: 3
objectId: e534d995-c7d9-4760-a831-8afcd31677ec
randomNum:
--- !u!114 &1144161809
MonoBehaviour:
m_ObjectHideFlags: 0
@ -1343,7 +1344,7 @@ GameObject:
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
m_IsActive: 0
--- !u!4 &1170317911
Transform:
m_ObjectHideFlags: 0
@ -1397,6 +1398,7 @@ MonoBehaviour:
m_EditorClassIdentifier:
type: 3
objectId: 6969fb97-fd3c-4d86-bc5e-d36b10bc55fc
randomNum:
--- !u!114 &1170317914
MonoBehaviour:
m_ObjectHideFlags: 0
@ -1773,7 +1775,7 @@ GameObject:
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
m_IsActive: 0
--- !u!65 &1377711729
BoxCollider:
m_ObjectHideFlags: 0
@ -1866,6 +1868,7 @@ MonoBehaviour:
m_EditorClassIdentifier:
type: 3
objectId: a35590d3-83fd-413c-89cf-7b7741360e1b
randomNum:
--- !u!114 &1377711734
MonoBehaviour:
m_ObjectHideFlags: 0
@ -2269,8 +2272,8 @@ Camera:
near clip plane: 0.3
far clip plane: 1000
field of view: 60
orthographic: 0
orthographic size: 5
orthographic: 1
orthographic size: 1
m_Depth: -1
m_CullingMask:
serializedVersion: 2
@ -2346,6 +2349,7 @@ MonoBehaviour:
m_EditorClassIdentifier:
type: 3
objectId: c4c0c234-abdc-4599-9251-2ba11d272218
randomNum: 83754194
--- !u!114 &1928596181
MonoBehaviour:
m_ObjectHideFlags: 0
@ -2635,6 +2639,7 @@ MonoBehaviour:
m_EditorClassIdentifier:
type: 3
objectId: 10538b39-c796-453b-bbdd-6ea4d67d6aa1
randomNum: 15816574
--- !u!114 &2044521651
MonoBehaviour:
m_ObjectHideFlags: 0
@ -2709,8 +2714,8 @@ Transform:
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 2044521647}
m_LocalRotation: {x: 0, y: 1, z: 0, w: 0}
m_LocalPosition: {x: -2.402, y: 0.506, z: 0.277}
m_LocalScale: {x: 0.125, y: 0.125, z: 0.125}
m_LocalPosition: {x: -2.402, y: 0.506, z: 1.22}
m_LocalScale: {x: 0.25, y: 0.25, z: 0.25}
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 7
@ -2738,7 +2743,7 @@ GameObject:
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
m_IsActive: 0
--- !u!114 &2129299479
MonoBehaviour:
m_ObjectHideFlags: 0
@ -2753,6 +2758,7 @@ MonoBehaviour:
m_EditorClassIdentifier:
type: 3
objectId: 9e648b07-a7c6-4bdb-80b5-6e399757a224
randomNum:
--- !u!114 &2129299480
MonoBehaviour:
m_ObjectHideFlags: 0

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.2 KiB

After

Width:  |  Height:  |  Size: 3.4 KiB

View file

@ -31,7 +31,7 @@ TextureImporter:
maxTextureSize: 2048
textureSettings:
serializedVersion: 2
filterMode: 0
filterMode: 1
aniso: 1
mipBias: 0
wrapU: 0

View file

@ -5,7 +5,7 @@
_LastFrame ("Texture", 2D) = "white" {}
_GrowtCenter ("Growth fn center (mu)", Range(0, 1)) = 0.2
_GrowthWidth ("Growth fn width (sigma / std deviation)", Range(0, 1)) = 0.07
_Speed ("Speed factor", Range(0.3, 5)) = 1
_Speed ("Speed factor", Range(0.01, 0.5)) = 0.05
}
SubShader
{
@ -22,16 +22,13 @@
#define WIDTH 512
struct appdata
{
struct appdata {
float4 vertex : POSITION;
float2 uv : TEXCOORD0;
};
struct v2f
{
struct v2f {
float2 uv : TEXCOORD0;
float4 vertex : SV_POSITION;
};
@ -40,8 +37,7 @@
float _GrowthWidth;
float _Speed;
v2f vert (appdata v)
{
v2f vert (appdata v) {
v2f o;
o.vertex = UnityObjectToClipPos(v.vertex);
o.uv = v.uv;
@ -63,7 +59,7 @@
// return exp(alpha - alpha/(4.0 * r * (1.0 - r)));
}
inline float activation(float neighbors) {
float activation(float neighbors) {
// return old_state * (neighbors > 2 && neighbors < 5) +
// ((1 - old_state) * neighbors == 3);
@ -76,14 +72,13 @@
return exp(-((u-mu) * (u-mu)) / (2 * sigma * sigma)) * 2.0 - 1.0;
}
inline float value(uint2 p, int dx, int dy) {
float value(uint2 p, int dx, int dy) {
const uint x = (p.x + dx) % WIDTH;
const uint y = (p.y + dy) % WIDTH;
return _LastFrame[uint2(x, y)].r;
}
fixed4 frag (v2f i) : SV_Target
{
float4 frag (v2f i) : SV_Target {
if(_ProjectionParams.z > 1) discard;
// Defines RADIUS Kernel total_max
@ -104,7 +99,7 @@
float old_state = value(p, 0, 0) ;
float count = total / total_max;
const float step = _Speed * unity_DeltaTime.x;
const float step = _Speed * unity_DeltaTime.x * 60;
float state = activation(count) * step + old_state;
state = clamp(state, 0, 1);

View file

@ -1,28 +1,26 @@
// generated by the rust program
#define RADIUS 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.02, 0.04, 0.10, 0.22, 0.40, 0.60, 0.82, 0.96, 0.98, 0.88, 0.68, 0.44, 0.26, 0.12, 0.06, 0.02, 0.00, 0.00, 0.00, 0.00, },
{0.04, 0.08, 0.16, 0.28, 0.46, 0.66, 0.86, 0.98, 0.98, 0.84, 0.64, 0.42, 0.24, 0.12, 0.04, 0.02, 0.00, 0.00, 0.00, 0.00, },
{0.10, 0.16, 0.24, 0.38, 0.56, 0.74, 0.92, 0.98, 0.94, 0.80, 0.58, 0.38, 0.22, 0.10, 0.04, 0.00, 0.00, 0.00, 0.00, 0.00, },
{0.22, 0.28, 0.38, 0.52, 0.68, 0.84, 0.96, 0.98, 0.90, 0.74, 0.52, 0.32, 0.18, 0.08, 0.02, 0.00, 0.00, 0.00, 0.00, 0.00, },
{0.40, 0.46, 0.56, 0.68, 0.82, 0.94, 0.98, 0.96, 0.82, 0.64, 0.44, 0.26, 0.14, 0.06, 0.02, 0.00, 0.00, 0.00, 0.00, 0.00, },
{0.60, 0.66, 0.74, 0.84, 0.94, 0.98, 0.98, 0.88, 0.72, 0.54, 0.34, 0.20, 0.10, 0.04, 0.02, 0.00, 0.00, 0.00, 0.00, 0.00, },
{0.82, 0.86, 0.92, 0.96, 0.98, 0.98, 0.90, 0.76, 0.58, 0.42, 0.26, 0.14, 0.06, 0.02, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, },
{0.96, 0.98, 0.98, 0.98, 0.96, 0.88, 0.76, 0.60, 0.44, 0.30, 0.18, 0.10, 0.04, 0.02, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, },
{0.98, 0.98, 0.94, 0.90, 0.82, 0.72, 0.58, 0.44, 0.32, 0.20, 0.10, 0.06, 0.02, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, },
{0.88, 0.84, 0.80, 0.74, 0.64, 0.54, 0.42, 0.30, 0.20, 0.12, 0.06, 0.02, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, },
{0.68, 0.64, 0.58, 0.52, 0.44, 0.34, 0.26, 0.18, 0.10, 0.06, 0.02, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, },
{0.44, 0.42, 0.38, 0.32, 0.26, 0.20, 0.14, 0.10, 0.06, 0.02, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, },
{0.26, 0.24, 0.22, 0.18, 0.14, 0.10, 0.06, 0.04, 0.02, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, },
{0.12, 0.12, 0.10, 0.08, 0.06, 0.04, 0.02, 0.02, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, },
{0.06, 0.04, 0.04, 0.02, 0.02, 0.02, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, },
{0.02, 0.02, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, },
{0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, },
{0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, },
{0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, },
{0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, },
#define RADIUS 18
const float Kernel[19][18] = {
{0.00, 0.00, 0.04, 0.16, 0.37, 0.60, 0.81, 0.95, 1.00, 0.95, 0.81, 0.60, 0.37, 0.16, 0.04, 0.00, 0.00, 0.00, },
{0.00, 0.00, 0.05, 0.18, 0.39, 0.62, 0.82, 0.95, 0.99, 0.94, 0.80, 0.59, 0.36, 0.16, 0.03, 0.00, 0.00, 0.00, },
{0.00, 0.02, 0.10, 0.25, 0.46, 0.67, 0.85, 0.97, 0.99, 0.93, 0.77, 0.56, 0.33, 0.14, 0.03, 0.00, 0.00, 0.00, },
{0.05, 0.10, 0.21, 0.37, 0.56, 0.75, 0.90, 0.98, 0.98, 0.90, 0.73, 0.52, 0.29, 0.11, 0.02, 0.00, 0.00, 0.00, },
{0.18, 0.25, 0.37, 0.52, 0.69, 0.84, 0.95, 0.99, 0.96, 0.85, 0.67, 0.45, 0.24, 0.08, 0.01, 0.00, 0.00, 0.00, },
{0.39, 0.46, 0.56, 0.69, 0.82, 0.93, 0.99, 0.99, 0.91, 0.77, 0.58, 0.37, 0.18, 0.05, 0.00, 0.00, 0.00, 0.00, },
{0.62, 0.67, 0.75, 0.84, 0.93, 0.98, 0.99, 0.95, 0.84, 0.68, 0.48, 0.28, 0.11, 0.02, 0.00, 0.00, 0.00, 0.00, },
{0.82, 0.85, 0.90, 0.95, 0.99, 0.99, 0.96, 0.87, 0.73, 0.55, 0.36, 0.18, 0.06, 0.00, 0.00, 0.00, 0.00, 0.00, },
{0.95, 0.97, 0.98, 0.99, 0.99, 0.95, 0.87, 0.75, 0.59, 0.41, 0.24, 0.10, 0.02, 0.00, 0.00, 0.00, 0.00, 0.00, },
{0.99, 0.99, 0.98, 0.96, 0.91, 0.84, 0.73, 0.59, 0.43, 0.27, 0.13, 0.04, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, },
{0.94, 0.93, 0.90, 0.85, 0.77, 0.68, 0.55, 0.41, 0.27, 0.14, 0.05, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, },
{0.80, 0.77, 0.73, 0.67, 0.58, 0.48, 0.36, 0.24, 0.13, 0.05, 0.01, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, },
{0.59, 0.56, 0.52, 0.45, 0.37, 0.28, 0.18, 0.10, 0.04, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, },
{0.36, 0.33, 0.29, 0.24, 0.18, 0.11, 0.06, 0.02, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, },
{0.16, 0.14, 0.11, 0.08, 0.05, 0.02, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, },
{0.03, 0.03, 0.02, 0.01, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, },
{0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, },
{0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, },
{0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, },
};
const float total_max = 356.63977;
// Total texture lookups: 206 * 4 + 1 = 825
const float total_max = 386.71994;
// Total texture lookups: 185 * 4 + 1 = 741
// (lookups multiplied by 0.0 get optimised away by the shader compiler, and this giant table generally only exists at compile time)

View file

@ -70,8 +70,8 @@ Material:
- _GlossMapScale: 1
- _Glossiness: 0.5
- _GlossyReflections: 1
- _GrowtCenter: 0.14
- _GrowthWidth: 0.013
- _GrowtCenter: 0.28
- _GrowthWidth: 0.04
- _KOffset: 0.436
- _KSharpness: 28.3
- _Metallic: 0
@ -81,7 +81,7 @@ Material:
- _Radius: 13
- _SmoothnessTextureChannel: 0
- _SpecularHighlights: 1
- _Speed: 2
- _Speed: 0.05
- _SrcBlend: 1
- _UVSec: 0
- _ZWrite: 1

View file

@ -18,21 +18,19 @@
// Use shader model 3.0 target, to get nicer looking lighting
#pragma target 3.0
struct Input
{
struct Input {
float2 uv_MainTex;
};
sampler2D _MainTex;
half _Emission;
float _Emission;
void surf (Input IN, inout SurfaceOutputStandard o)
{
void surf (Input IN, inout SurfaceOutputStandard o) {
// don't interfere with simulation camera
if(_ProjectionParams.z < 1) discard;
// Albedo comes from a texture tinted by color
fixed4 c = tex2D(_MainTex, IN.uv_MainTex);
float4 c = tex2D(_MainTex, IN.uv_MainTex);
o.Albedo = c.rgb;
o.Emission = c.rgb * _Emission;

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.5 KiB

After

Width:  |  Height:  |  Size: 1.4 KiB

View file

@ -8,9 +8,7 @@ fn main() {
return;
}
let radius = args[0].parse().unwrap();
let k_offset = 0.435;
let k_sharpness = 28.0;
let precision = 50.0; // for rounding
let precision = 100.0; // for rounding
let mut img = image::RgbImage::new(radius * 2 + 1, radius * 2 + 1);
@ -18,11 +16,11 @@ fn main() {
let mut total_lookups = 0;
println!("// generated by the rust program");
println!("#define RADIUS {}", radius);
println!("const half Kernel[{}][{}] = {{", radius + 1, radius);
println!("const float Kernel[{}][{}] = {{", radius + 1, radius);
for y in 0..=radius {
print!(" {{");
for x in 1..=radius {
let k = (k(x, y, radius, k_offset, k_sharpness) * precision).floor() / precision;
let k = (k(x, y, radius) * precision).floor() / precision;
total_max += k * 4.0;
if k > 0.0 {
total_lookups += 1;
@ -50,15 +48,18 @@ fn main() {
img.save("kernel.png").unwrap();
}
fn k(x: u32, y: u32, radius: u32, k_offset: f32, k_sharpness: f32) -> f32 {
fn k(x: u32, y: u32, radius: u32) -> f32 {
let x = x as f32;
let y = y as f32;
let r = (x * x + y * y).sqrt() / radius as f32;
f32::exp(-((r - k_offset) * (r - k_offset)) * k_sharpness)
// let k_offset = 0.435;
// let k_sharpness = 28.0;
// f32::exp(-((r - k_offset) * (r - k_offset)) * k_sharpness)
// lenia paper example kernel
// if r < 1.0 {
// f32::exp(4.0 - 4.0 / (4.0 * r * (1.0 - r)))
// } else {
// 0.0
// }
if r < 1.0 {
f32::exp(4.0 - 4.0 / (4.0 * r * (1.0 - r)))
} else {
0.0
}
}