I am looking into Water plugin, and I found SmoothIntersections
function used in MeshBrush_Width
material.
This function can be written in HLSL like this:
void SmoothIntersections(float3 A, float3 B, float3 K, out float3 SmoothMax, out float3 SmoothMin)
{
float3 diff = A - B;
float3 t = saturate(0.5 + 0.5 * diff / K);
SmoothMax = B + t * diff;
SmoothMin = A - t * diff;
float3 tt = t * (1 - t);
SmoothMax += tt * K;
SmoothMin -= tt * K;
}
This code is understandable except for the last 3 lines.
Why do we need the last 3 lines? In case where A == B (t == 0.5), SmoothMin will be less than A and B and SmoothMax will be greater than A and B. Is it intended?
I suspect that the function is supposed to be like this:
void SmoothIntersections(float3 A, float3 B, float3 K, out float3 SmoothMax, out float3 SmoothMin)
{
float3 diff = A - B;
float3 t = saturate(0.5 + 0.5 * diff / K);
t = t * t * (3.0f - 2.0f * t);
SmoothMax = B + t * diff;
SmoothMin = A - t * diff;
}
MeshBrush_Width
also have some weird nodes. I guess it tries to avoid some artifacts caused by the incorrect SmoothIntersections
function.