interesting question. is the data isn’t sorted?

the most obvious way is to sum each value and check when the sum is equal to the percentage you desire. but you want a more efficient solution than that, right?

I’m not a math guru, but depending on whether the data is dynamic or static, one way i could think of is to calculate beforehand some best fit curve and perform integration on the resulting equation. you’d solve the integral for x, given the sum (which would represent the percentage). So if the data is static, you’d do the curve fitting offline. In the shader, it would be a matter of plugging in into the equation. This is probably not practical for dynamic data though.

i’ll give it more thought.

Hey all, just found your forums here and I’m hoping someone out there can help me with a problem I’ve been pondering for a while now.

If I have an array of values, with the sum of all value elements equal to 1.0, is there an efficient way to calculate the array index of where x% of the total value sum is before that index, and 100% - x% of the values are after that index? Ideally I will be able to calculate this value within a shader.

The practical use of this is to find the index within a histogram where 90% of all values are below that index, and the other 10% are above. This will allow me to reduce the effects of the top 10% of pixels in some techniques. Thanks in advance for any help you can give!