diff options
Diffstat (limited to 'NvCloth/src/cuda')
| -rw-r--r-- | NvCloth/src/cuda/CuClothData.cpp | 1 | ||||
| -rw-r--r-- | NvCloth/src/cuda/CuClothData.h | 1 | ||||
| -rw-r--r-- | NvCloth/src/cuda/CuSolverKernel.cu | 14 |
3 files changed, 11 insertions, 5 deletions
diff --git a/NvCloth/src/cuda/CuClothData.cpp b/NvCloth/src/cuda/CuClothData.cpp index decfd2c..927997c 100644 --- a/NvCloth/src/cuda/CuClothData.cpp +++ b/NvCloth/src/cuda/CuClothData.cpp @@ -124,6 +124,7 @@ cloth::CuFrameData::CuFrameData(CuCloth& cloth, uint32_t numSharedPositions, con stiffness = gSimd4fOne - exp2(logStiffness * stiffnessExponent); mDragCoefficient = array(stiffness)[0]; mLiftCoefficient = array(stiffness)[1]; + mFluidDensity = cloth.mFluidDensity * 0.5f; //divide by 2 to so we don't have to compensate for double area from cross product in the solver for (int i = 0; i < 9; ++i) mRotation[i] = array(state.mRotationMatrix[i / 3])[i % 3]; diff --git a/NvCloth/src/cuda/CuClothData.h b/NvCloth/src/cuda/CuClothData.h index 0e4cda0..dd836fd 100644 --- a/NvCloth/src/cuda/CuClothData.h +++ b/NvCloth/src/cuda/CuClothData.h @@ -135,6 +135,7 @@ struct CuFrameData // wind data float mDragCoefficient; float mLiftCoefficient; + float mFluidDensity; float mRotation[9]; // motion constraint data diff --git a/NvCloth/src/cuda/CuSolverKernel.cu b/NvCloth/src/cuda/CuSolverKernel.cu index 3517193..edb66dc 100644 --- a/NvCloth/src/cuda/CuSolverKernel.cu +++ b/NvCloth/src/cuda/CuSolverKernel.cu @@ -867,6 +867,8 @@ __device__ void applyWind(CurrentT& current, PreviousT& previous) { const float dragCoefficient = gFrameData.mDragCoefficient; const float liftCoefficient = gFrameData.mLiftCoefficient; + const float fluidDensity = gFrameData.mFluidDensity; + const float itrDt = gFrameData.mIterDt; if (dragCoefficient == 0.0f && liftCoefficient == 0.0f) return; @@ -912,20 +914,22 @@ __device__ void applyWind(CurrentT& current, PreviousT& previous) float3 normal = cross3(c2 - c0, c1 - c0); - float doubleArea = sqrtf(dot3(normal, normal)); + const float doubleArea = sqrtf(dot3(normal, normal)); + normal = (1.0f / doubleArea) * normal; float invSqrScale = dot3(delta, delta); float scale = rsqrtf(invSqrScale); + float deltaLength = sqrtf(invSqrScale); - float cosTheta = dot3(normal, delta) * scale / doubleArea; + float cosTheta = dot3(normal, delta) * scale; float sinTheta = sqrtf(max(0.0f, 1.0f - cosTheta * cosTheta)); float3 liftDir = cross3(cross3(delta, normal), scale * delta); - float3 lift = liftCoefficient * cosTheta * sinTheta * liftDir; - float3 drag = dragCoefficient * abs(cosTheta) * doubleArea * delta; + float3 lift = liftCoefficient * cosTheta * sinTheta * ((deltaLength / itrDt) * liftDir); + float3 drag = dragCoefficient * abs(cosTheta) * ((deltaLength / itrDt) * delta); - float3 impulse = invSqrScale < FLT_EPSILON ? make_float3(0.0f, 0.0f, 0.0f) : lift + drag; + float3 impulse = invSqrScale < FLT_EPSILON ? make_float3(0.0f, 0.0f, 0.0f) : fluidDensity * doubleArea * (lift + drag); applyImpulse(current(i0), impulse); applyImpulse(current(i1), impulse); |