added Ratangle Mask and FWidth

This commit is contained in:
NoriteSC
2023-10-04 10:00:03 +02:00
parent 167fead18d
commit 70ca1996c5
2 changed files with 57 additions and 0 deletions
@@ -882,6 +882,44 @@ namespace FlaxEditor.Surface.Archetypes
NodeElementArchetype.Factory.Output(1, "Inv Size", typeof(Float2), 1),
}
},
new NodeArchetype
{
TypeID = 40,
Title = "Ratangle Mask",
Description = "Creates a Ratangle mask",
Flags = NodeFlags.MaterialGraph,
Size = new Float2(150, 100),
ConnectionsHints = ConnectionsHint.Vector,
DefaultValues = new object[]
{
new Float2(0, 0),
new Float2(0.5f, 0.5f),
},
Elements = new[]
{
NodeElementArchetype.Factory.Input(0, "UV", true, typeof(Float2), 0),
NodeElementArchetype.Factory.Input(1, "Ratangle", true, typeof(Float2), 1),
NodeElementArchetype.Factory.Output(0, string.Empty, typeof(float), 5),
}
},
new NodeArchetype
{
TypeID = 41,
Title = "FWidth",
Description = "Creates a Partial Derivatives (fwidth)",
Flags = NodeFlags.MaterialGraph,
Size = new Float2(150, 100),
ConnectionsHints = ConnectionsHint.Vector,
DefaultValues = new object[]
{
1
},
Elements = new[]
{
NodeElementArchetype.Factory.Input(0, "value", true, typeof(float), 0),
NodeElementArchetype.Factory.Output(0, string.Empty, typeof(float), 5),
}
},
};
}
}
@@ -519,6 +519,25 @@ void MaterialGenerator::ProcessGroupMaterial(Box* box, Node* node, Value& value)
}
break;
}
// Ratangle Mask
case 40:
{
const auto uv = tryGetValue(node->GetBox(0), getUVs).AsFloat2();
const auto ratangle = tryGetValue(node->GetBox(1), node->Values[1]).AsFloat2();
auto d = writeLocal(ValueType::Float2, String::Format(TEXT("abs({0} * 2 - 1) - {1}"),uv.Value, ratangle.Value), node);
auto fwidth = writeLocal(ValueType::Float , String::Format(TEXT("abs(ddx({0})) + abs(ddy({0}))"), d.Value), node);
auto d2 = writeLocal(ValueType::Float , String::Format(TEXT("1 - {0} / {1}"), d.Value, fwidth.Value), node);
value = writeLocal(ValueType::Float , String::Format(TEXT("saturate(min({0}.x, {0}.y))"), d2.Value), node);
break;
}
// FWidth
case 41:
{
const auto d = tryGetValue(node->GetBox(0), node->Values[0]).AsFloat();
value = writeLocal(ValueType::Float, String::Format(TEXT("abs(ddx({0})) + abs(ddy({0}))"), d.Value), node);
break;
}
default:
break;
}