// 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 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&) { 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 Fn) const { for (const TPair& 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); }