Fix T54609: Erros in precise BBox extraction algorithm
This commit is contained in:
parent
6a75a1a669
commit
b31ebd8c5c
Notes:
blender-bot
2023-05-03 10:14:48 +02:00
Referenced by commit 86abc4da10
, Fix rBb31ebd8c5c55: the asymmetric furstrum algorithm was still incorrect.
Referenced by issue #54609, DRW: Culling: Precise BBox extraction does not work correctly
|
@ -386,11 +386,10 @@ void DRW_state_clip_planes_reset(void)
|
|||
|
||||
/* Extract the 8 corners (world space).
|
||||
* Although less accurate, this solution can be simplified as follows:
|
||||
*
|
||||
* BKE_boundbox_init_from_minmax(&bbox, (const float[3]){-1.0f, -1.0f, -1.0f}, (const float[3]){1.0f, 1.0f, 1.0f});
|
||||
* for (int i = 0; i < 8; i++) {mul_project_m4_v3(viewprojinv, bbox.vec[i]);}
|
||||
*/
|
||||
static void UNUSED_FUNCTION(draw_frustum_boundbox_calc)(
|
||||
static void draw_frustum_boundbox_calc(
|
||||
const float (*projmat)[4], const float (*viewinv)[4], BoundBox *r_bbox)
|
||||
{
|
||||
float screenvecs[3][3], loc[3], near, far, w_half, h_half;
|
||||
|
@ -426,8 +425,8 @@ static void UNUSED_FUNCTION(draw_frustum_boundbox_calc)(
|
|||
madd_v3_v3fl(mid, ver, projmat[2][1]);
|
||||
}
|
||||
else {
|
||||
madd_v3_v3fl(mid, hor, projmat[3][0]);
|
||||
madd_v3_v3fl(mid, ver, projmat[3][1]);
|
||||
madd_v3_v3fl(mid, hor, -projmat[3][0]);
|
||||
madd_v3_v3fl(mid, ver, -projmat[3][1]);
|
||||
}
|
||||
|
||||
r_bbox->vec[0][0] = mid[0] - ver[0] - hor[0];
|
||||
|
@ -460,8 +459,8 @@ static void UNUSED_FUNCTION(draw_frustum_boundbox_calc)(
|
|||
madd_v3_v3v3fl(mid, loc, screenvecs[2], -far);
|
||||
|
||||
/* Non-symmetric frustum. */
|
||||
madd_v3_v3fl(mid, hor, projmat[3][0]);
|
||||
madd_v3_v3fl(mid, ver, projmat[3][1]);
|
||||
madd_v3_v3fl(mid, hor, -projmat[3][0]);
|
||||
madd_v3_v3fl(mid, ver, -projmat[3][1]);
|
||||
}
|
||||
|
||||
r_bbox->vec[1][0] = mid[0] - ver[0] - hor[0];
|
||||
|
@ -493,13 +492,13 @@ static void draw_clipping_setup_from_view(void)
|
|||
|
||||
/* Extract Clipping Planes */
|
||||
BoundBox bbox;
|
||||
#if 0 /* does not currently work for all casses. */
|
||||
draw_frustum_boundbox_calc(projmat, viewinv, &bbox);
|
||||
#else
|
||||
#if 0 /* It has accuracy problems. */
|
||||
BKE_boundbox_init_from_minmax(&bbox, (const float[3]){-1.0f, -1.0f, -1.0f}, (const float[3]){1.0f, 1.0f, 1.0f});
|
||||
for (int i = 0; i < 8; i++) {
|
||||
mul_project_m4_v3(DST.view_data.matstate.mat[DRW_MAT_PERSINV], bbox.vec[i]);
|
||||
}
|
||||
#else
|
||||
draw_frustum_boundbox_calc(projmat, viewinv, &bbox);
|
||||
#endif
|
||||
|
||||
/* Compute clip planes using the world space frustum corners. */
|
||||
|
|
Loading…
Reference in New Issue