Skip to content

Instantly share code, notes, and snippets.

@amygoodchild
Created January 11, 2020 23:49
Show Gist options
  • Save amygoodchild/05c7cf7be5e0278489daaaab2974037e to your computer and use it in GitHub Desktop.
Save amygoodchild/05c7cf7be5e0278489daaaab2974037e to your computer and use it in GitHub Desktop.
[numthreads(1, 1, 1)]
void StepKernel(uint3 id: SV_DispatchThreadID)
{
// READ STATE
uint state = readTex[id.xy];
uint count0 = 0;
uint count1 = 0;
uint count2 = 0;
uint count3 = 0;
//uint next = state + 1 == nstates ? 0 : state + 1; // (preserves higher states)
for (int i=0; i < 128; i++){
uint s = readTex.SampleLevel(sampler_readTex, (id.xy + neighborhood0[i]) / (float)rez, 0);
count0 += (uint) (s==1);
s = readTex.SampleLevel(sampler_readTex, (id.xy + neighborhood1[i]) / (float)rez, 0);
count1 += (uint) (s==1);
s = readTex.SampleLevel(sampler_readTex, (id.xy + neighborhood2[i]) / (float)rez, 0);
count2 += (uint) (s==1);
s = readTex.SampleLevel(sampler_readTex, (id.xy + neighborhood3[i]) / (float)rez, 0);
count3 += (uint) (s==1);
}
// RULES
if (count0 <= 17) { state = 0; }
if (count0 >= 40 && count0 <= 42) { state=1; }
if (count1 >= 10 && count1 <= 13) { state=1; }
if (count2 >= 9 && count2 <= 21) { state = 0; }
if (count3 >= 78 && count3 <= 89) { state = 0; }
if (count3 >= 108) { state = 0; }
// WRITE STATE
writeTex[id.xy] = state;
Render(id, state, count0);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment