Skip to content

Commit 28c0840

Browse files
gabrieldelacruzEvergreen
authored andcommitted
[VFX] Strip tangent not properly computed when using Shader Graph output
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">
1 parent b516dcf commit 28c0840

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

Packages/com.unity.visualeffectgraph/Editor/ShaderGraph/Templates/VFXConfig.template.hlsl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ float3 GetStripTangent(float3 currentPos, uint instanceIndex, uint relativeIndex
173173
uint prevIndex = GetParticleIndex(relativeIndex - 1, stripData);
174174
float3 tangent = currentPos - GetParticlePosition(prevIndex, instanceIndex);
175175
float sqrLength = dot(tangent, tangent);
176-
if (sqrLength > VFX_EPSILON)
176+
if (sqrLength > VFX_EPSILON * VFX_EPSILON)
177177
prevTangent = tangent * rsqrt(sqrLength);
178178
}
179179

@@ -183,7 +183,7 @@ float3 GetStripTangent(float3 currentPos, uint instanceIndex, uint relativeIndex
183183
uint nextIndex = GetParticleIndex(relativeIndex + 1, stripData);
184184
float3 tangent = GetParticlePosition(nextIndex, instanceIndex) - currentPos;
185185
float sqrLength = dot(tangent, tangent);
186-
if (sqrLength > VFX_EPSILON)
186+
if (sqrLength > VFX_EPSILON * VFX_EPSILON)
187187
nextTangent = tangent * rsqrt(sqrLength);
188188
}
189189

0 commit comments

Comments
 (0)