diff options
author | Clément Foucault <foucault.clem@gmail.com> | 2022-10-07 01:06:27 +0300 |
---|---|---|
committer | Clément Foucault <foucault.clem@gmail.com> | 2022-10-07 13:43:10 +0300 |
commit | a945cf4d0fc38f3c84747767612ad1d748ceb2a0 (patch) | |
tree | 72aa5ff66b79168506cb9542d0144d42c10dd1d4 /source | |
parent | 223f970407666828922616f1646768433ab7e7a0 (diff) |
DRW: Move clipping planes to their own UBO
This is part of the effor to simplify the View struct in order to implement
multiview rendering.
Diffstat (limited to 'source')
17 files changed, 41 insertions, 37 deletions
diff --git a/source/blender/draw/engines/gpencil/shaders/infos/gpencil_info.hh b/source/blender/draw/engines/gpencil/shaders/infos/gpencil_info.hh index ee22362e0d4..9936a7bdf99 100644 --- a/source/blender/draw/engines/gpencil/shaders/infos/gpencil_info.hh +++ b/source/blender/draw/engines/gpencil/shaders/infos/gpencil_info.hh @@ -26,7 +26,7 @@ GPU_SHADER_CREATE_INFO(gpencil_geometry) .sampler(1, ImageType::FLOAT_2D, "gpStrokeTexture") .sampler(2, ImageType::DEPTH_2D, "gpSceneDepthTexture") .sampler(3, ImageType::FLOAT_2D, "gpMaskTexture") - .uniform_buf(2, "gpMaterial", "materials[GPENCIL_MATERIAL_BUFFER_LEN]", Frequency::BATCH) + .uniform_buf(4, "gpMaterial", "materials[GPENCIL_MATERIAL_BUFFER_LEN]", Frequency::BATCH) .uniform_buf(3, "gpLight", "lights[GPENCIL_LIGHT_BUFFER_LEN]", Frequency::BATCH) /* Per Object */ .push_constant(Type::VEC3, "gpNormal") diff --git a/source/blender/draw/engines/overlay/shaders/infos/overlay_extra_info.hh b/source/blender/draw/engines/overlay/shaders/infos/overlay_extra_info.hh index 690d12b7020..4874f251d67 100644 --- a/source/blender/draw/engines/overlay/shaders/infos/overlay_extra_info.hh +++ b/source/blender/draw/engines/overlay/shaders/infos/overlay_extra_info.hh @@ -110,12 +110,12 @@ GPU_SHADER_CREATE_INFO(overlay_extra_wire) GPU_SHADER_CREATE_INFO(overlay_extra_wire_select) .do_static_compilation(true) .define("SELECT_EDGES") - .additional_info("overlay_extra_wire", "drw_clipped"); + .additional_info("overlay_extra_wire"); GPU_SHADER_CREATE_INFO(overlay_extra_wire_object) .do_static_compilation(true) .define("OBJECT_WIRE") - .additional_info("overlay_extra_wire", "drw_clipped"); + .additional_info("overlay_extra_wire"); GPU_SHADER_CREATE_INFO(overlay_extra_wire_select_clipped) .do_static_compilation(true) diff --git a/source/blender/draw/intern/draw_common.h b/source/blender/draw/intern/draw_common.h index d31c98e0dee..b5e9b3ee8bd 100644 --- a/source/blender/draw/intern/draw_common.h +++ b/source/blender/draw/intern/draw_common.h @@ -132,6 +132,7 @@ struct DRW_Global { struct GPUTexture *weight_ramp; struct GPUUniformBuf *view_ubo; + struct GPUUniformBuf *clipping_ubo; }; extern struct DRW_Global G_draw; diff --git a/source/blender/draw/intern/draw_defines.h b/source/blender/draw/intern/draw_defines.h index 2a50cc6f17b..f5976ddd34e 100644 --- a/source/blender/draw/intern/draw_defines.h +++ b/source/blender/draw/intern/draw_defines.h @@ -13,6 +13,7 @@ #define DRW_VIEW_UBO_SLOT 0 #define DRW_VIEW_CULLING_UBO_SLOT 1 +#define DRW_CLIPPING_UBO_SLOT 2 #define DRW_RESOURCE_ID_SLOT 11 #define DRW_OBJ_MAT_SLOT 10 diff --git a/source/blender/draw/intern/draw_manager.c b/source/blender/draw/intern/draw_manager.c index 50ea27efba1..83dc08f2f23 100644 --- a/source/blender/draw/intern/draw_manager.c +++ b/source/blender/draw/intern/draw_manager.c @@ -612,6 +612,11 @@ static void drw_manager_init(DRWManager *dst, GPUViewport *viewport, const int s G_draw.view_ubo = GPU_uniformbuf_create_ex(sizeof(ViewInfos), NULL, "G_draw.view_ubo"); } + if (G_draw.clipping_ubo == NULL) { + G_draw.clipping_ubo = GPU_uniformbuf_create_ex( + sizeof(float4) * 6, NULL, "G_draw.clipping_ubo"); + } + if (dst->draw_list == NULL) { dst->draw_list = GPU_draw_list_create(DRW_DRAWLIST_LEN); } @@ -3079,6 +3084,7 @@ void DRW_engines_free(void) DRW_UBO_FREE_SAFE(G_draw.block_ubo); DRW_UBO_FREE_SAFE(G_draw.view_ubo); + DRW_UBO_FREE_SAFE(G_draw.clipping_ubo); DRW_TEXTURE_FREE_SAFE(G_draw.ramp); DRW_TEXTURE_FREE_SAFE(G_draw.weight_ramp); diff --git a/source/blender/draw/intern/draw_manager.h b/source/blender/draw/intern/draw_manager.h index 056f93d5d77..f9baf3994ae 100644 --- a/source/blender/draw/intern/draw_manager.h +++ b/source/blender/draw/intern/draw_manager.h @@ -443,6 +443,8 @@ struct DRWView { ViewInfos storage; + float4 clip_planes[6]; + float4x4 persmat; float4x4 persinv; /** Number of active clip planes. */ diff --git a/source/blender/draw/intern/draw_manager_data.cc b/source/blender/draw/intern/draw_manager_data.cc index b7e237231ff..42c574dd4d5 100644 --- a/source/blender/draw/intern/draw_manager_data.cc +++ b/source/blender/draw/intern/draw_manager_data.cc @@ -1629,6 +1629,7 @@ static void drw_shgroup_init(DRWShadingGroup *shgroup, GPUShader *shader) shgroup->uniforms = nullptr; shgroup->uniform_attrs = nullptr; + int clipping_ubo_location = GPU_shader_get_builtin_block(shader, GPU_UNIFORM_BLOCK_DRW_CLIPPING); int view_ubo_location = GPU_shader_get_builtin_block(shader, GPU_UNIFORM_BLOCK_VIEW); int model_ubo_location = GPU_shader_get_builtin_block(shader, GPU_UNIFORM_BLOCK_MODEL); int info_ubo_location = GPU_shader_get_builtin_block(shader, GPU_UNIFORM_BLOCK_INFO); @@ -1702,6 +1703,16 @@ static void drw_shgroup_init(DRWShadingGroup *shgroup, GPUShader *shader) shgroup, view_ubo_location, DRW_UNIFORM_BLOCK, G_draw.view_ubo, GPU_SAMPLER_DEFAULT, 0, 1); } + if (clipping_ubo_location) { + drw_shgroup_uniform_create_ex(shgroup, + clipping_ubo_location, + DRW_UNIFORM_BLOCK, + G_draw.clipping_ubo, + GPU_SAMPLER_DEFAULT, + 0, + 1); + } + #ifdef DEBUG int debug_print_location = GPU_shader_get_builtin_ssbo(shader, GPU_STORAGE_BUFFER_DEBUG_PRINT); if (debug_print_location != -1) { @@ -2144,8 +2155,6 @@ static void draw_view_matrix_state_update(DRWView *view, 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); } DRWView *DRW_view_create(const float viewmat[4][4], @@ -2305,7 +2314,7 @@ void DRW_view_clip_planes_set(DRWView *view, float (*planes)[4], int plane_len) BLI_assert(plane_len <= MAX_CLIP_PLANES); view->clip_planes_len = plane_len; if (plane_len > 0) { - memcpy(view->storage.clip_planes, planes, sizeof(float[4]) * plane_len); + memcpy(view->clip_planes, planes, sizeof(float[4]) * plane_len); } } diff --git a/source/blender/draw/intern/draw_manager_exec.c b/source/blender/draw/intern/draw_manager_exec.c index 0e39cc1d3b9..1660239735b 100644 --- a/source/blender/draw/intern/draw_manager_exec.c +++ b/source/blender/draw/intern/draw_manager_exec.c @@ -1155,6 +1155,7 @@ static void drw_update_view(const float viewport_size[2]) /* TODO(fclem): update a big UBO and only bind ranges here. */ GPU_uniformbuf_update(G_draw.view_ubo, &DST.view_active->storage); + GPU_uniformbuf_update(G_draw.clipping_ubo, &DST.view_active->clip_planes); /* TODO: get rid of this. */ DST.view_storage_cpy = DST.view_active->storage; diff --git a/source/blender/draw/intern/draw_shader_shared.h b/source/blender/draw/intern/draw_shader_shared.h index c0c717d910d..3a5c5db8da3 100644 --- a/source/blender/draw/intern/draw_shader_shared.h +++ b/source/blender/draw/intern/draw_shader_shared.h @@ -67,8 +67,6 @@ struct ViewInfos { float4x4 winmat; float4x4 wininv; - float4 clip_planes[6]; - float2 viewport_size; float2 viewport_size_inverse; @@ -89,7 +87,6 @@ BLI_STATIC_ASSERT_ALIGN(ViewInfos, 16) # define ViewMatrixInverse drw_view.viewinv # define ProjectionMatrix drw_view.winmat # define ProjectionMatrixInverse drw_view.wininv -# define clipPlanes drw_view.clip_planes #endif /** \} */ diff --git a/source/blender/draw/intern/draw_view.cc b/source/blender/draw/intern/draw_view.cc index 3475b11be89..aa32549de56 100644 --- a/source/blender/draw/intern/draw_view.cc +++ b/source/blender/draw/intern/draw_view.cc @@ -203,15 +203,6 @@ void View::frustum_culling_sphere_calc(const BoundBox &bbox, BoundSphere &bspher } } -void View::set_clip_planes(Span<float4> planes) -{ - BLI_assert(planes.size() <= ARRAY_SIZE(data_.clip_planes)); - int i = 0; - for (const auto &plane : planes) { - data_.clip_planes[i++] = plane; - } -} - void View::update_viewport_size() { float4 viewport; diff --git a/source/blender/draw/intern/draw_view.hh b/source/blender/draw/intern/draw_view.hh index bc9033c2a65..aef8b5865be 100644 --- a/source/blender/draw/intern/draw_view.hh +++ b/source/blender/draw/intern/draw_view.hh @@ -50,8 +50,6 @@ class View { this->sync(view_mat, win_mat); } - void set_clip_planes(Span<float4> planes); - void sync(const float4x4 &view_mat, const float4x4 &win_mat); bool is_persp() const diff --git a/source/blender/draw/intern/shaders/common_view_clipping_lib.glsl b/source/blender/draw/intern/shaders/common_view_clipping_lib.glsl index d6dfa326511..4ff6a9a3778 100644 --- a/source/blender/draw/intern/shaders/common_view_clipping_lib.glsl +++ b/source/blender/draw/intern/shaders/common_view_clipping_lib.glsl @@ -7,12 +7,12 @@ void view_clipping_distances(vec3 wpos) { # ifdef USE_WORLD_CLIP_PLANES vec4 pos_4d = vec4(wpos, 1.0); - gl_ClipDistance[0] = dot(drw_view.clip_planes[0], pos_4d); - gl_ClipDistance[1] = dot(drw_view.clip_planes[1], pos_4d); - gl_ClipDistance[2] = dot(drw_view.clip_planes[2], pos_4d); - gl_ClipDistance[3] = dot(drw_view.clip_planes[3], pos_4d); - gl_ClipDistance[4] = dot(drw_view.clip_planes[4], pos_4d); - gl_ClipDistance[5] = dot(drw_view.clip_planes[5], pos_4d); + gl_ClipDistance[0] = dot(drw_clipping[0], pos_4d); + gl_ClipDistance[1] = dot(drw_clipping[1], pos_4d); + gl_ClipDistance[2] = dot(drw_clipping[2], pos_4d); + gl_ClipDistance[3] = dot(drw_clipping[3], pos_4d); + gl_ClipDistance[4] = dot(drw_clipping[4], pos_4d); + gl_ClipDistance[5] = dot(drw_clipping[5], pos_4d); # endif } diff --git a/source/blender/draw/intern/shaders/common_view_lib.glsl b/source/blender/draw/intern/shaders/common_view_lib.glsl index a09bccc4f2e..eafa36c4351 100644 --- a/source/blender/draw/intern/shaders/common_view_lib.glsl +++ b/source/blender/draw/intern/shaders/common_view_lib.glsl @@ -15,8 +15,6 @@ layout(std140) uniform viewBlock mat4 ViewMatrixInverse; mat4 ProjectionMatrix; mat4 ProjectionMatrixInverse; - - vec4 clipPlanes[6]; }; #endif /* USE_GPU_SHADER_CREATE_INFO */ @@ -38,12 +36,6 @@ vec3 cameraVec(vec3 P) } #define viewCameraVec(vP) ((ProjectionMatrix[3][3] == 0.0) ? normalize(-vP) : vec3(0.0, 0.0, 1.0)) -#ifdef world_clip_planes_calc_clip_distance -# undef world_clip_planes_calc_clip_distance -# define world_clip_planes_calc_clip_distance(p) \ - _world_clip_planes_calc_clip_distance(p, clipPlanes) -#endif - #ifdef COMMON_GLOBALS_LIB /* TODO move to overlay engine. */ float mul_project_m4_v3_zfac(in vec3 co) diff --git a/source/blender/draw/intern/shaders/draw_object_infos_info.hh b/source/blender/draw/intern/shaders/draw_object_infos_info.hh index 31fee018fbc..ad0426e6d3f 100644 --- a/source/blender/draw/intern/shaders/draw_object_infos_info.hh +++ b/source/blender/draw/intern/shaders/draw_object_infos_info.hh @@ -13,11 +13,11 @@ GPU_SHADER_CREATE_INFO(draw_object_infos) GPU_SHADER_CREATE_INFO(draw_volume_infos) .typedef_source("draw_shader_shared.h") - .uniform_buf(2, "VolumeInfos", "drw_volume", Frequency::BATCH); + .uniform_buf(3, "VolumeInfos", "drw_volume", Frequency::BATCH); GPU_SHADER_CREATE_INFO(draw_curves_infos) .typedef_source("draw_shader_shared.h") - .uniform_buf(2, "CurvesInfos", "drw_curves", Frequency::BATCH); + .uniform_buf(3, "CurvesInfos", "drw_curves", Frequency::BATCH); GPU_SHADER_CREATE_INFO(draw_object_infos_new) .typedef_source("draw_shader_shared.h") diff --git a/source/blender/draw/intern/shaders/draw_view_info.hh b/source/blender/draw/intern/shaders/draw_view_info.hh index b33deebadd5..5ebf3853266 100644 --- a/source/blender/draw/intern/shaders/draw_view_info.hh +++ b/source/blender/draw/intern/shaders/draw_view_info.hh @@ -75,7 +75,10 @@ GPU_SHADER_CREATE_INFO(draw_modelmat_instanced_attr) /** \name Draw View * \{ */ -GPU_SHADER_CREATE_INFO(drw_clipped).define("USE_WORLD_CLIP_PLANES"); +GPU_SHADER_CREATE_INFO(drw_clipped) + /* TODO(fclem): Move to engine side. */ + .uniform_buf(DRW_CLIPPING_UBO_SLOT, "vec4", "drw_clipping[6]", Frequency::PASS) + .define("USE_WORLD_CLIP_PLANES"); /** \} */ diff --git a/source/blender/gpu/GPU_shader.h b/source/blender/gpu/GPU_shader.h index 2e70bd77205..3f35db42eb9 100644 --- a/source/blender/gpu/GPU_shader.h +++ b/source/blender/gpu/GPU_shader.h @@ -145,6 +145,7 @@ typedef enum { GPU_UNIFORM_BLOCK_DRW_VIEW, GPU_UNIFORM_BLOCK_DRW_MODEL, GPU_UNIFORM_BLOCK_DRW_INFOS, + GPU_UNIFORM_BLOCK_DRW_CLIPPING, GPU_NUM_UNIFORM_BLOCKS, /* Special value, denotes number of builtin uniforms block. */ } GPUUniformBlockBuiltin; diff --git a/source/blender/gpu/intern/gpu_shader_interface.hh b/source/blender/gpu/intern/gpu_shader_interface.hh index 41e06569bdc..d223daa4a61 100644 --- a/source/blender/gpu/intern/gpu_shader_interface.hh +++ b/source/blender/gpu/intern/gpu_shader_interface.hh @@ -228,6 +228,8 @@ inline const char *ShaderInterface::builtin_uniform_block_name(GPUUniformBlockBu return "drw_matrices"; case GPU_UNIFORM_BLOCK_DRW_INFOS: return "drw_infos"; + case GPU_UNIFORM_BLOCK_DRW_CLIPPING: + return "drw_clipping"; default: return nullptr; } |