// Copyright UShaderLab. All Rights Reserved. #include "MaterialExpressionShaderLabParameterAnchor.h" #include "MaterialCompiler.h" UMaterialExpressionShaderLabParameterAnchor::UMaterialExpressionShaderLabParameterAnchor(const FObjectInitializer& ObjectInitializer) : Super(ObjectInitializer) { } #if WITH_EDITOR TArrayView 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 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& OutCaptions) const { OutCaptions.Add(TEXT("ShaderLab Static-Switch Defines / Parameter Anchor")); } #endif // WITH_EDITOR