Refactoring and Node implementation

Refactored all recently added nodes to maintain consistency.
This commit is contained in:
W2.Wizard
2021-01-28 01:26:57 +01:00
parent 876a728b41
commit bd18286fbd
2 changed files with 106 additions and 19 deletions

View File

@@ -725,7 +725,7 @@ namespace FlaxEditor.Surface.Archetypes
{
TypeID = 30,
Title = "DDX",
Description = "Returns the partial derivative of the specified value with respect to the screen-space x-coordinate.",
Description = "Returns the partial derivative of the specified value with respect to the screen-space x-coordinate",
Flags = NodeFlags.MaterialGraph,
Size = new Vector2(90, 25),
ConnectionsHints = ConnectionsHint.Numeric,
@@ -741,7 +741,7 @@ namespace FlaxEditor.Surface.Archetypes
{
TypeID = 31,
Title = "DDY",
Description = "Returns the partial derivative of the specified value with respect to the screen-space y-coordinate.",
Description = "Returns the partial derivative of the specified value with respect to the screen-space y-coordinate",
Flags = NodeFlags.MaterialGraph,
Size = new Vector2(90, 25),
ConnectionsHints = ConnectionsHint.Numeric,
@@ -753,6 +753,64 @@ namespace FlaxEditor.Surface.Archetypes
NodeElementArchetype.Factory.Output(0, string.Empty, null, 1),
}
},
new NodeArchetype
{
TypeID = 32,
Title = "Sign",
Description = "Returns -1 if value is less than zero; 0 if value equals zero; and 1 if value is greater than zero",
Flags = NodeFlags.MaterialGraph,
Size = new Vector2(90, 25),
ConnectionsHints = ConnectionsHint.Numeric,
IndependentBoxes = new[] { 0 },
Elements = new[]
{
NodeElementArchetype.Factory.Input(0, "Value", true, null, 0),
NodeElementArchetype.Factory.Output(0, string.Empty, typeof(float), 1),
}
},
new NodeArchetype
{
TypeID = 33,
Title = "Any",
Description = "True if any components of value are non-zero; otherwise, false",
Flags = NodeFlags.MaterialGraph,
Size = new Vector2(90, 25),
ConnectionsHints = ConnectionsHint.Numeric,
IndependentBoxes = new[] { 0 },
Elements = new[]
{
NodeElementArchetype.Factory.Input(0, "Value", true, null, 0),
NodeElementArchetype.Factory.Output(0, string.Empty, typeof(bool), 1),
}
},
new NodeArchetype
{
TypeID = 34,
Title = "All",
Description = "Determines if all components of the specified value are non-zero",
Flags = NodeFlags.MaterialGraph,
Size = new Vector2(90, 25),
ConnectionsHints = ConnectionsHint.Numeric,
IndependentBoxes = new[] { 0 },
Elements = new[]
{
NodeElementArchetype.Factory.Input(0, "Value", true, null, 0),
NodeElementArchetype.Factory.Output(0, string.Empty, typeof(bool), 1),
}
},
new NodeArchetype
{
TypeID = 35,
Title = "Black Body",
Description = "Simulates black body radiation via a given temperature in kelvin",
Flags = NodeFlags.MaterialGraph,
Size = new Vector2(120, 25),
Elements = new[]
{
NodeElementArchetype.Factory.Input(0, "Temp", true, typeof(float), 0),
NodeElementArchetype.Factory.Output(0, string.Empty, typeof(Vector3), 1),
}
},
};
}
}

View File

