mirror of
https://github.com/panda3d/panda3d.git
synced 2025-10-01 17:35:34 -04:00
Fix broken convergence distance calculation, adding a configuration variable to restore the old behavior if needed.
This commit is contained in:
parent
70f73a5ea1
commit
bb7a6a3ec4
@ -510,6 +510,16 @@ ConfigVariableInt lens_geom_segments
|
|||||||
"lens; for a normal perspective or orthographic lens, the "
|
"lens; for a normal perspective or orthographic lens, the "
|
||||||
"wireframe is not subdivided."));
|
"wireframe is not subdivided."));
|
||||||
|
|
||||||
|
ConfigVariableBool stereo_lens_old_convergence
|
||||||
|
("stereo-lens-old-convergence", false,
|
||||||
|
PRC_DESC("In Panda3D 1.8 and below, when using a stereo lens, Panda "
|
||||||
|
"generate an incorrect frustum skew for a given convergence "
|
||||||
|
"distance, meaning that the left-right images wouldn't "
|
||||||
|
"overlap at the configured distance. This calculation has "
|
||||||
|
"since been corrected, but if your application relies on the "
|
||||||
|
"old, incorrect behavior, this may be set to 'true' to switch "
|
||||||
|
"back to the old calculation."));
|
||||||
|
|
||||||
ConfigVariableString cg_glsl_version
|
ConfigVariableString cg_glsl_version
|
||||||
("cg-glsl-version", "",
|
("cg-glsl-version", "",
|
||||||
PRC_DESC("If this is set, it forces the Cg compiler to generate GLSL "
|
PRC_DESC("If this is set, it forces the Cg compiler to generate GLSL "
|
||||||
|
@ -98,6 +98,7 @@ extern EXPCL_PANDA_GOBJ ConfigVariableDouble adaptive_lru_weight;
|
|||||||
extern EXPCL_PANDA_GOBJ ConfigVariableInt adaptive_lru_max_updates_per_frame;
|
extern EXPCL_PANDA_GOBJ ConfigVariableInt adaptive_lru_max_updates_per_frame;
|
||||||
extern EXPCL_PANDA_GOBJ ConfigVariableDouble async_load_delay;
|
extern EXPCL_PANDA_GOBJ ConfigVariableDouble async_load_delay;
|
||||||
extern EXPCL_PANDA_GOBJ ConfigVariableInt lens_geom_segments;
|
extern EXPCL_PANDA_GOBJ ConfigVariableInt lens_geom_segments;
|
||||||
|
extern EXPCL_PANDA_GOBJ ConfigVariableBool stereo_lens_old_convergence;
|
||||||
|
|
||||||
extern EXPCL_PANDA_GOBJ ConfigVariableString cg_glsl_version;
|
extern EXPCL_PANDA_GOBJ ConfigVariableString cg_glsl_version;
|
||||||
|
|
||||||
|
@ -608,14 +608,26 @@ get_interocular_distance() const {
|
|||||||
// PerspectiveLens.
|
// PerspectiveLens.
|
||||||
//
|
//
|
||||||
// This parameter must be greater than 0, but may be as
|
// This parameter must be greater than 0, but may be as
|
||||||
// large as you like. It controls the amount to which
|
// large as you like. It controls the distance at
|
||||||
// the two eyes are directed inwards towards each other,
|
// which the two stereo images will appear to converge,
|
||||||
// which is a normal property of stereo vision. It is a
|
// which is a normal property of stereo vision. Normally
|
||||||
// distance, not an angle; normally this should be set
|
// this should be set to the distance from the camera to
|
||||||
// to the distance from the camera to the area of
|
// the area of interest in your scene. Anything beyond
|
||||||
// interest in your scene. If you want to simulate
|
// this distance will appear to go into the screen, and
|
||||||
// parallel stereo, set this value to a very large
|
// anything closer will appear to come out of the screen.
|
||||||
// number.
|
// If you want to simulate parallel stereo, set this
|
||||||
|
// to infinity.
|
||||||
|
//
|
||||||
|
// Note that this creates an off-axis frustum, which
|
||||||
|
// means that the lenses are still pointing in the
|
||||||
|
// same direction, which is usually more desirable
|
||||||
|
// than the more naive toe-in approach, where the
|
||||||
|
// two lenses are simply tilted toward each other.
|
||||||
|
//
|
||||||
|
// Prior to Panda3D 1.9.0, the convergence was being
|
||||||
|
// calculated incorrectly. It has since been corrected.
|
||||||
|
// To restore the legacy behavior you can set the
|
||||||
|
// stereo-lens-old-convergence variable to true.
|
||||||
//
|
//
|
||||||
// Also see set_interocular_distance(), which relates.
|
// Also see set_interocular_distance(), which relates.
|
||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
|
@ -138,9 +138,16 @@ do_compute_projection_mat(Lens::CData *lens_cdata) {
|
|||||||
lens_cdata->_projection_mat_left = do_get_lens_mat_inv(lens_cdata) * LMatrix4::translate_mat(-iod) * canonical * do_get_film_mat(lens_cdata);
|
lens_cdata->_projection_mat_left = do_get_lens_mat_inv(lens_cdata) * LMatrix4::translate_mat(-iod) * canonical * do_get_film_mat(lens_cdata);
|
||||||
lens_cdata->_projection_mat_right = do_get_lens_mat_inv(lens_cdata) * LMatrix4::translate_mat(iod) * canonical * do_get_film_mat(lens_cdata);
|
lens_cdata->_projection_mat_right = do_get_lens_mat_inv(lens_cdata) * LMatrix4::translate_mat(iod) * canonical * do_get_film_mat(lens_cdata);
|
||||||
|
|
||||||
if (lens_cdata->_user_flags & UF_convergence_distance) {
|
if ((lens_cdata->_user_flags & UF_convergence_distance) != 0 &&
|
||||||
|
!cinf(lens_cdata->_convergence_distance)) {
|
||||||
nassertv(lens_cdata->_convergence_distance != 0.0f);
|
nassertv(lens_cdata->_convergence_distance != 0.0f);
|
||||||
LVector3 cd = (0.25f / lens_cdata->_convergence_distance) * LVector3::left(lens_cdata->_cs);
|
LVector3 cd;
|
||||||
|
if (stereo_lens_old_convergence) { // The old, incorrect calculation was requested.
|
||||||
|
cd = (0.25f / lens_cdata->_convergence_distance) * LVector3::left(lens_cdata->_cs);
|
||||||
|
} else {
|
||||||
|
const LVecBase2 &fov = do_get_fov(lens_cdata);
|
||||||
|
cd = (2.0f / fov_to_film(fov[0], lens_cdata->_convergence_distance, true)) * iod;
|
||||||
|
}
|
||||||
lens_cdata->_projection_mat_left *= LMatrix4::translate_mat(cd);
|
lens_cdata->_projection_mat_left *= LMatrix4::translate_mat(cd);
|
||||||
lens_cdata->_projection_mat_right *= LMatrix4::translate_mat(-cd);
|
lens_cdata->_projection_mat_right *= LMatrix4::translate_mat(-cd);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user