Files
UShaderLab/Source/UShaderLabEditor/Private/MaterialExpressionShaderLabParameterAnchor.cpp
Eragon-Brisingr a861b4680b Init repo
2026-06-30 15:36:02 +08:00

58 lines
1.7 KiB
C++

// Copyright FlecsProj. All Rights Reserved.
#include "MaterialExpressionShaderLabParameterAnchor.h"
#include "MaterialCompiler.h"
UMaterialExpressionShaderLabParameterAnchor::UMaterialExpressionShaderLabParameterAnchor(const FObjectInitializer& ObjectInitializer)
: Super(ObjectInitializer)
{
}
#if WITH_EDITOR
TArrayView<FExpressionInput*> UMaterialExpressionShaderLabParameterAnchor::GetInputsView()
{
CachedInputs.Reset(Inputs.Num());
for (FExpressionInput& Input : Inputs)
{
CachedInputs.Add(&Input);
}
return CachedInputs;
}
FExpressionInput* UMaterialExpressionShaderLabParameterAnchor::GetInput(int32 InputIndex)
{
return Inputs.IsValidIndex(InputIndex) ? &Inputs[InputIndex] : nullptr;
}
FName UMaterialExpressionShaderLabParameterAnchor::GetInputName(int32 InputIndex) const
{
return FName(*FString::Printf(TEXT("Param%d"), InputIndex));
}
int32 UMaterialExpressionShaderLabParameterAnchor::Compile(FMaterialCompiler* Compiler, int32 OutputIndex)
{
// Compiled in the before-attributes pass. Compiling each input forces its static-switch selector
// (and the selected `#define`-emitting Custom node) to compile here — emitting `#define <Switch> 0/1`
// for the current permutation ahead of every body's `#if`. The returned value is unused.
int32 Last = INDEX_NONE;
for (FExpressionInput& Input : Inputs)
{
if (Input.GetTracedInput().Expression)
{
const int32 Code = Input.Compile(Compiler);
if (Code != INDEX_NONE)
{
Last = Code;
}
}
}
return Last != INDEX_NONE ? Last : Compiler->Constant(0.0f);
}
void UMaterialExpressionShaderLabParameterAnchor::GetCaption(TArray<FString>& OutCaptions) const
{
OutCaptions.Add(TEXT("ShaderLab Static-Switch Defines / Parameter Anchor"));
}
#endif // WITH_EDITOR