@@ -351,15 +351,15 @@ void MaterialGenerator::ProcessGroupMaterial(Box* box, Node* node, Value& value)
// Rotator
case 27:
{
auto uv = tryGetValue(node->GetBox(0), getUVs).AsVector2();
auto center = tryGetValue(node->GetBox(1), Value::Zero).AsVector2();
auto rotationAngle = tryGetValue(node->GetBox(2), Value::Zero).AsFloat();
const auto uv = tryGetValue(node->GetBox(0), getUVs).AsVector2();
const auto center = tryGetValue(node->GetBox(1), Value::Zero).AsVector2();
const auto rotationAngle = tryGetValue(node->GetBox(2), Value::Zero).AsFloat();
const auto x1 = writeLocal(ValueType::Vector2, String::Format(TEXT("({0} * -1) + {1}"), center.Value, uv.Value), node);
const auto raCosSin = writeLocal(ValueType::Vector2, String::Format(TEXT("float2(cos({0}), sin({0}))"), rotationAngle.Value), node);
auto x1 = writeLocal(ValueType::Vector2, String::Format(TEXT("({0} * -1) + {1}"), center.Value, uv.Value), node);
auto raCosSin = writeLocal(ValueType::Vector2, String::Format(TEXT("float2(cos({0}), sin({0}))"), rotationAngle.Value), node);
const auto dotB1 = writeLocal(ValueType::Vector2, String::Format(TEXT("float2({0}.x, {0}.y * -1)"), raCosSin.Value), node);
const auto dotB2 = writeLocal(ValueType::Vector2, String::Format(TEXT("float2({0}.y, {0}.x)"), raCosSin.Value), node);
auto dotB1 = writeLocal(ValueType::Vector2, String::Format(TEXT("float2({0}.x, {0}.y * -1)"), raCosSin.Value), node);
auto dotB2 = writeLocal(ValueType::Vector2, String::Format(TEXT("float2({0}.y, {0}.x)"), raCosSin.Value), node);
value = writeLocal(ValueType::Vector2, String::Format(TEXT("{3} + float2(dot({0},{1}), dot({0},{2}))"), x1.Value, dotB1.Value, dotB2.Value, center.Value), node);
break;
@@ -367,11 +367,11 @@ void MaterialGenerator::ProcessGroupMaterial(Box* box, Node* node, Value& value)
// Sphere Mask
case 28:
{
Value a = tryGetValue(node->GetBox(0), 0, Value::Zero);
Value b = tryGetValue(node->GetBox(1), 1, Value::Zero).Cast(a.Type);
Value radius = tryGetValue(node->GetBox(2), node->Values[0]).AsFloat();
Value hardness = tryGetValue(node->GetBox(3), node->Values[1]).AsFloat();
Value invert = tryGetValue(node->GetBox(4), node->Values[2]).AsBool();
const auto a = tryGetValue(node->GetBox(0), 0, Value::Zero);
const auto b = tryGetValue(node->GetBox(1), 1, Value::Zero).Cast(a.Type);
const auto radius = tryGetValue(node->GetBox(2), node->Values[0]).AsFloat();
const auto hardness = tryGetValue(node->GetBox(3), node->Values[1]).AsFloat();
const auto invert = tryGetValue(node->GetBox(4), node->Values[2]).AsBool();
// Get distance and apply radius
auto x1 = writeLocal(ValueType::Float, String::Format(TEXT("distance({0},{1}) * (1 / {2})"), a.Value, b.Value, radius.Value), node);
@@ -385,9 +385,9 @@ void MaterialGenerator::ProcessGroupMaterial(Box* box, Node* node, Value& value)
// Tiling & Offset
case 29:
{
auto uv = tryGetValue(node->GetBox(0), getUVs).AsVector2();
auto tiling = tryGetValue(node->GetBox(1), node->Values[0]).AsVector2();
auto offset = tryGetValue(node->GetBox(2), node->Values[1]).AsVector2();
const auto uv = tryGetValue(node->GetBox(0), getUVs).AsVector2();
const auto tiling = tryGetValue(node->GetBox(1), node->Values[0]).AsVector2();
const auto offset = tryGetValue(node->GetBox(2), node->Values[1]).AsVector2();
value = writeLocal(ValueType::Vector2, String::Format(TEXT("{0} * {1} + {2}"), uv.Value, tiling.Value, offset.Value), node);
break;
@@ -395,7 +395,7 @@ void MaterialGenerator::ProcessGroupMaterial(Box* box, Node* node, Value& value)
// DDX
case 30:
{
auto inValue = tryGetValue(node->GetBox(0), 0, Value::Zero);
const auto inValue = tryGetValue(node->GetBox(0), 0, Value::Zero);
value = writeLocal(inValue.Type, String::Format(TEXT("ddx({0})"), inValue.Value), node);
break;
@@ -403,10 +403,39 @@ void MaterialGenerator::ProcessGroupMaterial(Box* box, Node* node, Value& value)
// DDY
case 31:
{
auto inValue = tryGetValue(node->GetBox(0), 0, Value::Zero);
const auto inValue = tryGetValue(node->GetBox(0), 0, Value::Zero);
value = writeLocal(inValue.Type, String::Format(TEXT("ddy({0})"), inValue.Value), node);
break;
}
// Sign
case 32:
{
const auto inValue = tryGetValue(node->GetBox(0), 0, Value::Zero);
value = writeLocal(ValueType::Float, String::Format(TEXT("sign({0})"), inValue.Value), node);
break;
}
// Any
case 33:
{
const auto inValue = tryGetValue(node->GetBox(0), 0, Value::Zero);
value = writeLocal(ValueType::Bool, String::Format(TEXT("any({0})"), inValue.Value), node);
break;
}
// All
case 34:
{
const auto inValue = tryGetValue(node->GetBox(0), 0, Value::Zero);
value = writeLocal(ValueType::Bool, String::Format(TEXT("all({0})"), inValue.Value), node);
break;
}
// Blackbody
case 35:
{
break;
}
default:
break;