Added initial remap node

This commit is contained in:
W2.Wizard
2021-01-25 00:51:47 +01:00
parent f714afc180
commit ee166bafed
3 changed files with 55 additions and 0 deletions

View File

@@ -404,6 +404,29 @@ namespace FlaxEditor.Surface.Archetypes
NodeElementArchetype.Factory.Output(0, "A | B", null, 2),
}
},
new NodeArchetype
{
TypeID = 48,
Title = "Remap",
Description = "Remaps a value from one range to another, so for example having 25 in a range of 0 to 100 being remapped to 0 to 1 would return 0.25",
Flags = NodeFlags.AllGraphs,
Size = new Vector2(175, 75),
DefaultValues = new object[]
{
25.0f,
new Vector2(0.0f, 100.0f),
new Vector2(0.0f, 1.0f),
false
},
Elements = new[]
{
NodeElementArchetype.Factory.Input(0, "Value", true, typeof(float), 0, 0),
NodeElementArchetype.Factory.Input(1, "In Range", true, typeof(Vector2), 1, 1),
NodeElementArchetype.Factory.Input(2, "Out Range", true, typeof(Vector2), 2, 2),
NodeElementArchetype.Factory.Input(3, "Clamp", true, typeof(bool), 3, 3),
NodeElementArchetype.Factory.Output(0, string.Empty, typeof(float), 4),
}
},
};
}
}

View File

@@ -401,6 +401,22 @@ void ShaderGenerator::ProcessGroupMath(Box* box, Node* node, Value& value)
{
value = writeFunction1(node, tryGetValue(node->GetBox(0), Value::Zero), TEXT("radians"));
break;
}
// Remap
case 48:
{
auto inVal = tryGetValue(node->GetBox(0), node->Values[0]);
auto rangeA = tryGetValue(node->GetBox(1), node->Values[1]);
auto rangeB = tryGetValue(node->GetBox(2), node->Values[2]);
// Clamp value?
if (node->Values[3].AsBool)
{
value = writeLocal(ValueType::Float, String::Format(TEXT("clamp({2}.x + ({0} - {1}.x) * ({2}.y - {2}.x) / ({1}.y - {1}.x), {2}.x, {2}.y)"), inVal.Value, rangeA.Value, rangeB.Value), node);
break;
}
value = writeLocal(ValueType::Float, String::Format(TEXT("{2}.x + ({0} - {1}.x) * ({2}.y - {2}.x) / ({1}.y - {1}.x)"), inVal.Value, rangeA.Value, rangeB.Value), node);
break;
}
default:
break;

View File

@@ -371,6 +371,22 @@ void VisjectExecutor::ProcessGroupMath(Box* box, Node* node, Value& value)
if (value.Type.Type == VariantType::Enum)
value.AsUint64 = value.AsUint64 | (uint64)tryGetValue(node->GetBox(1), Value::Zero);
break;
case 48:
{
const float inVal = tryGetValue(node->GetBox(0), node->Values[0]).AsFloat;
const Vector2 rangeA = tryGetValue(node->GetBox(1), node->Values[1]).AsVector2();
const Vector2 rangeB = tryGetValue(node->GetBox(2), node->Values[2]).AsVector2();
// Use clamp?
if (node->Values[3].AsBool)
{
value = Math::Clamp(rangeB.X + (inVal - rangeA.X) * (rangeB.Y - rangeB.X) / (rangeA.Y - rangeA.X), rangeB.X, rangeB.Y);
break;
}
value = rangeB.X + (inVal - rangeA.X) * (rangeB.Y - rangeB.X) / (rangeA.Y - rangeA.X);
break;
}
default:
break;
}