Files
UShaderLab/Shaders/Private/UEFunctions/DistanceField.ush
2026-07-03 18:45:27 +08:00

28 lines
1.9 KiB
Plaintext

// Copyright UShaderLab. All Rights Reserved.
//
// UE_ global-distance-field reads at an arbitrary, body-computed world position — forward to the engine's
// GetDistanceToNearestSurfaceGlobal / GetDistanceFieldGradientGlobal. Because these take a DYNAMIC position
// they are emitted as HLSL helpers (like Noise / SceneTexture), NOT wired intrinsics: a body-computed value
// cannot be fed into a material-expression node from inside the opaque Custom node.
//
// The position argument is an ABSOLUTE world position (e.g. UE_WorldPosition()); MakeDFVector3(pos, 0) packs
// it as a large-world-coordinate value and the engine overload converts to translated-world internally.
//
// Global-distance-field binding: the engine only prepares the global distance field for a view when the
// material's relevance flags bUsesGlobalDistanceField, which is a side effect of compiling a
// UMaterialExpressionDistanceToNearestSurface. The raw HLSL call bypasses that node, so the graph builder's
// "GlobalDistanceField" anchor capability adds a hidden one when this parameterized form is used (see
// FShaderLabAnchorCapabilityRegistry). The NULLARY form UE_DistanceToNearestSurface() / UE_DistanceFieldGradient()
// is instead a wired intrinsic whose real node both supplies the value (current pixel) and sets the flag.
#pragma once
#ifdef SHADERLAB_IDE
// IDE stubs: the parameterized overloads (the nullary forms are generated into ShaderLabUENode.ush).
float UE_DistanceToNearestSurface(float3 AbsoluteWorldPosition) { return 0; }
float3 UE_DistanceFieldGradient(float3 AbsoluteWorldPosition) { return (float3)0; }
#else
float UE_DistanceToNearestSurface(float3 AbsoluteWorldPosition) { return GetDistanceToNearestSurfaceGlobal(MakeDFVector3(AbsoluteWorldPosition, 0)); }
float3 UE_DistanceFieldGradient(float3 AbsoluteWorldPosition) { return GetDistanceFieldGradientGlobal(MakeDFVector3(AbsoluteWorldPosition, 0)); }
#endif