It’s in there!!! DistanceFieldGradient. Gotta normalize if you just want direction only.
Of course you can compute your own gradient by finite differencing the DistanceToNearestSurface, but this node is faster as it only does the clipmap selection once.
I would love to know what other use cases you know of for distance + gradient.
Here’s how the collision plane is extracted using the DistanceToNearestSurface + gradient. This is in the context of a particle that has position and velocity state. Look in ParticleSimulationShader.usf in master or future 4.9 for the rest of the shader.
float DistanceToNearestSurface = GetDistanceToNearestSurfaceGlobal(InPosition);
float MaxCollisionDistance = CollisionRadius + length(DeltaPosition.xyz);
if (DistanceToNearestSurface < MaxCollisionDistance)
{
float3 CollisionWorldNormal = normalize(GetDistanceFieldGradientGlobal(InPosition));
float3 CollisionWorldPosition = InPosition - CollisionWorldNormal * DistanceToNearestSurface;
float4 CollisionPlane = float4(CollisionWorldNormal.xyz, dot(CollisionWorldPosition.xyz, CollisionWorldNormal.xyz));