kiyo 0.0.7

Lightweight compute shader playground
Documentation
#version 450

/*
 * Kiyo data
 * - WORKGROUP_SIZE and NUM_IMAGES are provided by the engine
 */

layout ( local_size_x = WORKGROUP_SIZE, local_size_y = WORKGROUP_SIZE, local_size_z = 1 ) in;
layout( binding = 0, rgba8 ) uniform image2D images[NUM_IMAGES];
layout( push_constant ) uniform PushConstants
{
    float time;
    int in_image;
    int out_image;
} constants;

/*
 * User data
 */

vec3 palette( in float t, in vec3 a, in vec3 b, in vec3 c, in vec3 d )
{
    return a + b*cos( 6.28318*(c*t+d) );
}

void main()
{
    ivec2 p = ivec2( gl_GlobalInvocationID.xy );
    ivec2 screenSize = imageSize( images[ constants.out_image ] );
    if( p.x > screenSize.x || p.y > screenSize.y )
    {
        return;
    }

    vec2 pos = vec2( float( p.x ) / float( screenSize.x ), float( p.y ) / float( screenSize.y ) ) - 0.5f;

    if( fract( constants.time / 20. ) < 0.06f )
    {
        float t = constants.time * .3f + 0.5f * length( pos );
        vec3 color = palette(
            sin( pos.x * .2f / pos.y ) * 10.0f + constants.time,
            vec3( 2.5, 1.1, 0.3 ),
            vec3( 0.5, 0.5, 0.5 ),
            vec3( 2.0, 0.5, 0.5 ),
            vec3( 0.5, 0.30, 0.25 )
        );

        if( length( pos ) < 0.1f )
        {
            color = vec3( 1.0, 1.0, 1.0 );
        }

        color.r = cos( pos.x * sin( 2. * pos.y ) );
        imageStore( images[ constants.out_image ], p, vec4( color, 1 ) );
    }
}