How to build

  1. Install Visual Studio Community 2015.
  2. Install Boost Library Windows binaries from http://sourceforge.net/projects/boost/files/boost-binaries/1.59.0/ (boost1590-msvc-14.0-32.exe, boost1590-msvc-14.0-64.exe)
  3. Install WiX toolset http://wixtoolset.org/.
  4. Check paths in the property files ("GameOfLife3D/props/boost*.props" and "WindowsSDK_*.props")
  5. Download the source codes of Game of Life 3D and open them with Visual Studio.

How to write DirectX Compute Shader for Game of Life

Note for GPUs without Compute Shader

Game of Life 3D uses Compute Shader or CPU to calculate the rules of game. If GPU does not support Compute Shader, it select CPU based engine. In this case, you can not load your compute shader file.
However Game of Life 3D also support 'Reference DirectX Adapter' which is included in Direct X SDK. If you don't have GPU with Compute Shader, but want to write your rules, please install DirectX SDK.

Load an external Compute Shader file.

In order to load an external Compute Shader file, select "Advance"->"Open CS File" button. In the opened file dialog, select your Compute Shader file.
opencsfile.png

Simplest compute shader

This compute shader simply copy current generation cells to next generation cells.
cbuffer CBParams : register(b0)
{
	int width;
	int height;
	int r1;
	int r2;
	int r3;
	int r4;
};

struct Data {
	int alive;
	float3 color;
};

StructuredBuffer<Data> current : register(t0);
RWStructuredBuffer<Data> next : register(t1);

[numthreads(1, 1, 1)]
void main( uint3 tid : SV_DispatchThreadID )
{
        next[tid.x] = current[tid.x];
}
The result of this shader is:
simplest001.png

Change colors

In order to change colors, set color property of next generation cells.
cbuffer CBParams : register(b0)
{
	int width;
	int height;
	int r1;
	int r2;
	int r3;
	int r4;
};

struct Data {
	int alive;
	float3 color;
};

StructuredBuffer<Data> current : register(t0);
RWStructuredBuffer<Data> next : register(t1);

[numthreads(1, 1, 1)]
void main( uint3 tid : SV_DispatchThreadID )
{
        next[tid.x] = current[tid.x];
        next[tid.x].color = float3(1.0f, 0.0f, 0.0f);
}
The result of this shader is:
changecolor001.png

Conway's rules

This is the implementaion of Conway's natural rules.
static const int2 g_sumIndex[8] = {
    {-1, -1},
    { 0, -1},
    { 1, -1},
    {-1,  0},
    { 1,  0},
    {-1,  1},
    { 0,  1},
    { 1,  1},
};

cbuffer CBParams : register(b0)
{
	int width;
	int height;
	int r1;
	int r2;
	int r3;
	int r4;
};

struct Data {
	int alive;
	float3 color;
};

StructuredBuffer<Data> current : register(t0);
RWStructuredBuffer<Data> next : register(t1);

[numthreads(1, 1, 1)]
void main( uint3 tid : SV_DispatchThreadID )
{
	int cx = tid.x % width;
	int cy = tid.x / width;

	int sum = 0;
	for(int i = 0; i < 8; ++i) {
		int x = cx + g_sumIndex[i].x;
		int y = cy + g_sumIndex[i].y;
		if(0 <= x && x < width && 0 <= y && y < height) {
			int id = x + y * width;
			if(current[id].alive != 0) {
				sum++;
			}
		}
	}

	if(current[tid.x].alive == 0 && sum >= 3 && sum <= 3) {
		next[tid.x].alive = 1;
		next[tid.x].color = float3(1.0f, 1.0f, 1.0f);
	}
	else if(current[tid.x].alive != 0 && (sum > 3 || sum < 2)) {
		next[tid.x].alive = 0;
		next[tid.x].color = 0.0f;
	}
	else {
		next[tid.x].alive = current[tid.x].alive;
		next[tid.x].color = current[tid.x].color;
	}
}
The result of this shader is:
conways001.png

Last edited Sep 22, 2015 at 6:51 AM by yohei_yoshihara, version 27

Comments

No comments yet.