Untitled diff

Created Diff never expires
20 削除
合計
削除
単語
合計
削除
この機能を引き続き使用するには、アップグレードしてください
Diffchecker logo
Diffchecker Pro
88
20 追加
合計
追加
単語
合計
追加
この機能を引き続き使用するには、アップグレードしてください
Diffchecker logo
Diffchecker Pro
88
#version 450
#version 450


#define WIDTH 800
#define WIDTH 800
#define HEIGHT 600
#define HEIGHT 600
#define WORKGROUP_SIZE 32
#define WORKGROUP_SIZE 32


layout (local_size_x = WORKGROUP_SIZE, local_size_y = WORKGROUP_SIZE, local_size_z = 1) in;
layout (local_size_x = WORKGROUP_SIZE, local_size_y = WORKGROUP_SIZE, local_size_z = 1) in;


layout(binding = 0) readonly buffer buf1 {
layout(binding = 0) readonly buffer buf1 {
int data[WIDTH][HEIGHT];
int data[HEIGHT][WIDTH];
} previousBoard;
} previousBoard;


layout(binding = 1) buffer buf2 {
layout(binding = 1) buffer buf2 {
int data[WIDTH][HEIGHT];
int data[HEIGHT][WIDTH];
} nextBoard;
} nextBoard;


void main() {
void main() {


int x = int(gl_GlobalInvocationID.x);
int x = int(gl_GlobalInvocationID.x);
int y = int(gl_GlobalInvocationID.y);
int y = int(gl_GlobalInvocationID.y);


if(x >= WIDTH || y >= HEIGHT)
if(x >= WIDTH || y >= HEIGHT)
return;
return;
uint countNeighboors = 0;
uint countNeighboors = 0;
if (y > 0)
if (y > 0)
{
{
if (x > 0)
if (x > 0)
{
{
// x - 1 ; y - 1
// x - 1 ; y - 1
countNeighboors += previousBoard.data[x - 1][y - 1];
countNeighboors += previousBoard.data[y - 1][x - 1];
}
}
// x ; y - 1
// x ; y - 1
countNeighboors += previousBoard.data[x][y - 1];
countNeighboors += previousBoard.data[y - 1][x];
if(x < 799)
if(x < 799)
{
{
// x + 1 ; y - 1
// x + 1 ; y - 1
countNeighboors += previousBoard.data[x + 1][y - 1];
countNeighboors += previousBoard.data[y - 1][x + 1];
}
}
}
}
if (x > 0)
if (x > 0)
{
{
// x - 1 ; y
// x - 1 ; y
countNeighboors += previousBoard.data[x - 1][y];
countNeighboors += previousBoard.data[y][x - 1];
}
}
if(x < 799)
if(x < 799)
{
{
// x + 1 ; y
// x + 1 ; y
countNeighboors += previousBoard.data[x + 1][y];
countNeighboors += previousBoard.data[y][x + 1];
}
}
if (y < 599)
if (y < 599)
{
{
if (x > 0)
if (x > 0)
{
{
// x - 1 ; y + 1
// x - 1 ; y + 1
countNeighboors += previousBoard.data[x - 1][y + 1];
countNeighboors += previousBoard.data[y + 1][x - 1];
}
}
// x ; y + 1
// x ; y + 1
countNeighboors += previousBoard.data[x][y + 1];
countNeighboors += previousBoard.data[y + 1][x];
if(x < 799)
if(x < 799)
{
{
// x + 1 ; y + 1
// x + 1 ; y + 1
countNeighboors += previousBoard.data[x + 1][y + 1];
countNeighboors += previousBoard.data[y + 1][x + 1];
}
}
}
}
if(countNeighboors == 3)
if(countNeighboors == 3)
{
{
nextBoard.data[x][y] = 1;
nextBoard.data[y][x] = 1;
}
}
else if (countNeighboors == 2)
else if (countNeighboors == 2)
{
{
nextBoard.data[x][y] = previousBoard.data[x][y];
nextBoard.data[y][x] = previousBoard.data[y][x];
}
}
else
else
{
{
nextBoard.data[x][y] = 0;
nextBoard.data[y][x] = 0;
}
}
}
}