build-compute.azsl 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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 changes the value of c over time, which creates the animation.
  12. */
  13. ShaderResourceGroupSemantic ConstantSemantic
  14. {
  15. FrequencyId = 0;
  16. };
  17. ShaderResourceGroupSemantic BufferSemantic
  18. {
  19. FrequencyId = 1;
  20. };
  21. ShaderResourceGroup DispatchConstantSRG : ConstantSemantic
  22. {
  23. struct ConstantData
  24. {
  25. int2 dimension;
  26. float2 seed;
  27. };
  28. ConstantBuffer<ConstantData> m_constantData;
  29. }
  30. ShaderResourceGroup DispatchBufferSRG : BufferSemantic
  31. {
  32. struct BufferData
  33. {
  34. float4 m_data;
  35. };
  36. RWStructuredBuffer<BufferData> m_computeBuffer;
  37. }
  38. [numthreads(1,1,1)]
  39. void MainCS(uint2 thread_id: SV_DispatchThreadID)
  40. {
  41. float u = 2 * float(thread_id.x)/float(DispatchConstantSRG::m_constantData.dimension.x) - 1;
  42. float v = 2 * float(thread_id.y)/float(DispatchConstantSRG::m_constantData.dimension.y) - 1;
  43. float2 z = float2(u, v);
  44. int iter = 128;
  45. int count = iter;
  46. for(int i = 0; i < iter; ++i)
  47. {
  48. z = float2(z.x*z.x - z.y*z.y, 2.0*z.x*z.y) + DispatchConstantSRG::m_constantData.seed;
  49. if(dot(z,z) > 4.0)
  50. {
  51. count = i;
  52. break;
  53. }
  54. }
  55. float value = count/float(iter);
  56. DispatchBufferSRG::m_computeBuffer[thread_id.y * DispatchConstantSRG::m_constantData.dimension.x + thread_id.x].m_data = float4(value, value, value, 1.0);
  57. }