init
This commit is contained in:
@@ -0,0 +1,46 @@
|
||||
/* Copyright (c) 2021, Arm Limited and Contributors
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 the "License";
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#version 450
|
||||
layout(local_size_x = 8, local_size_y = 8) in;
|
||||
|
||||
layout(set = 0, binding = 0, rgba8) writeonly uniform image2D Image;
|
||||
|
||||
void main()
|
||||
{
|
||||
ivec2 index = ivec2(gl_GlobalInvocationID.xy);
|
||||
bool is_alive;
|
||||
|
||||
// Create an arbitrary pattern which happens to create a desirable result.
|
||||
|
||||
ivec2 mask = mix(ivec2(3), ivec2(7), notEqual(index & 16, ivec2(0)));
|
||||
|
||||
ivec2 wrapped_index = index & mask;
|
||||
if (all(equal(wrapped_index, ivec2(1, 0))) ||
|
||||
all(equal(wrapped_index, ivec2(2, 1))) ||
|
||||
all(equal(wrapped_index, ivec2(0, 2))) ||
|
||||
all(equal(wrapped_index, ivec2(1, 2))) ||
|
||||
all(equal(wrapped_index, ivec2(2, 2))))
|
||||
{
|
||||
is_alive = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
is_alive = false;
|
||||
}
|
||||
|
||||
imageStore(Image, index, is_alive ? vec4(1.0, 1.0, 1.0, 0.0) : vec4(0.0));
|
||||
}
|
||||
Binary file not shown.
@@ -0,0 +1,39 @@
|
||||
/* Copyright (c) 2021, Arm Limited and Contributors
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 the "License";
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#version 450
|
||||
layout(local_size_x = 8, local_size_y = 8) in;
|
||||
|
||||
layout(rgba8, set = 0, binding = 0) writeonly uniform image2D ImageOutput;
|
||||
layout(set = 1, binding = 0) uniform sampler2D ImageInput;
|
||||
|
||||
layout(push_constant) uniform Registers
|
||||
{
|
||||
float counter;
|
||||
} registers;
|
||||
|
||||
void main()
|
||||
{
|
||||
vec4 v = texelFetch(ImageInput, ivec2(gl_GlobalInvocationID.xy), 0);
|
||||
|
||||
// Increase intensity over time until the cell dies.
|
||||
if (any(notEqual(v.rgb, vec3(0.0))))
|
||||
v.w = max(v.w, registers.counter);
|
||||
else
|
||||
v.w = 0.0;
|
||||
|
||||
imageStore(ImageOutput, ivec2(gl_GlobalInvocationID.xy), v);
|
||||
}
|
||||
Binary file not shown.
@@ -0,0 +1,77 @@
|
||||
/* Copyright (c) 2021, Arm Limited and Contributors
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 the "License";
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#version 450
|
||||
layout(local_size_x = 8, local_size_y = 8) in;
|
||||
|
||||
layout(set = 0, binding = 0, rgba8) writeonly uniform image2D ImageOutput;
|
||||
layout(set = 1, binding = 0) uniform sampler2D ImageInput;
|
||||
|
||||
void main()
|
||||
{
|
||||
ivec2 index = ivec2(gl_GlobalInvocationID.xy);
|
||||
vec2 uv = (vec2(index) + 0.5) / vec2(textureSize(ImageInput, 0));
|
||||
int neighbors = 0;
|
||||
|
||||
vec4 self = textureLod(ImageInput, uv, 0.0);
|
||||
bool is_alive = any(notEqual(self.rgb, vec3(0.0)));
|
||||
vec3 total = self.rgb;
|
||||
|
||||
#define CHECK_OFFSET(x, y) { \
|
||||
vec3 tmp; \
|
||||
tmp = textureLodOffset(ImageInput, uv, 0.0, ivec2(x, y)).rgb; \
|
||||
if (any(notEqual(tmp, vec3(0.0)))) { \
|
||||
neighbors++; \
|
||||
total += tmp.rgb; \
|
||||
} \
|
||||
}
|
||||
CHECK_OFFSET(-1, -1)
|
||||
CHECK_OFFSET( 0, -1)
|
||||
CHECK_OFFSET(+1, -1)
|
||||
CHECK_OFFSET(-1, 0)
|
||||
CHECK_OFFSET(+1, 0)
|
||||
CHECK_OFFSET(-1, +1)
|
||||
CHECK_OFFSET( 0, +1)
|
||||
CHECK_OFFSET(+1, +1)
|
||||
|
||||
if (is_alive)
|
||||
{
|
||||
is_alive = neighbors == 2u || neighbors == 3u;
|
||||
if (is_alive)
|
||||
{
|
||||
total /= float(neighbors);
|
||||
}
|
||||
else
|
||||
{
|
||||
total = vec3(0.0);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
is_alive = neighbors == 3u;
|
||||
if (is_alive)
|
||||
{
|
||||
vec3 fresh_color = vec3(uv.x, uv.y, 1.0 - uv.x - uv.y);
|
||||
total = fresh_color;
|
||||
}
|
||||
else
|
||||
{
|
||||
total = vec3(0.0);
|
||||
}
|
||||
}
|
||||
|
||||
imageStore(ImageOutput, index, vec4(total, 0.0));
|
||||
}
|
||||
Binary file not shown.
@@ -0,0 +1,32 @@
|
||||
/* Copyright (c) 2021, Arm Limited and Contributors
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 the "License";
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#version 450
|
||||
|
||||
layout(set = 0, binding = 0) uniform sampler2D in_image;
|
||||
layout(location = 0) in vec2 in_uv;
|
||||
layout(location = 0) out vec4 out_color;
|
||||
|
||||
vec4 convert_color(vec4 value)
|
||||
{
|
||||
float gray = dot(value.rgb, vec3(0.3, 0.6, 0.1));
|
||||
return vec4(mix(vec3(gray), value.rgb, value.a), 1.0);
|
||||
}
|
||||
|
||||
void main()
|
||||
{
|
||||
out_color = convert_color(textureLod(in_image, in_uv, 0.0));
|
||||
}
|
||||
Binary file not shown.
@@ -0,0 +1,31 @@
|
||||
/* Copyright (c) 2021, Arm Limited and Contributors
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 the "License";
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#version 450
|
||||
|
||||
layout(location = 0) out vec2 out_uv;
|
||||
|
||||
void main()
|
||||
{
|
||||
if (gl_VertexIndex == 0)
|
||||
gl_Position = vec4(-1.0, -1.0, 0.0, 1.0);
|
||||
else if (gl_VertexIndex == 1)
|
||||
gl_Position = vec4(-1.0, 3.0, 0.0, 1.0);
|
||||
else
|
||||
gl_Position = vec4(3.0, -1.0, 0.0, 1.0);
|
||||
|
||||
out_uv = gl_Position.xy * 0.5 + 0.5;
|
||||
}
|
||||
Binary file not shown.
Reference in New Issue
Block a user