Fix T93520: wrong subframe motion blur with rigid body physics

The code here was using velocity based interpolation copied from particles.
However there is no velocity cached in the rigid body point cache so the
results were non-sensical.
This commit is contained in:
Brecht Van Lommel 2022-01-20 20:28:56 +01:00
parent 24e00c115c
commit e1ae95f6b2
Notes: blender-bot 2023-10-04 09:42:55 +02:00
Referenced by issue #97204, Regression: Eevee & Cycles motion blur doesn't work correctly
Referenced by issue #95527, Regression: Motion blur resulting from rigid body simulation vectors is amplified / wrong / too strong
Referenced by issue #93520, Wrong motion blur with RBDs (wrong subframe interpolation?)
1 changed files with 11 additions and 19 deletions

View File

@ -831,31 +831,23 @@ static void ptcache_rigidbody_interpolate(int index,
RigidBodyOb *rbo = ob->rigidbody_object;
if (rbo->type == RBO_TYPE_ACTIVE) {
ParticleKey keys[4];
ParticleKey result;
float dfra;
memset(keys, 0, sizeof(keys));
copy_v3_v3(keys[1].co, rbo->pos);
copy_qt_qt(keys[1].rot, rbo->orn);
/* It may be possible to improve results by taking into account velocity
* for interpolation using psys_interpolate_particle, however this is
* not currently cached. */
float pos[3], orn[4];
if (old_data) {
memcpy(keys[2].co, data, sizeof(float[3]));
memcpy(keys[2].rot, data + 3, sizeof(float[4]));
memcpy(pos, data, sizeof(float[3]));
memcpy(orn, data + 3, sizeof(float[4]));
}
else {
BKE_ptcache_make_particle_key(&keys[2], 0, data, cfra2);
PTCACHE_DATA_TO(data, BPHYS_DATA_LOCATION, index, pos);
PTCACHE_DATA_TO(data, BPHYS_DATA_ROTATION, index, orn);
}
dfra = cfra2 - cfra1;
/* NOTE: keys[0] and keys[3] unused for type < 1 (crappy). */
psys_interpolate_particle(-1, keys, (cfra - cfra1) / dfra, &result, true);
interp_qt_qtqt(result.rot, keys[1].rot, keys[2].rot, (cfra - cfra1) / dfra);
copy_v3_v3(rbo->pos, result.co);
copy_qt_qt(rbo->orn, result.rot);
const float t = (cfra - cfra1) / (cfra2 - cfra1);
interp_v3_v3v3(rbo->pos, rbo->pos, pos, t);
interp_qt_qtqt(rbo->orn, rbo->orn, orn, t);
}
}
}