Download

How to clamp texture value

Hello,

I am having a hard time figuring out how to do very essential thing in UE4 material blueprint - clamping texture range. What I basically need is a simple way of compressing texture range to generate quick masks, like on the video example here: https://youtu.be/J6V2e_utecI

I would like to stress that I am looking for quick and simple solution, preferably just one node. It’s not so much about knowing if this is possible with UE or not (I am 100% sure it is), but rather about if it is easily possible with UE. If there is not simple out of the box operation to perform so essential task, then it will be clear message for me I will likely encounter a lot of similar obstacles in future, and should look for different, more artist friendly game engine. Therefore please no “You can build compound using these 20 nodes” kind of suggestions. My question is more about finding out if UE really lacks so basic out-of-the-box tools in expectation that user will build them on his own, or if I am just looking in wrong places.

Thank you very much in advance.

First off, I would say that in my experience the overall Unreal Engine philosophy is to give devs lots of tools and pieces to create exactly what they want. This is especially true in the material editor. All the math functions available (along with the custom code node) mean there is almost nothing you cannot do. However, this does mean that there are fewer “out-of-the-box” functions available to you. The devs at Epic have started including more of this type of functionality with the pre-made Material Functions, but they are really just using the tools already available and doing the work for you ahead of time.

That being said, remapping a value in the way you want is pretty simple. It is not all together in one node, but it is possible with only a few math nodes:

Remapper.JPG

In reality, you could take these nodes and put them together in a material function of your own so you can reuse them in any other material in your project.

I hope this helps and also maybe lets you see that the Unreal Engine is actually incredibly artist friendly; it just may take a little extra exploring to find what you need. Cheers!

Thanks! This is actually a lot less intimidating then I though. This will definitely do… I thought it would be a lot more complex.

What kind of put me off and made me write what I wrote is because I am still somehow perplexed there are node presets for very complex specific stuff, for example Fuzzy shader or two versions of LerpScratchGrime, yet no one though of including so essential node as this. There are a lot of artists coming to UE from offline rendering world, like me, and about half of the nodes we are used to are hidden under very cryptic names (i for example initially assumed UE does not even have Mix/Blend node until I realized it’s strangely named “Lerp”), and second half completely absent with “build it yourself” encouragement. Not many people know the math behind those color transforms they use in offline rendering every day, though :wink:

It just partially suffers from the " built by programmers for programmers" syndrome :slight_smile:

Alright.

I got it working. Thanks again! Unfortunately now I struggle with turning it into material function. No matter what I do, I can not figure out a way to add parameters to the node, in the same way Clamp node has them, so that they are present right in the details panel, and I do not need to create two new constant nodes and plug them in. I can not imagine having to create two constants and plugging them in every time I just want to use my pre-made material fuction. I think that kind of defeats point of material functions…

Unfortunately, that is exactly how material functions work. I too wish we could make parameters that show up in the node similar to the other math nodes. That would be a really nice addition that would save time and clarity. I’m not sure if there is a place to put feature requests on these forums, but that would be a good one.

You described this as “clamping the texture range” but that is actually not the operation being done. If you were clamping a texture from ~0.2 to 0.8, it means that the darkest color would be 0.2 and the brightest color would be 0.8.

What you are describing is extracting a limited range from a larger 0-1 gradient and remapping it to fit the 0-1 range.

The closest node we have to this is probably “Alpha Offset”. The only problem is that it assumes the “top range” will always be 1. DSurley’s graph above is basically AlphaOffset with 1 as a parameter.

If I were to make a node for this and check it into engine, I would probably call it “Gradient Remap” or “Extract Gradient”. Can anybody think of a better one? It is often difficult to pick names for functions like this where people have wildly different expectations of what the operations should be called or does. It can’t be clamping though because that is an already established standard operation.

Yeah, I agree that meaning of clamping may be different in unreal engine.

In Photoshop, this option is called Input Levels. Appropriate name could be also Compress Levels. Even Gradient Remap would still make some sense, but Extract Gradient would be completely cryptic name I would never ever associate with such operation. Or Remap Value or Compress Value are another two good candidates for a name.

Unreal Engine actually seems to suffer from this syndrome heavily. Half of the image editing operations I am commonly used to, and which are pretty much consistently named between nearly all of the computer graphics softwares I ever used, are named in completely different, often very confusing ways. So when I started to learn unreal engine, I spent most of my time in frustration not because UE would lack feature set, but because features would be hidden under very cryptic names.

RangeRemap or LinearRangeRemap is the function name I would search for

Inputs
in
inStart
inEnd
outStart
outEnd

Outputs
out

where

out = outStart + (in - inStart) * (outEnd - outStart) / (inEnd - inStart)

Ref: http://stackoverflow.com/questions/3451553/value-remapping

This is not a clamping function, in values outside of the input range will still map to the slope created by the output range. Feeding the value from the remap into the existing clamp function would be just as effective and more versatile.

I prefer Start and End, since its just as valid to reverse the range, in {0,1} out {0,-1}, which makes low and high a bit of misnomer.

I already have a custom node based on what DSursely posted, so I don’t mind, but for sake of future users, I would suggest to keep the node as simple as possible. Meaning just RGB input, and two parameters called either low and high or black and white.

The problem with material functions in UE4 is that they can not have parameters right in the node, so you need to plug in a lot of junk (constants) often to get the node even working, so each additional input parameters means time wasted setting the node up.

Meanwhile, I found out that UE4 actually has a full fledged levels node already, turns out it is named “3PointLevels”… Again, 3Point is the last thing I would search for if I was looking to clamp/compress range of value.

So if you need a complex leves node, then there is 3PointLevels. But again, for sake of future newbies, it would be good to have a simple preset node with just RGB input, and two super simple parameters :slight_smile: