Advertisement
cajphrase

NoMoreSort

Aug 12th, 2024
17
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.75 KB | None | 0 0
  1.  
  2. int FirstTrue(bool4 b)
  3. {
  4. return b.x ? 0 : b.y ? 1 : b.z ? : 2 : b.w ? : 3 : -1;
  5. }
  6.  
  7. int IndexOf(float4 a, float b)
  8. {
  9. return FirstTrue(a == b);
  10. }
  11. {
  12. float4 UVweights[9];
  13.  
  14. float4 bestWeights = 0;
  15. float4x4 bestValues = 0;
  16.  
  17. // bubble sort is overkill, we don't need the samples ordered nor do we care about the order of the lower 5.
  18. // use SIMD type logic to find the 4 best values in no particular order
  19. [unroll]
  20. for (i = 0; i < 9; i++)
  21. {
  22. float weight = UVweights[i].z;
  23. int slot = FirstTrue(weight > bestWeights && cmin(bestWeights) == bestWeights);
  24. if (slot >= 0)
  25. {
  26. bestWeights[slot] = weight;
  27. bestValues[slot] = UVweights[i];
  28. }
  29. }
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement