Custom expression additional outputs are considered (0,0,0) when connected to WPO.
[Attachment Removed]
Custom expression additional outputs are considered (0,0,0) when connected to WPO.
[Attachment Removed]
Steps to Reproduce
Create a custom node, add an additional output, set the additional output to a not zero number and return this value as custom expression result too. Connect the custom expression’s output to WPO: it works. Connect the custom expression’s additional output: it doesn’t work.
[Attachment Removed]
Hello,
Thanks for reporting this bug. I’ve verified the problem still exists in latest and created the following issue for tracking which should be visible soon https://issues.unrealengine.com/issue/UE\-385745
It looks likely that this issue was caused by CL#17030334 which was added to fix a FXC.exe ICE. One potential fix is:
+++ b/HLSLMaterialTranslator.cpp
[Content removed]23 @@
// If we found the definition of the return value, there is no need to add more definitions as they won't contribute to the outcome
if (ReturnValueSymbolName != nullptr && CodeChunk.SymbolName == ReturnValueSymbolName)
{
- break;
+ // Don't break early if a later chunk modifies this value via inout
+ // (e.g. a CustomExpression function call that takes this variable as
+ // an 'inout' parameter). Without this check, that call gets truncated
+ // and the variable is never modified, producing a zero result.
+ bool bHasUnemittedDependency = false;
+ for (int32 DepIdx : CodeChunk.ReferencedCodeChunks)
+ {
+ if (DepIdx > ChunkIndex && DepIdx < EndChunk)
+ {
+ bHasUnemittedDependency = true;
+ break;
+ }
+ }
+ if (!bHasUnemittedDependency)
+ {
+ break;
+ }
}
}
with
--- a/HLSLMaterialTranslator.cpp
+++ b/HLSLMaterialTranslator.cpp
[Content removed]17 @@
}
int32 Result = CustomEntry->OutputCodeIndex[OutputIndex];
+
+ // When an additional output is the result, mark the main function call as
+ // a dependency so GetDefinitions() will continue past this chunk and emit
+ // the call that modifies this variable via inout.
+ if (OutputIndex > 0 && CustomEntry->OutputCodeIndex[0] != INDEX_NONE)
+ {
+ ReferencedCodeChunks.AddUnique(CustomEntry->OutputCodeIndex[0]);
+ }
+
if (Custom->IsResultMaterialAttributes(OutputIndex))
{
However, this fix hasn’t been thoroughly tested.
[Attachment Removed]