ComputeDispatch.azsl 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. /*
  2. * Copyright (c) Contributors to the Open 3D Engine Project.
  3. * For complete copyright and license terms please see the LICENSE at the root of this distribution.
  4. *
  5. * SPDX-License-Identifier: Apache-2.0 OR MIT
  6. *
  7. */
  8. /*
  9. * Julia Fractals
  10. * The Julia set is the set of points x in the complex plane such that f(x) = z^2 + c converges to zero.
  11. * We change the value of c (seed) over time, which creates the animation.
  12. */
  13. #include "Compute.azsli"
  14. [numthreads(16,4,1)]
  15. void MainCS(uint3 thread_id: SV_DispatchThreadID)
  16. {
  17. static const int iter = 128;
  18. float2 z = 2.0 * float2(thread_id.xy) / ConstantSrg::dimension - 1.0;
  19. int count = iter;
  20. for(int i = 0; i < iter; ++i)
  21. {
  22. z = float2(z.x*z.x - z.y*z.y, 2.0*z.x*z.y) + ConstantSrg::seed;
  23. if(dot(z,z) > 4.0)
  24. {
  25. count = i;
  26. break;
  27. }
  28. }
  29. float value = float(count)/float(iter) ;
  30. int index = thread_id.y * int(ConstantSrg::dimension.x) + thread_id.x;
  31. BufferSrg::m_computeBuffer[index].m_data = float4(value, value, value, 1.0);
  32. }