Files
UShaderLab/Source/UShaderLabBuilder/Private/ShaderLabIntrinsicRegistry.cpp
2026-07-05 11:26:32 +08:00

69 lines
1.8 KiB
C++

// Copyright UShaderLab. All Rights Reserved.
#include "ShaderLabIntrinsicRegistry.h"
#include "ShaderLabIntrinsics.h"
void ShaderLabIntrinsic_Private::AddSimple(
FShaderLabIntrinsicRegistry& Registry,
const TCHAR* Name,
EShaderLabIntrinsicFrequency Frequency,
const TCHAR* ReturnType,
TFunction<UMaterialExpression*(UMaterial&)> Make,
int32 OutputIndex)
{
FShaderLabIntrinsicDesc Desc;
Desc.Name = FName(Name);
Desc.Frequency = Frequency;
Desc.ReturnType = ReturnType;
Desc.OutputIndex = OutputIndex;
Desc.MakeNode = [Make = MoveTemp(Make)](UMaterial& M, const TArray<FString>&, FString&) { return Make(M); };
Registry.Register(MoveTemp(Desc));
}
FShaderLabIntrinsicRegistry& FShaderLabIntrinsicRegistry::Get()
{
static FShaderLabIntrinsicRegistry Instance;
return Instance;
}
FShaderLabIntrinsicRegistry::FShaderLabIntrinsicRegistry()
{
RegisterBuiltins();
}
void FShaderLabIntrinsicRegistry::Register(FShaderLabIntrinsicDesc Desc)
{
check(!Desc.Name.IsNone());
check(Desc.MakeNode);
// Contract: every intrinsic is IDE-describable so ShaderLab.IDE.Prepare can always emit a stub.
check(!Desc.ReturnType.IsEmpty());
Descs.Add(Desc.Name, MoveTemp(Desc));
}
const FShaderLabIntrinsicDesc* FShaderLabIntrinsicRegistry::Find(FName Name) const
{
return Descs.Find(Name);
}
void FShaderLabIntrinsicRegistry::ForEach(TFunctionRef<void(const FShaderLabIntrinsicDesc&)> Fn) const
{
for (const TPair<FName, FShaderLabIntrinsicDesc>& Pair : Descs)
{
Fn(Pair.Value);
}
}
void FShaderLabIntrinsicRegistry::RegisterBuiltins()
{
RegisterMeshIntrinsics(*this);
RegisterViewIntrinsics(*this);
RegisterObjectIntrinsics(*this);
RegisterInstancingIntrinsics(*this);
RegisterTimeIntrinsics(*this);
RegisterParticleIntrinsics(*this);
RegisterDecalIntrinsics(*this);
RegisterAtmosphereIntrinsics(*this);
RegisterDistanceFieldIntrinsics(*this);
}