Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #pragma kernel SortFloats
- #define EVEN(x) (fmod((x),2)==0)
- #define ODD(x) (fmod((x),2)!=0)
- RWStructuredBuffer<float> inputFloatBuffer;
- RWStructuredBuffer<float> outputFloatBuffer;
- RWStructuredBuffer<int> didSwapOccur;
- int bufferLength = 0;
- uint _Iteration;
- [numthreads(32, 1, 1)]
- void SortFloats(uint id : SV_DispatchThreadID)
- {
- float C = inputFloatBuffer[id.x]; // Centre
- float result = C;
- if ( ( EVEN(_Iteration) && EVEN(id.x) ) ||
- ( ODD (_Iteration) && ODD (id.x) )
- )
- {
- if(id.x < bufferLength - 1)
- {
- float R = inputFloatBuffer[id.x + 1]; // Left
- result = min(R, C);
- }
- }
- else
- {
- if(id.x > 0)
- {
- // Min operation
- float L = inputFloatBuffer[id.x - 1]; // Right
- result = max(C, L);
- }
- }
- if(result != C && id.x >= 0 && id.x < bufferLength)
- didSwapOccur[0] = 0;
- outputFloatBuffer[id.x] = result;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement