diff options
Diffstat (limited to 'NvCloth/src/dx')
| -rw-r--r-- | NvCloth/src/dx/DxClothData.cpp | 1 | ||||
| -rw-r--r-- | NvCloth/src/dx/DxClothData.h | 3 | ||||
| -rw-r--r-- | NvCloth/src/dx/DxSolverKernel.hlsl | 15 |
3 files changed, 12 insertions, 7 deletions
diff --git a/NvCloth/src/dx/DxClothData.cpp b/NvCloth/src/dx/DxClothData.cpp index 075dc81..57049bf 100644 --- a/NvCloth/src/dx/DxClothData.cpp +++ b/NvCloth/src/dx/DxClothData.cpp @@ -112,6 +112,7 @@ cloth::DxFrameData::DxFrameData(DxCloth& cloth, uint32_t numSharedPositions, con Simd4f 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/dx/DxClothData.h b/NvCloth/src/dx/DxClothData.h index af02bc6..f91d37d 100644 --- a/NvCloth/src/dx/DxClothData.h +++ b/NvCloth/src/dx/DxClothData.h @@ -46,7 +46,7 @@ typedef unsigned int uint32_t; typedef int int32_t; #endif -static const uint32_t MaxParticlesInSharedMem = 1972; +static const uint32_t MaxParticlesInSharedMem = 1971; struct DxPhaseConfig @@ -167,6 +167,7 @@ struct DxFrameData // wind data float mDragCoefficient; float mLiftCoefficient; + float mFluidDensity; float mRotation[9]; // motion constraint data diff --git a/NvCloth/src/dx/DxSolverKernel.hlsl b/NvCloth/src/dx/DxSolverKernel.hlsl index 2ca42b3..4d91f4b 100644 --- a/NvCloth/src/dx/DxSolverKernel.hlsl +++ b/NvCloth/src/dx/DxSolverKernel.hlsl @@ -202,7 +202,8 @@ void applyWind(IParticles curParticles, IParticles prevParticles, uint32_t threa { 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; @@ -258,20 +259,22 @@ void applyWind(IParticles curParticles, IParticles prevParticles, uint32_t threa float3 normal = cross(c2.xyz - c0.xyz, c1.xyz - c0.xyz); - float doubleArea = sqrt(dot(normal, normal)); + const float doubleArea = sqrt(dot(normal, normal)); + normal = normal / doubleArea; float invSqrScale = dot(delta, delta); float scale = rsqrt(invSqrScale); + float deltaLength = sqrt(invSqrScale); - float cosTheta = dot(normal, delta) * scale / doubleArea; + float cosTheta = dot(normal, delta) * scale; float sinTheta = sqrt(max(0.0f, 1.0f - cosTheta * cosTheta)); float3 liftDir = cross(cross(delta, normal), scale * delta); - float3 lift = liftCoefficient * cosTheta * sinTheta * liftDir; - float3 drag = dragCoefficient * abs(cosTheta) * doubleArea * delta; + float3 lift = liftCoefficient * cosTheta * sinTheta * liftDir * deltaLength / itrDt; + float3 drag = dragCoefficient * abs(cosTheta) * delta * deltaLength / itrDt; - float3 impulse = invSqrScale < 1.192092896e-07F ? float3(0.0f, 0.0f, 0.0f) : lift + drag; + float3 impulse = invSqrScale < 1.192092896e-07F ? float3(0.0f, 0.0f, 0.0f) : (lift + drag) * fluidDensity * doubleArea; curParticles.atomicAdd(i0, -impulse * c0.w); curParticles.atomicAdd(i1, -impulse * c1.w); |