Any way to "normalize" gradient to 0-1 range?

Hi folks,

let’s say I have a gradient (or general greyscale texture) where darkest pixel is above 0 and brightest pixel is below 1.
Is there an easy way how to “normalize” or “re-map” the gradient to cover the whole 0-1 range?
If there is no easy way, is there some hard way? :slight_smile:


Edit: By normalize/re-map I mean something you would do in Photoshop via Levels tool to make use of the whole range of the current bit depth.

Simple way is get your min and max values. Then subtract max minus min. So if .3 is the low and .9 is the high .9 - .3 = .6. Then get 1/.6, this is is the factor you will increase the new values by. Lastly take your current value minus the min value, then multiply by your increase factor. So like if you get the value .4 in this range you take (.4-.3)*1/.6

I should have mentioned that I need that happening dynamically, e.g. I don’t know the min or max values. So I guess I should be asking how to get the min and max values from a texture?

Did you ever find a solution for this? I’m in need of the same functionality. So far, it seems like you would have to make an array of the brightness values of each pixel and pick the brightest (and then run your remap function), but that sounds kind of expensive.