Levels For Noise texture in Shader

Suppose I have noise texture like this one:

It is in a range from 0.2 to 0.5, how can I remap it properly to range from 0 to 1 in Shader’s code in a case when I don’t know min and max values of original texture?
I’ve already tried Smoothstep and other nodes, but still can’t find a solution.

A remap requires begin and endstates, but you can easily write a function which accepts begin and end ranges.

Remapping functions should be relatively easy to find in google, but just for the sake of it, heres a very naïve, general purpose one.

Inputs
-StartLow
-StartHeigh
-EndLow
-EndHeigh
-StartValue

Output
-EndValue as
(StartValue - (EndLow-StartLow))*(EndHeigh/(StartHeigh - (EndLow-StartLow)))

If you don’t know the low and high ranges of your texture, you should do a min-max loop over all the pixels. Just make sure you do it once during texture load or something, not every tick.

Oh man, this bugged me for a while too!

my solution is to just define the min/max grayscale values as material properties and then convert that range to 0-1 using this forumla:
.
texCol = (texCol - MinGrayScaleValue) / (MaxGrayScaleValue - MinGrayScaleValue);

hope this helps!

How would you get this into Unreal’s materials? I’m still unfamiliar on how to make nodes or add in custom code for materials

Oh god I am of no use here - I just work with unity and am fairly comfortable with their shader code.

Haha no worries! I’m sure there’s documentation on it somewhere

Material functions will do the trick, they even allow you to define in and out nodes, which is prety handy

1 Like

I’ll go the material function route you posted up top, thanks!

Isn’t there a built in Remap function?

I don’t think they have that kind of remap, but they do have lerp which is a 0 to 1 remap. So theoreticaly you can use two lerps, one for remapping original to 0to1 and another to remap it to your new range