Advertisement
Guest User

Untitled

a guest
Jul 22nd, 2019
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.89 KB | None | 0 0
  1. #pragma kernel SortFloats
  2.  
  3. #define EVEN(x) (fmod((x),2)==0)
  4. #define ODD(x) (fmod((x),2)!=0)
  5.  
  6. RWStructuredBuffer<float> inputFloatBuffer;
  7. RWStructuredBuffer<float> outputFloatBuffer;
  8. RWStructuredBuffer<int> didSwapOccur;
  9. int bufferLength = 0;
  10. uint _Iteration;
  11.  
  12. [numthreads(32, 1, 1)]
  13. void SortFloats(uint id : SV_DispatchThreadID)
  14. {
  15. float C = inputFloatBuffer[id.x]; // Centre
  16. float result = C;
  17. if ( ( EVEN(_Iteration) && EVEN(id.x) ) ||
  18. ( ODD (_Iteration) && ODD (id.x) )
  19. )
  20. {
  21. if(id.x < bufferLength - 1)
  22. {
  23. float R = inputFloatBuffer[id.x + 1]; // Left
  24. result = min(R, C);
  25. }
  26. }
  27. else
  28. {
  29. if(id.x > 0)
  30. {
  31. // Min operation
  32. float L = inputFloatBuffer[id.x - 1]; // Right
  33. result = max(C, L);
  34. }
  35. }
  36.  
  37. if(result != C && id.x >= 0 && id.x < bufferLength)
  38. didSwapOccur[0] = 0;
  39.  
  40. outputFloatBuffer[id.x] = result;
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement