llaman95 / bullet

Automatically exported from code.google.com/p/bullet
Other
0 stars 0 forks source link

Sofbody friction does not work correctly in OpenCL and Direct Compute solvers. #594

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
1. Create cloth and capsule with friction coefficient values ranging 0-1.
2. Start simulation using OpenCL or Direct Compute solvers
3. Cloth vs capsule simulation doesn't show difference even with different 
friction coefficient values.

What is the expected output? What do you see instead?
Based on friction coefficient values, cloth should slide over capsule in 
different manners like slowly or fast. Instead, the sliding motion seems always 
the same regardless of friction coefficient. 

What version of the product are you using? On what operating system?
Bullet SVN revision 2483, Windows 7.

Please provide any additional information below.
Addition to friction issue, softBody->getFriction() doesn't return friction 
coef. Instead, softBody->m_cfg.kDF should be used. This fix is included in the 
attached patch file. 

Collision object doesn't seems to import/export friction coef correctly. 
Following line in btSoftBodySolver_OpenCL.cpp returns 0.5 always when the 
collision object is imported.

float friction = collisionObject->getFriction();

This fix is not included in this patch. 

Comparing CPU and OpenCL/DC solvers, friction does not show the exactly same 
effect in the simulation even though the same friction model is used. CPU 
solver shows more sticky sliding when friction coef is 1.0 for cloth and 
capsule. 

Original issue reported on code.google.com by saggitas...@gmail.com on 24 Jan 2012 at 12:05

Attachments:

GoogleCodeExporter commented 8 years ago
The friction in the regular CPU version is position based, while the OpenCL 
version is using external forces. This is not OK. The GPU version should apply 
the friction the same as the CPU, directly projecting the position.

Here is the relevant code of the CPU friction in case you can't find it:

-------------------------------------------------
const btVector3 vr=vb-va; //relative velocity
const btScalar      dn=btDot(vr,c.m_cti.m_normal); //surface component
const btVector3 fv=vr-c.m_cti.m_normal*dn; //relative velocity on the surface

//If the friction coefficient times surface velocity component larger than 
surface velocity,
then c3 (1-fc) = 0, remaining surface velocity will be zero, otherwise leave 
some tangentialsurface velocity

c.m_c3      =   fv.length2()<(btFabs(dn)*fc) ? 0: 1-fc;

const btVector3     fv = vr - (cti.m_normal * dn);

// c0 is the impulse matrix, c3 is 1 - the friction coefficient or 0

const btVector3     impulse = c.m_c0 * 
(
(vr - 
(fv * c.m_c3) + 
(cti.m_normal * (dp * c.m_c4))
) * kst 
);

c.m_node->m_x -= impulse * c.m_c2; //m_x is the position of the node/vertex

Original comment by erwin.coumans on 3 Mar 2012 at 8:48

GoogleCodeExporter commented 8 years ago
There seem to be issues with the fourth/w component in the patch.

It is better to use the built-in functions for length, normalize, dot etc,
and not override them with custom versions in the kernel.

If the 4th component is not properly initialized on the CPU side, we should fix 
it there.

Original comment by erwin.coumans on 3 Mar 2012 at 8:52

GoogleCodeExporter commented 8 years ago
[deleted comment]
GoogleCodeExporter commented 8 years ago
I partly applied the patch, to make the Bullet/Demos/SerializeDemo_AMD work, a 
modified version of SolveCollisionsAndUpdateVelocitiesSIMDBatched.cl (applying 
friction by projecting the position instead of using external forces)

The patch broke the MiniCL version of AppOpenCLClothDemo_Mini, so I didn't 
apply any changes to btSoftBodySolver_OpenCL.* and 
SolveCollisionsAndUpdateVelocities.cl

See http://code.google.com/p/bullet/source/detail?r=2518

Original comment by erwin.coumans on 4 Mar 2012 at 10:16

GoogleCodeExporter commented 8 years ago
Erwin, 

What do mean modified version of 
SolveCollisionsAndUpdateVelocitiesSIMDBatched.cl? Who do you mean 'modified' 
the cl file?

Original comment by saggitas...@gmail.com on 4 Mar 2012 at 10:28

GoogleCodeExporter commented 8 years ago
The position is updated rather than the (external) force. A few other changes 
are made around those lines. See the code around line 222 in the following link:

http://code.google.com/p/bullet/source/diff?spec=svn2518&r=2518&format=side&path
=/trunk/src/BulletMultiThreaded/GpuSoftBodySolvers/OpenCL/OpenCLC10/SolveCollisi
onsAndUpdateVelocitiesSIMDBatched.cl

Original comment by erwin.coumans on 4 Mar 2012 at 11:06

GoogleCodeExporter commented 8 years ago
[deleted comment]
GoogleCodeExporter commented 8 years ago
Eventually the GPU version should apply exactly the same friction as the CPU 
version,
as pointed out in comment #1 
http://code.google.com/p/bullet/issues/detail?id=594#c1

Hopefully you can help sorting this out?

I'm just applying this patch, so the demos will run reasonably for the new 
Bullet 2.80 release.

Original comment by erwin.coumans on 4 Mar 2012 at 11:10

GoogleCodeExporter commented 8 years ago
We will re-implement this from scratch in Bullet 3, see also 
https://github.com/bulletphysics/bullet3/issues/15

Original comment by erwin.coumans on 30 Mar 2014 at 7:35