If I have two arrays, one is weight and the other represents the original index as such
{0,0.4,0.8,0.2}
{2,5,3,4}
is there any easy way to sort both arrays so that the weights are in order from greater to little
The arrays are actually float4, so mathematical operations work on the pack
currently i have this crazy thing
void insertSorted(inout int4 indices, inout half4 weight, int newIndice, half newWeight)
{
int fourthPlace = step(weight.w, newWeight);
int thirdPlace = step(weight.z, newWeight);
int secondPlace = step(weight.y, newWeight);
int firstPlace = step(weight.x, newWeight);
weight.w = lerp(lerp(weight.w, newWeight, fourthPlace), weight.z, saturate(thirdPlace+secondPlace+firstPlace));
weight.z = lerp(lerp(weight.z, newWeight, thirdPlace), weight.y, saturate(secondPlace+firstPlace));
weight.y = lerp(lerp(weight.y, newWeight, secondPlace), weight.x, firstPlace);
weight.x = lerp(weight.x, newWeight, firstPlace);
indices.w = lerp(lerp(indices.w, newIndice, fourthPlace), indices.z, saturate(thirdPlace+secondPlace+firstPlace));
indices.z = lerp(lerp(indices.z, newIndice, thirdPlace), indices.y, saturate(secondPlace+firstPlace));
indices.y = lerp(lerp(indices.y, newIndice, secondPlace), indices.x, firstPlace);
indices.x = lerp(indices.x, newIndice, firstPlace);
}