Fix invalid shader codegen when using ddx/ddy in material vertex shader

#2376
This commit is contained in:
Wojtek Figat
2024-03-29 18:07:10 +01:00
parent 08e88587e6
commit 3696501050

View File

@@ -421,15 +421,31 @@ void MaterialGenerator::ProcessGroupMaterial(Box* box, Node* node, Value& value)
// DDX
case 30:
{
const auto inValue = tryGetValue(node->GetBox(0), 0, Value::Zero);
value = writeLocal(inValue.Type, String::Format(TEXT("ddx({0})"), inValue.Value), node);
if (_treeType == MaterialTreeType::PixelShader)
{
const auto inValue = tryGetValue(node->GetBox(0), 0, Value::Zero);
value = writeLocal(inValue.Type, String::Format(TEXT("ddx({0})"), inValue.Value), node);
}
else
{
// No derivatives support in VS/DS
value = Value::Zero;
}
break;
}
// DDY
case 31:
{
const auto inValue = tryGetValue(node->GetBox(0), 0, Value::Zero);
value = writeLocal(inValue.Type, String::Format(TEXT("ddy({0})"), inValue.Value), node);
if (_treeType == MaterialTreeType::PixelShader)
{
const auto inValue = tryGetValue(node->GetBox(0), 0, Value::Zero);
value = writeLocal(inValue.Type, String::Format(TEXT("ddy({0})"), inValue.Value), node);
}
else
{
// No derivatives support in VS/DS
value = Value::Zero;
}
break;
}
// Sign