Skip to content

Commit

Permalink
[VFX] Strip tangent not properly computed when using Shader Graph output
Browse files Browse the repository at this point in the history
To compute the tangents for strips, we check the distances to previous and next particles, and obtain the direction.
When the particles are too close, the direction may not be representative, so we check that they are under a certain threshold.
The threshold used is good enough for distance but, since we are testing distances squared, it turns out to be to large.
This was already fixed for VFX graph generated shaders, but we missed the same code path for Shader Graph generated shaders.

Wrong
<img width="653" alt="image" src="https://media.github.cds.internal.unity3d.com/user/2805/files/cf2712ec-be64-4838-b362-adb0b380e117">

Right
<img width="584" alt="image" src="https://media.github.cds.internal.unity3d.com/user/2805/files/1324fa06-571e-4e8e-a51a-49cfbf70af39">
  • Loading branch information
gabrieldelacruz authored and Evergreen committed Sep 19, 2024
1 parent b516dcf commit 28c0840
Showing 1 changed file with 2 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ float3 GetStripTangent(float3 currentPos, uint instanceIndex, uint relativeIndex
uint prevIndex = GetParticleIndex(relativeIndex - 1, stripData);
float3 tangent = currentPos - GetParticlePosition(prevIndex, instanceIndex);
float sqrLength = dot(tangent, tangent);
if (sqrLength > VFX_EPSILON)
if (sqrLength > VFX_EPSILON * VFX_EPSILON)
prevTangent = tangent * rsqrt(sqrLength);
}

Expand All @@ -183,7 +183,7 @@ float3 GetStripTangent(float3 currentPos, uint instanceIndex, uint relativeIndex
uint nextIndex = GetParticleIndex(relativeIndex + 1, stripData);
float3 tangent = GetParticlePosition(nextIndex, instanceIndex) - currentPos;
float sqrLength = dot(tangent, tangent);
if (sqrLength > VFX_EPSILON)
if (sqrLength > VFX_EPSILON * VFX_EPSILON)
nextTangent = tangent * rsqrt(sqrLength);
}

Expand Down

0 comments on commit 28c0840

Please sign in to comment.