So I have a list if vector4 values here [-4.571429, 12.142858, 0.35, 0.35] that need to be used as remapping values for a roughness texture i have. But here is the thing, my friend doesnt know nodes at all, only code. Vice versa for me. But he has given me this to attempt to turn it into a node group in the offchance i can get it worked out:

float remap_with_clamp(float remap_input, float min, float max, float zero, float one)

                            vec2 xform = vec2(zero, one - zero);

                            float in_value = remap_input;
                            return clamp(xform.x + xform.y * in_value, min, max);

A note he also gave me is: "Your float zero and float one is the values like the -4, 12. The remap_input would be the image that is being remapped. The min and max is your clamp values. Another thing to mention this is all happening in multiple shader nodes as a float value at runtime we combine all 4 of the floats into a vec4 to save on code."

Any help i can get on this will definitely be appreciated

  • 1
    $\begingroup$ Quite a weird way of mapping .. (eg no need to take zero and one into a vector and out again, and with the values given, everything will come out at .35...) Can you explain the 'Map Range' node to your friend? $\endgroup$ Sep 10 '20 at 10:05

Your question is very specific. However, converting code into nodes is precisely what the Dynamic Maths Expression / Node Expressions was made for (download it from https://github.com/baldingwizard/Blender-Addons/wiki/Dynamic-Maths-Expression).

Once you've installed the add-on you should have a new Maths Expression option in the node 'Add' menu.

Create a new text block and paste the following code :


xform[] = combine(zero, one - zero)

in_value = remap_input
output = combine(clip(xform[x] + xform[y] * in_value), clip(min), clip(max))

(NOTE: The above text is translated directly from your sample code, almost line for line)

Name the textblock something meaningful (eg, 'mycode'), go to the Node Editor and add a new Maths Expression with the text TEXT:<name> (replacing <name> with the name of your text block - eg, 'TEXT:mycode') and the add-on will interpret your code and generate a new node group containing the relevant nodes to implement the code.

Obviously your coder friend will need to produce code in the correct syntax for the add-on to interpret.

enter image description here

  • 1
    $\begingroup$ I think this works! Thanks for the help $\endgroup$
    – darupta
    Sep 10 '20 at 23:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.