diff options
Diffstat (limited to 'source/blender/draw/intern')
-rw-r--r-- | source/blender/draw/intern/draw_manager.h | 3 | ||||
-rw-r--r-- | source/blender/draw/intern/draw_manager_data.cc | 19 | ||||
-rw-r--r-- | source/blender/draw/intern/draw_shader_shared.h | 4 | ||||
-rw-r--r-- | source/blender/draw/intern/draw_view.cc | 8 | ||||
-rw-r--r-- | source/blender/draw/intern/shaders/common_view_lib.glsl | 13 |
5 files changed, 23 insertions, 24 deletions
diff --git a/source/blender/draw/intern/draw_manager.h b/source/blender/draw/intern/draw_manager.h index 67d0f79b83e..056f93d5d77 100644 --- a/source/blender/draw/intern/draw_manager.h +++ b/source/blender/draw/intern/draw_manager.h @@ -442,6 +442,9 @@ struct DRWView { struct DRWView *parent; ViewInfos storage; + + float4x4 persmat; + float4x4 persinv; /** Number of active clip planes. */ int clip_planes_len; /** Does culling result needs to be updated. */ diff --git a/source/blender/draw/intern/draw_manager_data.cc b/source/blender/draw/intern/draw_manager_data.cc index f5990010e9a..4ab522952b4 100644 --- a/source/blender/draw/intern/draw_manager_data.cc +++ b/source/blender/draw/intern/draw_manager_data.cc @@ -695,7 +695,7 @@ static void drw_call_obinfos_init(DRWObjectInfos *ob_infos, Object *ob) drw_call_calc_orco(ob, ob_infos->orcotexfac); /* Random float value. */ uint random = (DST.dupli_source) ? - DST.dupli_source->random_id : + DST.dupli_source->random_id : /* TODO(fclem): this is rather costly to do at runtime. Maybe we can * put it in ob->runtime and make depsgraph ensure it is up to date. */ BLI_hash_int_2d(BLI_hash_string(ob->id.name + 2), 0); @@ -2133,18 +2133,20 @@ static void draw_frustum_bound_sphere_calc(const BoundBox *bbox, } } -static void draw_view_matrix_state_update(ViewInfos *storage, +static void draw_view_matrix_state_update(DRWView *view, const float viewmat[4][4], const float winmat[4][4]) { + ViewInfos *storage = &view->storage; + copy_m4_m4(storage->viewmat.values, viewmat); invert_m4_m4(storage->viewinv.values, storage->viewmat.values); copy_m4_m4(storage->winmat.values, winmat); invert_m4_m4(storage->wininv.values, storage->winmat.values); - mul_m4_m4m4(storage->persmat.values, winmat, viewmat); - invert_m4_m4(storage->persinv.values, storage->persmat.values); + mul_m4_m4m4(view->persmat.values, winmat, viewmat); + invert_m4_m4(view->persinv.values, view->persmat.values); const bool is_persp = (winmat[3][3] == 0.0f); @@ -2260,7 +2262,7 @@ void DRW_view_update_sub(DRWView *view, const float viewmat[4][4], const float w view->is_dirty = true; view->is_inverted = (is_negative_m4(viewmat) == is_negative_m4(winmat)); - draw_view_matrix_state_update(&view->storage, viewmat, winmat); + draw_view_matrix_state_update(view, viewmat, winmat); } void DRW_view_update(DRWView *view, @@ -2277,7 +2279,7 @@ void DRW_view_update(DRWView *view, view->is_dirty = true; view->is_inverted = (is_negative_m4(viewmat) == is_negative_m4(winmat)); - draw_view_matrix_state_update(&view->storage, viewmat, winmat); + draw_view_matrix_state_update(view, viewmat, winmat); /* Prepare frustum culling. */ @@ -2318,7 +2320,7 @@ void DRW_view_update(DRWView *view, } draw_frustum_boundbox_calc(viewinv, winmat, &view->frustum_corners); - draw_frustum_culling_planes_calc(view->storage.persmat.values, view->frustum_planes); + draw_frustum_culling_planes_calc(view->persmat.values, view->frustum_planes); draw_frustum_bound_sphere_calc( &view->frustum_corners, viewinv, winmat, wininv, &view->frustum_bsphere); @@ -2433,8 +2435,7 @@ void DRW_view_winmat_get(const DRWView *view, float mat[4][4], bool inverse) void DRW_view_persmat_get(const DRWView *view, float mat[4][4], bool inverse) { view = (view) ? view : DST.view_default; - const ViewInfos *storage = &view->storage; - copy_m4_m4(mat, (inverse) ? storage->persinv.values : storage->persmat.values); + copy_m4_m4(mat, (inverse) ? view->persinv.values : view->persmat.values); } /** \} */ diff --git a/source/blender/draw/intern/draw_shader_shared.h b/source/blender/draw/intern/draw_shader_shared.h index a572b9ee865..c6cd15551b9 100644 --- a/source/blender/draw/intern/draw_shader_shared.h +++ b/source/blender/draw/intern/draw_shader_shared.h @@ -52,8 +52,6 @@ typedef enum eObjectInfoFlag eObjectInfoFlag; struct ViewInfos { /* View matrices */ - float4x4 persmat; - float4x4 persinv; float4x4 viewmat; float4x4 viewinv; float4x4 winmat; @@ -86,8 +84,6 @@ BLI_STATIC_ASSERT_ALIGN(ViewInfos, 16) /* Do not override old definitions if the shader uses this header but not shader info. */ #ifdef USE_GPU_SHADER_CREATE_INFO /* TODO(@fclem): Mass rename. */ -# define ViewProjectionMatrix drw_view.persmat -# define ViewProjectionMatrixInverse drw_view.persinv # define ViewMatrix drw_view.viewmat # define ViewMatrixInverse drw_view.viewinv # define ProjectionMatrix drw_view.winmat diff --git a/source/blender/draw/intern/draw_view.cc b/source/blender/draw/intern/draw_view.cc index cb0e1370c28..1e739cf0871 100644 --- a/source/blender/draw/intern/draw_view.cc +++ b/source/blender/draw/intern/draw_view.cc @@ -21,8 +21,6 @@ void View::sync(const float4x4 &view_mat, const float4x4 &win_mat) data_.viewinv = view_mat.inverted(); data_.winmat = win_mat; data_.wininv = win_mat.inverted(); - data_.persmat = data_.winmat * data_.viewmat; - data_.persinv = data_.persmat.inverted(); /* Should not be used anymore. */ data_.viewcamtexcofac = float4(1.0f, 1.0f, 0.0f, 0.0f); @@ -83,7 +81,8 @@ void View::frustum_boundbox_calc(BoundBox &bbox) void View::frustum_culling_planes_calc() { - planes_from_projmat(data_.persmat.ptr(), + float4x4 persmat = data_.winmat * data_.viewmat; + planes_from_projmat(persmat.ptr(), data_.frustum_planes[0], data_.frustum_planes[5], data_.frustum_planes[1], @@ -298,7 +297,8 @@ void View::compute_visibility(ObjectBoundsBuf &bounds, uint resource_len, bool d } #ifdef DEBUG if (debug_freeze) { - drw_debug_matrix_as_bbox(data_freeze_.persinv, float4(0, 1, 0, 1)); + float4x4 persmat = data_freeze_.winmat * data_freeze_.viewmat; + drw_debug_matrix_as_bbox(persmat.inverted(), float4(0, 1, 0, 1)); } #endif frozen_ = debug_freeze; diff --git a/source/blender/draw/intern/shaders/common_view_lib.glsl b/source/blender/draw/intern/shaders/common_view_lib.glsl index 6521476c3a7..46f16a9ca40 100644 --- a/source/blender/draw/intern/shaders/common_view_lib.glsl +++ b/source/blender/draw/intern/shaders/common_view_lib.glsl @@ -11,9 +11,6 @@ /* keep in sync with DRWManager.view_data */ layout(std140) uniform viewBlock { - /* Same order as DRWViewportMatrixType */ - mat4 ViewProjectionMatrix; - mat4 ViewProjectionMatrixInverse; mat4 ViewMatrix; mat4 ViewMatrixInverse; mat4 ProjectionMatrix; @@ -61,8 +58,9 @@ vec3 cameraVec(vec3 P) /* TODO move to overlay engine. */ float mul_project_m4_v3_zfac(in vec3 co) { - return pixelFac * ((ViewProjectionMatrix[0][3] * co.x) + (ViewProjectionMatrix[1][3] * co.y) + - (ViewProjectionMatrix[2][3] * co.z) + ViewProjectionMatrix[3][3]); + vec3 vP = (ViewMatrix * vec4(co, 1.0)).xyz; + return pixelFac * ((ProjectionMatrix[0][3] * vP.x) + (ProjectionMatrix[1][3] * vP.y) + + (ProjectionMatrix[2][3] * vP.z) + ProjectionMatrix[3][3]); } #endif @@ -267,13 +265,14 @@ uniform mat4 ModelMatrixInverse; #define normal_world_to_view(n) (mat3(ViewMatrix) * n) #define normal_view_to_world(n) (mat3(ViewMatrixInverse) * n) -#define point_object_to_ndc(p) (ViewProjectionMatrix * vec4((ModelMatrix * vec4(p, 1.0)).xyz, 1.0)) +#define point_object_to_ndc(p) \ + (ProjectionMatrix * (ViewMatrix * vec4((ModelMatrix * vec4(p, 1.0)).xyz, 1.0))) #define point_object_to_view(p) ((ViewMatrix * vec4((ModelMatrix * vec4(p, 1.0)).xyz, 1.0)).xyz) #define point_object_to_world(p) ((ModelMatrix * vec4(p, 1.0)).xyz) #define point_view_to_ndc(p) (ProjectionMatrix * vec4(p, 1.0)) #define point_view_to_object(p) ((ModelMatrixInverse * (ViewMatrixInverse * vec4(p, 1.0))).xyz) #define point_view_to_world(p) ((ViewMatrixInverse * vec4(p, 1.0)).xyz) -#define point_world_to_ndc(p) (ViewProjectionMatrix * vec4(p, 1.0)) +#define point_world_to_ndc(p) (ProjectionMatrix * (ViewMatrix * vec4(p, 1.0))) #define point_world_to_object(p) ((ModelMatrixInverse * vec4(p, 1.0)).xyz) #define point_world_to_view(p) ((ViewMatrix * vec4(p, 1.0)).xyz) |