75 lines
1.3 KiB
GLSL
75 lines
1.3 KiB
GLSL
Shader "CrispyPin/gol"
|
|
{
|
|
Properties
|
|
{
|
|
[NoScaleOffset]
|
|
_LastFrame ("Render texture", 2D) = "white" {}
|
|
}
|
|
SubShader
|
|
{
|
|
Tags { "RenderType"="Opaque" }
|
|
LOD 100
|
|
|
|
Pass
|
|
{
|
|
CGPROGRAM
|
|
#pragma vertex vert
|
|
#pragma fragment frag
|
|
|
|
#include "UnityCG.cginc"
|
|
|
|
#define WIDTH 256
|
|
|
|
struct appdata
|
|
{
|
|
float4 vertex : POSITION;
|
|
float2 uv : TEXCOORD0;
|
|
};
|
|
|
|
struct v2f
|
|
{
|
|
float2 uv : TEXCOORD0;
|
|
float4 vertex : SV_POSITION;
|
|
};
|
|
|
|
texture2D _LastFrame;
|
|
|
|
v2f vert (appdata v)
|
|
{
|
|
v2f o;
|
|
o.vertex = UnityObjectToClipPos(v.vertex);
|
|
o.uv = v.uv;
|
|
return o;
|
|
}
|
|
|
|
inline half state(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)].b > 0;
|
|
}
|
|
|
|
fixed3 frag (v2f i) : SV_Target
|
|
{
|
|
if(_ProjectionParams.z > 1) discard;
|
|
|
|
const uint2 p = i.uv * WIDTH;
|
|
half count =
|
|
state(p, -1, -1) +
|
|
state(p, 0, -1) +
|
|
state(p, 1, -1) +
|
|
state(p, -1, 0) +
|
|
state(p, 1, 0) +
|
|
state(p, -1, 1) +
|
|
state(p, 0, 1) +
|
|
state(p, 1, 1);
|
|
half prev = _LastFrame[p].b > 0;
|
|
|
|
half next = count == 3 || ((count == 2) && prev);
|
|
|
|
return fixed3(i.uv * next, next * (_SinTime.y * 0.4 + 0.6));
|
|
}
|
|
ENDCG
|
|
}
|
|
}
|
|
}
|