Merge branch 'DDX-DDY-Nodes' of git://github.com/W2Wizard/FlaxEngine into W2Wizard-DDX-DDY-Nodes

This commit is contained in:
Wojtek Figat
2021-01-27 22:39:19 +01:00
2 changed files with 49 additions and 1 deletions

View File

@@ -720,7 +720,39 @@ namespace FlaxEditor.Surface.Archetypes
NodeElementArchetype.Factory.Input(2, "Offset", true, typeof(Vector2), 2, 1),
NodeElementArchetype.Factory.Output(0, string.Empty, typeof(Vector2), 3),
}
}
},
new NodeArchetype
{
TypeID = 30,
Title = "DDX",
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,
IndependentBoxes = new[] { 0 },
DependentBoxes = new[] { 1 },
Elements = new[]
{
NodeElementArchetype.Factory.Input(0, "Value", true, null, 0),
NodeElementArchetype.Factory.Output(0, string.Empty, null, 1),
}
},
new NodeArchetype
{
TypeID = 31,
Title = "DDY",
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,
IndependentBoxes = new[] { 0 },
DependentBoxes = new[] { 1 },
Elements = new[]
{
NodeElementArchetype.Factory.Input(0, "Value", true, null, 0),
NodeElementArchetype.Factory.Output(0, string.Empty, null, 1),
}
},
};
}
}

View File

@@ -391,6 +391,22 @@ void MaterialGenerator::ProcessGroupMaterial(Box* box, Node* node, Value& value)
value = writeLocal(ValueType::Vector2, String::Format(TEXT("{0} * {1} + {2}"), uv.Value, tiling.Value, offset.Value), node);
break;
}
// DDX
case 30:
{
auto inValue = tryGetValue(node->GetBox(0), 0, Value::Zero);
value = writeLocal(inValue.Type, String::Format(TEXT("ddx({0})"), inValue.Value), node);
break;
}
// DDY
case 31:
{
auto inValue = tryGetValue(node->GetBox(0), 0, Value::Zero);
value = writeLocal(inValue.Type, String::Format(TEXT("ddy({0})"), inValue.Value), node);
break;
}
default:
break;