/*
 * Copyright (c) Contributors to the Open 3D Engine Project.
 * For complete copyright and license terms please see the LICENSE at the root of this distribution.
 *
 * SPDX-License-Identifier: Apache-2.0 OR MIT
 *
 */

/*
* Julia Fractals
* The Julia set is the set of points x in the complex plane such that f(x) = z^2 + c converges to zero. 
* We change the value of c (seed) over time, which creates the animation.
*/

#include "Compute.azsli"


[numthreads(16,4,1)]
void MainCS(uint3 thread_id: SV_DispatchThreadID)
{
    static const int iter = 128;
    float2 z = 2.0 * float2(thread_id.xy) / ConstantSrg::dimension - 1.0;

    int count = iter;
    for(int i = 0; i < iter; ++i)
    {
        z = float2(z.x*z.x - z.y*z.y, 2.0*z.x*z.y) + ConstantSrg::seed;
        if(dot(z,z) > 4.0)
        {
            count = i;
            break;
        }
    }

    float value = float(count)/float(iter) ;
    int index = thread_id.y * int(ConstantSrg::dimension.x) + thread_id.x;
    BufferSrg::m_computeBuffer[index].m_data = float4(value, value, value, 1.0);
}