Baffling material problem. Graph isn't generating correct HLSL code... or is it?

I have a function, it takes a linear gradient and rounds it, you can see it here on Desmos. (btw if anyone has a more efficient way to do this I’m all ears, I only need the 0-1 part)

Problem is, when I use Unreal’s built in Power node (specifically using this math) it produces different results than just multiplying or using a custom node: return pow(x,2);

Am I just not understanding how Power works or is something wrong here? Does anyone know where I can find the HLSL that’s being generated so I can see wtf it is doing? The generated HLSL is 3k lines of code and I’m not sure where I should be looking.

The problem is you’re putting a negative value into X, which returns NAN for HLSL & undefined results for GLSL. Putting an Abs() before the power fixes this:

Since you’re squaring it, it’s best just to multiply it by itself.

1 Like

Thank you for the explanation, I must admit, I’ve very minimal experience with HLSL.

I don’t suppose you know why it seems to work correctly when used as HLSL in a custom node?

1 Like

Nope, lol. I’m surprised it works in the custom node considering it’s HLSL as well. Maybe it knows to check for it, but I don’t get how.

1 Like