Added Spheremask node

This commit is contained in:
W2.Wizard
2021-01-25 22:03:30 +01:00
parent f714afc180
commit 5845bc3fca
2 changed files with 50 additions and 0 deletions

View File

@@ -364,6 +364,27 @@ void MaterialGenerator::ProcessGroupMaterial(Box* box, Node* node, Value& value)
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;
}
// SphereMask
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();
// 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);
// Apply hardness, use 0.991 since any value above will result in harsh aliasing
auto x2 = writeLocal(ValueType::Float, String::Format(TEXT("saturate((1 - {0}) * (1 / (1 - clamp({1}, 0, 0.991f))))"), x1.Value, hardness.Value), node);
value = writeLocal(ValueType::Float, String::Format(TEXT("{0} ? (1 - {1}) : {1}"), invert.Value, x2.Value), node);
break;
}
default:
break;
}