From c871f04a1e08344f732a0a97380e72e5e98f5d0a Mon Sep 17 00:00:00 2001 From: ousttrue Date: Fri, 29 Nov 2024 20:19:59 +0900 Subject: [PATCH] batch count 1 --- .../RotateParticleRuntimeProviderEditor.cs | 1 + .../Runtime/Jobs/ClothWarpJobRuntime.cs | 28 +++++++------- .../ClothWarp/Runtime/Jobs/Collision.cs | 38 ++++++++++++------- 3 files changed, 40 insertions(+), 27 deletions(-) diff --git a/Assets/VRM10_Samples/ClothSample/ClothWarp/Editor/RotateParticleRuntimeProviderEditor.cs b/Assets/VRM10_Samples/ClothSample/ClothWarp/Editor/RotateParticleRuntimeProviderEditor.cs index 5b935b7e9..29271b877 100644 --- a/Assets/VRM10_Samples/ClothSample/ClothWarp/Editor/RotateParticleRuntimeProviderEditor.cs +++ b/Assets/VRM10_Samples/ClothSample/ClothWarp/Editor/RotateParticleRuntimeProviderEditor.cs @@ -29,6 +29,7 @@ namespace UniVRM10.ClothWarp.Components s.SetEnabled(false); root.Add(s); } + root.Add(new PropertyField { bindingPath = nameof(_target.UseJob) }); root.Add(new PropertyField { bindingPath = nameof(_target.Warps) }); root.Add(new PropertyField { bindingPath = nameof(_target.Cloths) }); diff --git a/Assets/VRM10_Samples/ClothSample/ClothWarp/Runtime/Jobs/ClothWarpJobRuntime.cs b/Assets/VRM10_Samples/ClothSample/ClothWarp/Runtime/Jobs/ClothWarpJobRuntime.cs index 16ef28e90..237d880be 100644 --- a/Assets/VRM10_Samples/ClothSample/ClothWarp/Runtime/Jobs/ClothWarpJobRuntime.cs +++ b/Assets/VRM10_Samples/ClothSample/ClothWarp/Runtime/Jobs/ClothWarpJobRuntime.cs @@ -43,7 +43,7 @@ namespace UniVRM10.ClothWarp.Jobs NativeArray _strandCollision; NativeArray _clothCollisionCount; - NativeArray _clothCollisionDelta; + NativeArray _clothCollision; NativeArray _forces; // @@ -72,7 +72,7 @@ namespace UniVRM10.ClothWarp.Jobs if (_nextRotations.IsCreated) _nextRotations.Dispose(); if (_strandCollision.IsCreated) _strandCollision.Dispose(); if (_clothCollisionCount.IsCreated) _clothCollisionCount.Dispose(); - if (_clothCollisionDelta.IsCreated) _clothCollisionDelta.Dispose(); + if (_clothCollision.IsCreated) _clothCollision.Dispose(); if (_forces.IsCreated) _forces.Dispose(); if (_warps.IsCreated) _warps.Dispose(); @@ -213,7 +213,7 @@ namespace UniVRM10.ClothWarp.Jobs _info = new(info.ToArray(), Allocator.Persistent); _strandCollision = new(pos.Length, Allocator.Persistent); _clothCollisionCount = new(pos.Length, Allocator.Persistent); - _clothCollisionDelta = new(pos.Length, Allocator.Persistent); + _clothCollision = new(pos.Length, Allocator.Persistent); _forces = new(pos.Length, Allocator.Persistent); // @@ -269,7 +269,7 @@ namespace UniVRM10.ClothWarp.Jobs Forces = _forces, CollisionCount = _clothCollisionCount, - CollisionDelta = _clothCollisionDelta, + CollisionDelta = _clothCollision, }.Schedule(_transformAccessArray, handle); // spring(cloth weft) @@ -279,7 +279,7 @@ namespace UniVRM10.ClothWarp.Jobs CurrentPositions = _currentPositions, Force = _forces, - }.Schedule(_clothRects.Length, 128, handle); + }.Schedule(_clothRects.Length, 1, handle); // verlet handle = new VerletJob @@ -293,7 +293,7 @@ namespace UniVRM10.ClothWarp.Jobs NextPositions = _nextPositions, NextRotations = _nextRotations, - }.Schedule(_info.Length, 128, handle); + }.Schedule(_info.Length, 1, handle); // 親子の長さで拘束 handle = new ParentLengthConstraintJob @@ -301,7 +301,7 @@ namespace UniVRM10.ClothWarp.Jobs Warps = _warps, Info = _info, NextPositions = _nextPositions, - }.Schedule(_warps.Length, 16, handle); + }.Schedule(_warps.Length, 1, handle); // collision { @@ -314,7 +314,7 @@ namespace UniVRM10.ClothWarp.Jobs NextPositions = _nextPositions, ClothUsedParticles = _clothUsedParticles, StrandCollision = _strandCollision, - }.Schedule(_info.Length, 128, handle); + }.Schedule(_info.Length, 1, handle); var handle1 = new ClothCollisionJob { @@ -324,10 +324,10 @@ namespace UniVRM10.ClothWarp.Jobs Info = _info, NextPositions = _nextPositions, CollisionCount = _clothCollisionCount, - CollisionDelta = _clothCollisionDelta, + ClothCollision = _clothCollision, ClothRects = _clothRects, - }.Schedule(_clothRects.Length, 128, handle); + }.Schedule(_clothRects.Length, 1, handle); handle = JobHandle.CombineDependencies(handle0, handle1); @@ -336,9 +336,9 @@ namespace UniVRM10.ClothWarp.Jobs ClothUsedParticles = _clothUsedParticles, StrandCollision = _strandCollision, ClothCollisionCount = _clothCollisionCount, - ClothCollisionDelta = _clothCollisionDelta, + ClothCollision = _clothCollision, NextPosition = _nextPositions, - }.Schedule(_info.Length, 128, handle); + }.Schedule(_info.Length, 1, handle); } // 親子の長さで拘束. TODO: ApplyRotationJob と合体 @@ -347,7 +347,7 @@ namespace UniVRM10.ClothWarp.Jobs Warps = _warps, Info = _info, NextPositions = _nextPositions, - }.Schedule(_warps.Length, 16, handle); + }.Schedule(_warps.Length, 1, handle); // NextPositions から NextRotations を作る handle = new ApplyRotationJob { @@ -356,7 +356,7 @@ namespace UniVRM10.ClothWarp.Jobs CurrentTransforms = _inputData, NextPositions = _nextPositions, NextRotations = _nextRotations, - }.Schedule(_warps.Length, 16, handle); + }.Schedule(_warps.Length, 1, handle); // output handle = new OutputTransformJob diff --git a/Assets/VRM10_Samples/ClothSample/ClothWarp/Runtime/Jobs/Collision.cs b/Assets/VRM10_Samples/ClothSample/ClothWarp/Runtime/Jobs/Collision.cs index ab5c6ec2a..49fa37d34 100644 --- a/Assets/VRM10_Samples/ClothSample/ClothWarp/Runtime/Jobs/Collision.cs +++ b/Assets/VRM10_Samples/ClothSample/ClothWarp/Runtime/Jobs/Collision.cs @@ -141,24 +141,35 @@ namespace UniVRM10.ClothWarp.Jobs [ReadOnly] public NativeArray Info; [ReadOnly] public NativeArray NextPositions; [NativeDisableParallelForRestriction] public NativeArray CollisionCount; - [NativeDisableParallelForRestriction] public NativeArray CollisionDelta; + [NativeDisableParallelForRestriction] public NativeArray ClothCollision; // cloth [ReadOnly] public NativeArray<(SpringConstraint, ClothRect)> ClothRects; - private void CollisionMove(int particleIndex, Vector3 delta) + private void CollisionMove(int particleIndex, LineSegment l, BlittableCollider c) { +#if false + CollisionCount[particleIndex] = 1; + ClothCollision[particleIndex] = l.GetPoint(c.radius); +#else + var delta = l.GetDelta(c.radius); + #if false // 足して割る CollisionCount[particleIndex] += 1; CollisionDelta[particleIndex] += delta; +#elif false + // 足す + CollisionCount[particleIndex] = 1; + CollisionDelta[particleIndex] += delta; #else - // 深いのに1回当てる - if (CollisionDelta[particleIndex].sqrMagnitude < delta.sqrMagnitude) + // max + if (delta.sqrMagnitude > ClothCollision[particleIndex].sqrMagnitude) { CollisionCount[particleIndex] = 1; - CollisionDelta[particleIndex] = delta; + ClothCollision[particleIndex] = delta; } +#endif #endif } @@ -206,15 +217,15 @@ namespace UniVRM10.ClothWarp.Jobs if (TryCollide(collider, collider_matrix, _triangle0, out var l0)) { - CollisionMove(rect._a, l0.GetDelta(collider.radius)); - CollisionMove(rect._b, l0.GetDelta(collider.radius)); - CollisionMove(rect._c, l0.GetDelta(collider.radius)); + CollisionMove(rect._a, l0, collider); + CollisionMove(rect._b, l0, collider); + CollisionMove(rect._c, l0, collider); } if (TryCollide(collider, collider_matrix, _triangle1, out var l1)) { - CollisionMove(rect._c, l1.GetDelta(collider.radius)); - CollisionMove(rect._d, l1.GetDelta(collider.radius)); - CollisionMove(rect._a, l1.GetDelta(collider.radius)); + CollisionMove(rect._c, l1, collider); + CollisionMove(rect._d, l1, collider); + CollisionMove(rect._a, l1, collider); } } } @@ -308,7 +319,7 @@ namespace UniVRM10.ClothWarp.Jobs [ReadOnly] public NativeArray ClothUsedParticles; [ReadOnly] public NativeArray StrandCollision; [ReadOnly] public NativeArray ClothCollisionCount; - [ReadOnly] public NativeArray ClothCollisionDelta; + [ReadOnly] public NativeArray ClothCollision; [NativeDisableParallelForRestriction] public NativeArray NextPosition; public void Execute(int particleIndex) @@ -317,7 +328,8 @@ namespace UniVRM10.ClothWarp.Jobs { if (ClothCollisionCount[particleIndex] > 0) { - NextPosition[particleIndex] += (ClothCollisionDelta[particleIndex] / ClothCollisionCount[particleIndex]); + NextPosition[particleIndex] += (ClothCollision[particleIndex] / ClothCollisionCount[particleIndex]); + // NextPosition[particleIndex] = ClothCollision[particleIndex]; } } else