Files
UShaderLab/Source/UShaderLabEditor/Private/ShaderLabIntrinsics_DistanceField.cpp
2026-07-03 18:45:27 +08:00

44 lines
1.6 KiB
C++

// Copyright UShaderLab. All Rights Reserved.
//
// Global-distance-field intrinsics. These names are OVERLOADED (bAllowRawHelperWithArgs): the nullary form
// UE_DistanceToNearestSurface() / UE_DistanceFieldGradient() is this wired intrinsic (its real node reads the
// current pixel's world position and sets bUsesGlobalDistanceField), while UE_Name(worldPos) is a same-named
// raw HLSL helper in UEFunctions/DistanceField.ush whose binding is supplied by the "GlobalDistanceField"
// anchor capability. The parser routes a call with args to the helper and a nullary call to this node.
#include "ShaderLabIntrinsics.h"
#include "Materials/MaterialExpressionDistanceToNearestSurface.h"
#include "Materials/MaterialExpressionDistanceFieldGradient.h"
void RegisterDistanceFieldIntrinsics(FShaderLabIntrinsicRegistry& Registry)
{
using namespace ShaderLabIntrinsic_Private;
using EFreq = EShaderLabIntrinsicFrequency;
{
FShaderLabIntrinsicDesc Desc;
Desc.Name = TEXT("DistanceToNearestSurface");
Desc.Frequency = EFreq::Any;
Desc.ReturnType = TEXT("float");
Desc.bAllowRawHelperWithArgs = true;
Desc.MakeNode = [](UMaterial& M, const TArray<FString>&, FString&)
{
return MakeSimple<UMaterialExpressionDistanceToNearestSurface>(M);
};
Registry.Register(MoveTemp(Desc));
}
{
FShaderLabIntrinsicDesc Desc;
Desc.Name = TEXT("DistanceFieldGradient");
Desc.Frequency = EFreq::Any;
Desc.ReturnType = TEXT("float3");
Desc.bAllowRawHelperWithArgs = true;
Desc.MakeNode = [](UMaterial& M, const TArray<FString>&, FString&)
{
return MakeSimple<UMaterialExpressionDistanceFieldGradient>(M);
};
Registry.Register(MoveTemp(Desc));
}
}