lenia: optimise shader & move files

This commit is contained in:
Crispy 2023-06-23 21:27:34 +02:00
parent cf9e4b266d
commit 5281bfa340
24 changed files with 591 additions and 215 deletions

View file

@ -287,6 +287,85 @@ Transform:
m_Father: {fileID: 1206554220}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1 &289856511
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 289856512}
- component: {fileID: 289856515}
- component: {fileID: 289856514}
m_Layer: 0
m_Name: Simulation
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!4 &289856512
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 289856511}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 1928596186}
m_RootOrder: 1
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!23 &289856514
MeshRenderer:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 289856511}
m_Enabled: 1
m_CastShadows: 1
m_ReceiveShadows: 1
m_DynamicOccludee: 1
m_MotionVectors: 1
m_LightProbeUsage: 1
m_ReflectionProbeUsage: 1
m_RayTracingMode: 2
m_RenderingLayerMask: 1
m_RendererPriority: 0
m_Materials:
- {fileID: 2100000, guid: d3dc0619e4151e6b2b6b6b08038953f0, type: 2}
m_StaticBatchInfo:
firstSubMesh: 0
subMeshCount: 0
m_StaticBatchRoot: {fileID: 0}
m_ProbeAnchor: {fileID: 0}
m_LightProbeVolumeOverride: {fileID: 0}
m_ScaleInLightmap: 1
m_ReceiveGI: 1
m_PreserveUVs: 0
m_IgnoreNormalsForChartDetection: 0
m_ImportantGI: 0
m_StitchLightmapSeams: 1
m_SelectedEditorRenderState: 3
m_MinimumChartSize: 4
m_AutoUVMaxDistance: 0.5
m_AutoUVMaxAngle: 89
m_LightmapParameters: {fileID: 0}
m_SortingLayerID: 0
m_SortingLayer: 0
m_SortingOrder: 0
--- !u!33 &289856515
MeshFilter:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 289856511}
m_Mesh: {fileID: 10210, guid: 0000000000000000e000000000000000, type: 0}
--- !u!1 &336599934
GameObject:
m_ObjectHideFlags: 0
@ -360,7 +439,7 @@ Transform:
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 336599934}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: -1.704, y: 0.287, z: 0}
m_LocalPosition: {x: -4.33, y: 0.894, z: 1.465}
m_LocalScale: {x: 0.1, y: 0.3, z: 0.03}
m_Children: []
m_Father: {fileID: 0}
@ -845,7 +924,7 @@ Transform:
- {fileID: 1534265987}
- {fileID: 1235347441}
m_Father: {fileID: 0}
m_RootOrder: 6
m_RootOrder: 5
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!114 &1377711733
MonoBehaviour:
@ -978,6 +1057,85 @@ MeshFilter:
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1534265986}
m_Mesh: {fileID: 10202, guid: 0000000000000000e000000000000000, type: 0}
--- !u!1 &1759620710
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 1759620714}
- component: {fileID: 1759620713}
- component: {fileID: 1759620712}
m_Layer: 0
m_Name: Output
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!23 &1759620712
MeshRenderer:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1759620710}
m_Enabled: 1
m_CastShadows: 1
m_ReceiveShadows: 1
m_DynamicOccludee: 1
m_MotionVectors: 1
m_LightProbeUsage: 1
m_ReflectionProbeUsage: 1
m_RayTracingMode: 2
m_RenderingLayerMask: 1
m_RendererPriority: 0
m_Materials:
- {fileID: 2100000, guid: 8eeec989f878e94ecb0d1f05c401034c, type: 2}
m_StaticBatchInfo:
firstSubMesh: 0
subMeshCount: 0
m_StaticBatchRoot: {fileID: 0}
m_ProbeAnchor: {fileID: 0}
m_LightProbeVolumeOverride: {fileID: 0}
m_ScaleInLightmap: 1
m_ReceiveGI: 1
m_PreserveUVs: 0
m_IgnoreNormalsForChartDetection: 0
m_ImportantGI: 0
m_StitchLightmapSeams: 1
m_SelectedEditorRenderState: 3
m_MinimumChartSize: 4
m_AutoUVMaxDistance: 0.5
m_AutoUVMaxAngle: 89
m_LightmapParameters: {fileID: 0}
m_SortingLayerID: 0
m_SortingLayer: 0
m_SortingOrder: 0
--- !u!33 &1759620713
MeshFilter:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1759620710}
m_Mesh: {fileID: 10210, guid: 0000000000000000e000000000000000, type: 0}
--- !u!4 &1759620714
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1759620710}
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 1928596186}
m_RootOrder: 2
m_LocalEulerAnglesHint: {x: 0, y: -180, z: 0}
--- !u!1 &1829861728
GameObject:
m_ObjectHideFlags: 0
@ -989,6 +1147,7 @@ GameObject:
- component: {fileID: 1829861731}
- component: {fileID: 1829861730}
- component: {fileID: 1829861729}
- component: {fileID: 1829861732}
m_Layer: 0
m_Name: Main Camera
m_TagString: MainCamera
@ -1055,12 +1214,24 @@ Transform:
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1829861728}
m_LocalRotation: {x: 0, y: 1, z: 0, w: 0}
m_LocalPosition: {x: -1.5, y: 0.5, z: 1}
m_LocalPosition: {x: -2, y: 1, z: 1.5}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 180, z: 0}
--- !u!114 &1829861732
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1829861728}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 7c930f9c62136f05dae4987c3fc776d2, type: 3}
m_Name:
m_EditorClassIdentifier:
--- !u!1 &1928596179
GameObject:
m_ObjectHideFlags: 0
@ -1070,14 +1241,12 @@ GameObject:
serializedVersion: 6
m_Component:
- component: {fileID: 1928596186}
- component: {fileID: 1928596185}
- component: {fileID: 1928596184}
- component: {fileID: 1928596183}
- component: {fileID: 1928596182}
- component: {fileID: 1928596181}
- component: {fileID: 1928596180}
m_Layer: 0
m_Name: Lenia_Canvas
m_Name: Lenia
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
@ -1109,7 +1278,7 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: a37fd8d654d5c2840a0ab3a5ad65a5ae, type: 3}
m_Name:
m_EditorClassIdentifier:
spawnHeight: 0.5
spawnHeight: 1
useAdditionalValues: 0
syncValues: []
propPrivacy: 1
@ -1148,53 +1317,6 @@ BoxCollider:
serializedVersion: 2
m_Size: {x: 1, y: 1, z: 0.02}
m_Center: {x: 0, y: 0, z: 0}
--- !u!23 &1928596184
MeshRenderer:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1928596179}
m_Enabled: 1
m_CastShadows: 1
m_ReceiveShadows: 1
m_DynamicOccludee: 1
m_MotionVectors: 1
m_LightProbeUsage: 1
m_ReflectionProbeUsage: 1
m_RayTracingMode: 2
m_RenderingLayerMask: 1
m_RendererPriority: 0
m_Materials:
- {fileID: 2100000, guid: d3dc0619e4151e6b2b6b6b08038953f0, type: 2}
m_StaticBatchInfo:
firstSubMesh: 0
subMeshCount: 0
m_StaticBatchRoot: {fileID: 0}
m_ProbeAnchor: {fileID: 0}
m_LightProbeVolumeOverride: {fileID: 0}
m_ScaleInLightmap: 1
m_ReceiveGI: 1
m_PreserveUVs: 0
m_IgnoreNormalsForChartDetection: 0
m_ImportantGI: 0
m_StitchLightmapSeams: 1
m_SelectedEditorRenderState: 3
m_MinimumChartSize: 4
m_AutoUVMaxDistance: 0.5
m_AutoUVMaxAngle: 89
m_LightmapParameters: {fileID: 0}
m_SortingLayerID: 0
m_SortingLayer: 0
m_SortingOrder: 0
--- !u!33 &1928596185
MeshFilter:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1928596179}
m_Mesh: {fileID: 10210, guid: 0000000000000000e000000000000000, type: 0}
--- !u!4 &1928596186
Transform:
m_ObjectHideFlags: 0
@ -1203,12 +1325,14 @@ Transform:
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1928596179}
m_LocalRotation: {x: 0, y: -1, z: 0, w: 0}
m_LocalPosition: {x: -1.5, y: 0.5, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_LocalPosition: {x: -2, y: 1, z: 0}
m_LocalScale: {x: 2, y: 2, z: 2}
m_Children:
- {fileID: 2004190974}
- {fileID: 289856512}
- {fileID: 1759620714}
m_Father: {fileID: 0}
m_RootOrder: 4
m_RootOrder: 7
m_LocalEulerAnglesHint: {x: 0, y: -180, z: 0}
--- !u!1 &2004190973
GameObject:
@ -1221,7 +1345,7 @@ GameObject:
- component: {fileID: 2004190974}
- component: {fileID: 2004190975}
m_Layer: 0
m_Name: Lenia_Camera
m_Name: Camera
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
@ -1268,7 +1392,7 @@ Camera:
far clip plane: 0.02
field of view: 60
orthographic: 1
orthographic size: 0.5
orthographic size: 1
m_Depth: 0
m_CullingMask:
serializedVersion: 2
@ -1364,7 +1488,7 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: a37fd8d654d5c2840a0ab3a5ad65a5ae, type: 3}
m_Name:
m_EditorClassIdentifier:
spawnHeight: 0
spawnHeight: 0.3
useAdditionalValues: 0
syncValues: []
propPrivacy: 1
@ -1426,11 +1550,11 @@ Transform:
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 2044521647}
m_LocalRotation: {x: 0, y: 1, z: 0, w: 0}
m_LocalPosition: {x: -1.4943, y: 0.0817, z: 0.03585}
m_LocalScale: {x: 0.1, y: 0.1, z: 0.1}
m_LocalPosition: {x: -2.471, y: 0.543, z: 0.143}
m_LocalScale: {x: 0.123, y: 0.123, z: 0.123}
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 7
m_RootOrder: 6
m_LocalEulerAnglesHint: {x: 0, y: 180, z: 0}
--- !u!1 &2129299478
GameObject:
@ -1587,7 +1711,7 @@ Transform:
m_Children:
- {fileID: 1187452030}
m_Father: {fileID: 0}
m_RootOrder: 5
m_RootOrder: 4
m_LocalEulerAnglesHint: {x: 0, y: -180, z: 0}
--- !u!114 &2129299486
MonoBehaviour:

