Convert values into a range

I’m working with my first material (this is the first time I work with Unreal Engine)

I have a scalar parameter that will accept values from -4 to 100, and I want to avoid 0 values.

Maybe a need a function to avoid 0 values. For example, If value is -4, it will return 1, and from that value, the function will return lower values until zero.

Is there a function to do that in Unreal?

Are you saying it goes from -4 to 100 or from -4 to -100?
Are you saying you want to enter positive values to change the negative values?
After reading your post a few times we need a little more info to get you sorted.

To convert -4 to -100 to 0 to 1:

X is the value we want to convert to that range

float ClampedValue = (X + 108) / 104

  1. Add 108
  2. Divide by 104

You can test it here: http://wolfr.am/7nN8EW5l Replace -4 with whatever value you have.

I need this function to set a value to set emissive effect value in my material. Now, I have a parameter, and I want a function to convert a value between -4, 100] to [0, 1].

And how can I implement this in Unreal Material editor?

May need to multiply the final float4 to get more brightness, but it works.

EDIT: This only works from -4 to -100. If you want 100, I would just convert the number to negative if it’s bigger than 0.

I’ll post again if I figure out the formula for -4 to positive 100. This is a really very odd range, are you sure there isn’t a better way to do this?

I see.
So what you want is a slider in a material instance to have your range of -4 to +100 correct?
You actually don’t need any fancy math for that.
Multiply your emissive by a scalar
In the scalar set the max slider range to -4 and 100

1 Like