View file

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 9c5428b31e4ba7d119181b96ce168f1a
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View file

Before

Width:  |  Height:  |  Size: 3.5 KiB

After

Width:  |  Height:  |  Size: 3.5 KiB

View file

Before

Width:  |  Height:  |  Size: 1.2 KiB

After

Width:  |  Height:  |  Size: 1.2 KiB

View file

@ -0,0 +1,189 @@
Shader "CrispyPin/Lenia"
{
Properties
{
_LastFrame ("Texture", 2D) = "white" {}
// _Radius ("Radius", Range(1,100)) = 10
_GrowtCenter ("Growth fn center (mu)", Range(0, 1)) = 0.2
_GrowthWidth ("Growth fn width (sigma / std deviation)", Range(0, 1)) = 0.07
// _KSharpness ("Kernel sharpness", Range(1, 100)) = 2
// _KOffset ("Kernel offset", Range(0, 1)) = 0.2
_Speed ("Speed factor", Range(0.001, 0.5)) = 0.1
}
SubShader
{
Tags { "RenderType"="Opaque" }
LOD 100
Pass
{
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#include "UnityCG.cginc"
struct appdata
{
float4 vertex : POSITION;
float2 uv : TEXCOORD0;
};
struct v2f
{
float2 uv : TEXCOORD0;
float4 vertex : SV_POSITION;
};
sampler2D _LastFrame;
// int _Radius;
float _GrowtCenter;
float _GrowthWidth;
// float _KSharpness;
// float _KOffset;
float _Speed;
v2f vert (appdata v)
{
v2f o;
o.vertex = UnityObjectToClipPos(v.vertex);
o.uv = v.uv;
return o;
}
float kernel(float p) {
float r = p / 8.0;
float k_sharpness=28;
float k_offset =0.435;
return exp(-((r - k_offset) * (r - k_offset)) * k_sharpness);
// float r = p / _Radius;
// // -- normal
// return exp(-((r - _KOffset)*(r - _KOffset)) * _KSharpness);
// -- example from the lenia paper
// if (r >= 1) return 0;
// const float alpha = 4;
// return exp(alpha - alpha/(4.0 * r * (1.0 - r)));
}
inline float activation(float neighbors) {
// return old_state * (neighbors > 2 && neighbors < 5) +
// ((1 - old_state) * neighbors == 3);
// const float sharpness = 1000.0;
// float x = neighbors - _GrowtCenter;
// return exp(-(x*x) * _GrowthWidth) * 2.0 - 1.0;
const float mu = _GrowtCenter;
const float sigma = _GrowthWidth;
const float u = neighbors;
return exp(-((u-mu) * (u-mu)) / (2 * sigma * sigma)) * 2.0 - 1.0;
}
inline half value(float2 center, float x, float y) {
return tex2D(_LastFrame, center + float2(x, y)).r;
}
fixed4 frag (v2f i) : SV_Target
{
if(_ProjectionParams.z > 1) discard;
const float resolution = 512.0;
const float d = 1.0 / resolution;
// generated by the rust program
const int Radius = 16;
// /*
#define RADIUS 16
// kernel LUT size is 544 bytes
const half Kernel[17][16] = {
{0.0205, 0.0678, 0.1799, 0.3835, 0.6569, 0.9041, 0.9998, 0.8884, 0.6343, 0.3639, 0.1678, 0.0621, 0.0185, 0.0044, 0.0009, 0.0001, },
{0.0346, 0.0871, 0.2065, 0.4147, 0.6847, 0.9193, 0.9987, 0.8756, 0.6186, 0.3520, 0.1611, 0.0593, 0.0176, 0.0042, 0.0008, 0.0001, },
{0.0871, 0.1546, 0.2921, 0.5082, 0.7624, 0.9568, 0.9889, 0.8345, 0.5721, 0.3177, 0.1425, 0.0516, 0.0151, 0.0035, 0.0007, 0.0001, },
{0.2065, 0.2921, 0.4459, 0.6569, 0.8699, 0.9931, 0.9541, 0.7600, 0.4974, 0.2659, 0.1156, 0.0407, 0.0116, 0.0027, 0.0005, 0.0001, },
{0.4147, 0.5082, 0.6569, 0.8305, 0.9667, 0.9931, 0.8756, 0.6501, 0.4014, 0.2043, 0.0852, 0.0290, 0.0080, 0.0018, 0.0003, 0.0000, },
{0.6847, 0.7624, 0.8699, 0.9667, 0.9987, 0.9240, 0.7445, 0.5120, 0.2961, 0.1425, 0.0567, 0.0185, 0.0049, 0.0011, 0.0002, 0.0000, },
{0.9193, 0.9568, 0.9931, 0.9931, 0.9240, 0.7753, 0.5721, 0.3639, 0.1966, 0.0891, 0.0336, 0.0105, 0.0027, 0.0006, 0.0001, 0.0000, },
{0.9987, 0.9889, 0.9541, 0.8756, 0.7445, 0.5721, 0.3887, 0.2292, 0.1156, 0.0493, 0.0176, 0.0052, 0.0013, 0.0003, 0.0000, 0.0000, },
{0.8756, 0.8345, 0.7600, 0.6501, 0.5120, 0.3639, 0.2292, 0.1258, 0.0593, 0.0238, 0.0080, 0.0023, 0.0005, 0.0001, 0.0000, 0.0000, },
{0.6186, 0.5721, 0.4974, 0.4014, 0.2961, 0.1966, 0.1156, 0.0593, 0.0263, 0.0099, 0.0032, 0.0009, 0.0002, 0.0000, 0.0000, 0.0000, },
{0.3520, 0.3177, 0.2659, 0.2043, 0.1425, 0.0891, 0.0493, 0.0238, 0.0099, 0.0035, 0.0011, 0.0003, 0.0001, 0.0000, 0.0000, 0.0000, },
{0.1611, 0.1425, 0.1156, 0.0852, 0.0567, 0.0336, 0.0176, 0.0080, 0.0032, 0.0011, 0.0003, 0.0001, 0.0000, 0.0000, 0.0000, 0.0000, },
{0.0593, 0.0516, 0.0407, 0.0290, 0.0185, 0.0105, 0.0052, 0.0023, 0.0009, 0.0003, 0.0001, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, },
{0.0176, 0.0151, 0.0116, 0.0080, 0.0049, 0.0027, 0.0013, 0.0005, 0.0002, 0.0001, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, },
{0.0042, 0.0035, 0.0027, 0.0018, 0.0011, 0.0006, 0.0003, 0.0001, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, },
{0.0008, 0.0007, 0.0005, 0.0003, 0.0002, 0.0001, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, },
{0.0001, 0.0001, 0.0001, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, },
};
const float total_max = 234.37535;
float total = 0.0;
[unroll(RADIUS)]
for (int y = 0; y < Radius; y++) {
[unroll(RADIUS)]
for (int x = 1; x <= Radius; x++) {
const float xx = (float)x * d;
const float yy = (float)y * d;
total += value(i.uv, xx, yy) * Kernel[y][x-1];
total += value(i.uv, -yy, xx) * Kernel[y][x-1];
total += value(i.uv, -xx, -yy) * 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 count = total / total_max;
float state = activation(count) * _Speed + old_state;
state = clamp(state, 0, 1);
// // kernel visualization: lookup table
// float k = 0;
// {
// float2 p = (i.uv - 0.5 ) * resolution;
// p = floor(p);
// if (p.x > 0 && p.y >= 0) {
// k = Kernel[p.y][p.x-1];
// } else if (p.x <= 0 && p.y > 0) {
// k = Kernel[-p.x][p.y-1];
// } else if (p.x < 0 && p.y <= 0) {
// k = Kernel[-p.y][-p.x-1];
// } else if (p.x >= 0 && p.y < 0) {
// k = Kernel[p.x][-p.y-1];
// }
// }
// float2 p = (i.uv - 0.5) * resolution;
// float k = kernel(length(p)) * (max(abs(p.x), abs(p.y)) <= _Radius); // kernel visualisation: real size
// float k = kernel(length(i.uv - 0.5) * _Radius * 2); // kernel visualisation: fill square
// float a = activation(i.uv.x);
// float4 col = float4(state, k, a, 1);
// float4 col = float4(state, k, k2, 1);
// float4 col = float4(state, state * 0.5, 0, 1);
// float4 col = float4(state, i.uv.x * state, i.uv.y * state, 1);
float4 col = state;
col.a = 1;
return col;
}
ENDCG
}
}
}

View file

@ -0,0 +1,97 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!21 &2100000
Material:
serializedVersion: 6
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_Name: lenia_out
m_Shader: {fileID: 211, guid: 0000000000000000f000000000000000, type: 0}
m_ShaderKeywords:
m_LightmapFlags: 0
m_EnableInstancingVariants: 0
m_DoubleSidedGI: 0
m_CustomRenderQueue: -1
stringTagMap: {}
disabledShaderPasses:
- ALWAYS
m_SavedProperties:
serializedVersion: 3
m_TexEnvs:
- _BumpMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _DetailAlbedoMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _DetailMask:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _DetailNormalMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _EmissionMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _MainTex:
m_Texture: {fileID: 8400000, guid: b8b62218c9d4ca16f887e8ae9d9d2942, type: 2}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _MetallicGlossMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _OcclusionMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _ParallaxMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
m_Floats:
- _BlendOp: 0
- _BumpScale: 1
- _CameraFadingEnabled: 0
- _CameraFarFadeDistance: 2
- _CameraNearFadeDistance: 1
- _ColorMode: 0
- _Cull: 2
- _Cutoff: 0.5
- _DetailNormalMapScale: 1
- _DistortionBlend: 0.5
- _DistortionEnabled: 0
- _DistortionStrength: 1
- _DistortionStrengthScaled: 0
- _DstBlend: 0
- _EmissionEnabled: 0
- _FlipbookMode: 0
- _GlossMapScale: 1
- _Glossiness: 0.5
- _GlossyReflections: 1
- _LightingEnabled: 0
- _Metallic: 0
- _Mode: 0
- _OcclusionStrength: 1
- _Parallax: 0.02
- _SmoothnessTextureChannel: 0
- _SoftParticlesEnabled: 0
- _SoftParticlesFarFadeDistance: 1
- _SoftParticlesNearFadeDistance: 0
- _SpecularHighlights: 1
- _SrcBlend: 1
- _UVSec: 0
- _ZWrite: 1
m_Colors:
- _CameraFadeParams: {r: 0, g: Infinity, b: 0, a: 0}
- _Color: {r: 2, g: 2, b: 2, a: 1}
- _ColorAddSubDiff: {r: 0, g: 0, b: 0, a: 0}
- _EmissionColor: {r: 0, g: 0, b: 0, a: 1}
- _SoftParticleFadeParams: {r: 0, g: 0, b: 0, a: 0}

View file

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 8eeec989f878e94ecb0d1f05c401034c
NativeFormatImporter:
externalObjects: {}
mainObjectFileID: 2100000
userData:
assetBundleName:
assetBundleVariant:

View file

@ -13,8 +13,8 @@ RenderTexture:
m_ForcedFallbackFormat: 4
m_DownscaleFallback: 0
serializedVersion: 3
m_Width: 256
m_Height: 256
m_Width: 512
m_Height: 512
m_AntiAliasing: 1
m_MipCount: -1
m_DepthFormat: 0

View file

@ -7,7 +7,7 @@ Material:
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_Name: lenia
m_Name: lenia_sim
m_Shader: {fileID: 4800000, guid: 2ce832468d1053a50b5dc09a9689af26, type: 3}
m_ShaderKeywords:
m_LightmapFlags: 4

View file

@ -1,141 +0,0 @@
Shader "CrispyPin/Lenia"
{
Properties
{
_LastFrame ("Texture", 2D) = "white" {}
_Radius ("Radius", Range(1,100)) = 10
_GrowtCenter ("Growth fn center (mu)", Range(0, 1)) = 0.2
_GrowthWidth ("Growth fn width (sigma / std deviation)", Range(0, 1)) = 0.07
_KSharpness ("Kernel sharpness", Range(1, 100)) = 2
_KOffset ("Kernel offset", Range(0, 1)) = 0.2
_Speed ("Speed factor", Range(0.001, 1)) = 0.1
}
SubShader
{
Tags { "RenderType"="Opaque" }
LOD 100
Pass
{
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#include "UnityCG.cginc"
struct appdata
{
float4 vertex : POSITION;
float2 uv : TEXCOORD0;
};
struct v2f
{
float2 uv : TEXCOORD0;
float4 vertex : SV_POSITION;
};
sampler2D _LastFrame;
int _Radius;
float _GrowtCenter;
float _GrowthWidth;
float _KSharpness;
float _KOffset;
float _Speed;
v2f vert (appdata v)
{
v2f o;
o.vertex = UnityObjectToClipPos(v.vertex);
o.uv = v.uv;
return o;
}
float kernel(float p) {
float r = p / _Radius;
// -- example from the lenia paper
// if (r >= 1) return 0;
// const float alpha = 4;
// return exp(alpha - alpha/(4.0 * r * (1.0 - r)));
// -- forgor
// return exp(-((r-0.5)*(r-0.5))*25);
// -- circle :)
// return r < 1 && r > 0.2;
// -- adjustable hard circle
// float a = _KOffset+_KSharpness;
// float b =_KOffset -_KSharpness;
// return r < a && r > b;
// -- normal
return exp(-((r - _KOffset)*(r - _KOffset)) * _KSharpness);
}
float activation(float neighbors) {
// return old_state * (neighbors > 2 && neighbors < 5) +
// ((1 - old_state) * neighbors == 3);
// const float sharpness = 1000.0;
// float x = neighbors - _GrowtCenter;
// return exp(-(x*x) * _GrowthWidth) * 2.0 - 1.0;
float mu = _GrowtCenter;
float sigma = _GrowthWidth;
float u = neighbors;
// float u = neighbors - _GrowtCenter;
return exp(-((u-mu) * (u-mu)) / (2 * sigma * sigma)) * 2.0 - 1.0;
}
half value(float2 center, float x, float y) {
return tex2D(_LastFrame, center + float2(x, y)).r;
}
fixed4 frag (v2f i) : SV_Target
{
const float resolution = 256.0;
const float d = 1.0 / resolution;
float total_max = 0.0; // TODO replace with const?
float total = 0.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 count = total / total_max;
float state = activation(count) * _Speed + old_state;
state = clamp(state, 0, 1);
// float2 p = (i.uv - 0.5) * resolution;
// float k = kernel(length(p)) * (max(abs(p.x), abs(p.y)) <= _Radius); // kernel visualisation: real size
// // float k = kernel(length(i.uv - 0.5) * _Radius * 2); // kernel visualisation: fill square
// float a = activation(i.uv.x);
// float4 col = float4(state, k, a, 1);
// float4 col = float4(state, state * 0.5, 0, 1);
float4 col = float4(state, i.uv.x * state, i.uv.y * state, 1);
// float4 col = state;
// col.a = 1;
return col;
}
ENDCG
}
}
}

View file

@ -0,0 +1,20 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class UnlimitFPS : MonoBehaviour
{
// Start is called before the first frame update
void Start()
{
Application.targetFrameRate = 0;
QualitySettings.vSyncCount = 0;
Debug.Log("unlocked fps");
}
// Update is called once per frame
void Update()
{
}
}

View file

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 7c930f9c62136f05dae4987c3fc776d2
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View file

@ -18,7 +18,7 @@ QualitySettings:
shadowCascade2Split: 0.33333334
shadowCascade4Split: {x: 0.06666667, y: 0.2, z: 0.46666667}
shadowmaskMode: 0
blendWeights: 1
skinWeights: 1
textureQuality: 1
anisotropicTextures: 0
antiAliasing: 0
@ -40,6 +40,7 @@ QualitySettings:
asyncUploadBufferSize: 16
asyncUploadPersistentBuffer: 1
resolutionScalingFixedDPIFactor: 1
customRenderPipeline: {fileID: 0}
excludedTargetPlatforms: []
- serializedVersion: 2
name: Low
@ -53,7 +54,7 @@ QualitySettings:
shadowCascade2Split: 0.33333334
shadowCascade4Split: {x: 0.06666667, y: 0.2, z: 0.46666667}
shadowmaskMode: 0
blendWeights: 2
skinWeights: 2
textureQuality: 0
anisotropicTextures: 0
antiAliasing: 0
@ -75,6 +76,7 @@ QualitySettings:
asyncUploadBufferSize: 16
asyncUploadPersistentBuffer: 1
resolutionScalingFixedDPIFactor: 1
customRenderPipeline: {fileID: 0}
excludedTargetPlatforms: []
- serializedVersion: 2
name: Medium
@ -88,7 +90,7 @@ QualitySettings:
shadowCascade2Split: 0.33333334
shadowCascade4Split: {x: 0.06666667, y: 0.2, z: 0.46666667}
shadowmaskMode: 0
blendWeights: 2
skinWeights: 2
textureQuality: 0
anisotropicTextures: 1
antiAliasing: 0
@ -110,6 +112,7 @@ QualitySettings:
asyncUploadBufferSize: 16
asyncUploadPersistentBuffer: 1
resolutionScalingFixedDPIFactor: 1
customRenderPipeline: {fileID: 0}
excludedTargetPlatforms: []
- serializedVersion: 2
name: High
@ -123,7 +126,7 @@ QualitySettings:
shadowCascade2Split: 0.33333334
shadowCascade4Split: {x: 0.06666667, y: 0.2, z: 0.46666667}
shadowmaskMode: 1
blendWeights: 2
skinWeights: 2
textureQuality: 0
anisotropicTextures: 1
antiAliasing: 0
@ -145,6 +148,7 @@ QualitySettings:
asyncUploadBufferSize: 16
asyncUploadPersistentBuffer: 1
resolutionScalingFixedDPIFactor: 1
customRenderPipeline: {fileID: 0}
excludedTargetPlatforms: []
- serializedVersion: 2
name: Very High
@ -158,7 +162,7 @@ QualitySettings:
shadowCascade2Split: 0.33333334
shadowCascade4Split: {x: 0.06666667, y: 0.2, z: 0.46666667}
shadowmaskMode: 1
blendWeights: 4
skinWeights: 4
textureQuality: 0
anisotropicTextures: 2
antiAliasing: 2
@ -180,6 +184,7 @@ QualitySettings:
asyncUploadBufferSize: 16
asyncUploadPersistentBuffer: 1
resolutionScalingFixedDPIFactor: 1
customRenderPipeline: {fileID: 0}
excludedTargetPlatforms: []
- serializedVersion: 2
name: Ultra
@ -193,7 +198,7 @@ QualitySettings:
shadowCascade2Split: 0.33333334
shadowCascade4Split: {x: 0.06666667, y: 0.2, z: 0.46666667}
shadowmaskMode: 1
blendWeights: 4
skinWeights: 4
textureQuality: 0
anisotropicTextures: 2
antiAliasing: 2
@ -201,7 +206,7 @@ QualitySettings:
softVegetation: 1
realtimeReflectionProbes: 1
billboardsFaceCameraPosition: 1
vSyncCount: 1
vSyncCount: 0
lodBias: 2
maximumLODLevel: 0
streamingMipmapsActive: 0
@ -215,6 +220,7 @@ QualitySettings:
asyncUploadBufferSize: 16
asyncUploadPersistentBuffer: 1
resolutionScalingFixedDPIFactor: 1
customRenderPipeline: {fileID: 0}
excludedTargetPlatforms: []
m_PerPlatformDefaultQuality:
Android: 2

2
lenia-kernel/.gitignore vendored Normal file
View file

@ -0,0 +1,2 @@
target/
Cargo.lock

8
lenia-kernel/Cargo.toml Normal file
View file

@ -0,0 +1,8 @@
[package]
name = "lenia-kernel"
version = "0.1.0"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]

View file

@ -0,0 +1 @@
hard_tabs = true

43
lenia-kernel/src/main.rs Normal file
View file

@ -0,0 +1,43 @@
use std::env;
fn main() {
let args: Vec<_> = env::args().skip(1).collect();
if args.is_empty() {
println!("usage: kernel_radius");
return;
}
let radius = args[0].parse().unwrap();
let k_offset = 0.435;
let k_sharpness = 28.0;
let mut total_max = 0.0;
println!(" // generated by the rust program");
println!(" const int Radius = {};", radius);
println!(" #define RADIUS {}", radius);
println!(" // kernel LUT size is {} bytes", radius * (radius + 1) * 2);
println!(" const half 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);
total_max += k * 4.0;
print!("{:.4}, ", k);
}
println!("}},");
}
println!(" }};");
println!(" const float TOTAL_MAX = {};", total_max);
}
fn k(x: usize, y: usize, radius: usize, k_offset: f32, k_sharpness: f32) -> 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)
// lenia paper example kernel
// if r < 1.0 {
// f32::exp(4.0 - 4.0 / (4.0 * r * (1.0 - r)))
// } else {
// 0.0
// }
}