diff options
author | Campbell Barton <ideasman42@gmail.com> | 2019-01-21 15:51:34 +0300 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2019-01-21 15:55:53 +0300 |
commit | 9bc47ed0f6d0db9e43af30c741a7e5ac347cbecd (patch) | |
tree | ca8dbd6ce37e3529a3c5fe8c0bc944c535128ec3 /source | |
parent | 0c829e8240eebd7ce4ed9d61f8682c0d6bf534f4 (diff) |
Fix clipping shaders with some AMD/Intel drivers
Caused:
error: unsized array index must be constant
Use hard coded number of clipping planes, copying the 4th to 5 & 6
when only 4 are used.
Diffstat (limited to 'source')
25 files changed, 111 insertions, 163 deletions
diff --git a/source/blender/draw/CMakeLists.txt b/source/blender/draw/CMakeLists.txt index 8ba9058f210..a305d18a592 100644 --- a/source/blender/draw/CMakeLists.txt +++ b/source/blender/draw/CMakeLists.txt @@ -249,6 +249,7 @@ data_to_c_simple(modes/shaders/common_hair_refine_vert.glsl SRC) data_to_c_simple(modes/shaders/common_view_lib.glsl SRC) data_to_c_simple(modes/shaders/common_fxaa_lib.glsl SRC) data_to_c_simple(modes/shaders/common_fullscreen_vert.glsl SRC) +data_to_c_simple(modes/shaders/common_world_clip_lib.glsl SRC) data_to_c_simple(modes/shaders/animviz_mpath_lines_vert.glsl SRC) data_to_c_simple(modes/shaders/animviz_mpath_lines_geom.glsl SRC) data_to_c_simple(modes/shaders/animviz_mpath_points_vert.glsl SRC) diff --git a/source/blender/draw/engines/workbench/shaders/workbench_prepass_vert.glsl b/source/blender/draw/engines/workbench/shaders/workbench_prepass_vert.glsl index e821581298d..66372f82b89 100644 --- a/source/blender/draw/engines/workbench/shaders/workbench_prepass_vert.glsl +++ b/source/blender/draw/engines/workbench/shaders/workbench_prepass_vert.glsl @@ -6,11 +6,6 @@ uniform mat4 ViewProjectionMatrix; uniform mat4 ViewMatrixInverse; uniform mat3 NormalMatrix; -#ifdef USE_WORLD_CLIP_PLANES -uniform vec4 WorldClipPlanes[6]; -uniform int WorldClipPlanesLen; -#endif - #ifndef HAIR_SHADER in vec3 pos; in vec3 nor; @@ -76,12 +71,7 @@ void main() #endif #ifdef USE_WORLD_CLIP_PLANES - { - vec3 worldPosition = (ModelMatrix * vec4(pos, 1.0)).xyz; - for (int i = 0; i < WorldClipPlanesLen; i++) { - gl_ClipDistance[i] = dot(WorldClipPlanes[i].xyz, worldPosition) + WorldClipPlanes[i].w; - } - } + world_clip_planes_calc_clip_distance((ModelMatrix * vec4(pos, 1.0)).xyz); #endif } diff --git a/source/blender/draw/engines/workbench/workbench_data.c b/source/blender/draw/engines/workbench/workbench_data.c index 60bcae3eee3..38787210036 100644 --- a/source/blender/draw/engines/workbench/workbench_data.c +++ b/source/blender/draw/engines/workbench/workbench_data.c @@ -91,12 +91,11 @@ void workbench_private_data_init(WORKBENCH_PrivateData *wpd) { RegionView3D *rv3d = draw_ctx->rv3d; if (rv3d->rflag & RV3D_CLIPPING) { - wpd->world_clip_planes_len = (rv3d->viewlock & RV3D_BOXCLIP) ? 4 : 6; - memcpy(wpd->world_clip_planes, rv3d->clip, sizeof(float[4]) * wpd->world_clip_planes_len); - DRW_state_clip_planes_len_set(wpd->world_clip_planes_len); + wpd->world_clip_planes = rv3d->clip; + DRW_state_clip_planes_set_from_rv3d(rv3d); } else { - wpd->world_clip_planes_len = 0; + wpd->world_clip_planes = NULL; } } diff --git a/source/blender/draw/engines/workbench/workbench_deferred.c b/source/blender/draw/engines/workbench/workbench_deferred.c index 3f537f6c6d0..dce30a7056b 100644 --- a/source/blender/draw/engines/workbench/workbench_deferred.c +++ b/source/blender/draw/engines/workbench/workbench_deferred.c @@ -90,6 +90,7 @@ static struct { /* Shaders */ extern char datatoc_common_hair_lib_glsl[]; +extern char datatoc_common_world_clip_lib_glsl[]; extern char datatoc_workbench_prepass_vert_glsl[]; extern char datatoc_workbench_prepass_frag_glsl[]; @@ -159,12 +160,15 @@ static char *workbench_build_prepass_vert(bool is_hair) { char *str = NULL; if (!is_hair) { - return BLI_strdup(datatoc_workbench_prepass_vert_glsl); + return BLI_string_joinN( + datatoc_common_world_clip_lib_glsl, + datatoc_workbench_prepass_vert_glsl); } DynStr *ds = BLI_dynstr_new(); BLI_dynstr_append(ds, datatoc_common_hair_lib_glsl); + BLI_dynstr_append(ds, datatoc_common_world_clip_lib_glsl); BLI_dynstr_append(ds, datatoc_workbench_prepass_vert_glsl); str = BLI_dynstr_get_cstring(ds); diff --git a/source/blender/draw/engines/workbench/workbench_forward.c b/source/blender/draw/engines/workbench/workbench_forward.c index 94cbb20ef5f..485348f65f3 100644 --- a/source/blender/draw/engines/workbench/workbench_forward.c +++ b/source/blender/draw/engines/workbench/workbench_forward.c @@ -29,6 +29,7 @@ #include "BLI_alloca.h" #include "BLI_dynstr.h" +#include "BLI_string_utils.h" #include "BLI_utildefines.h" #include "BKE_node.h" @@ -66,6 +67,7 @@ static struct { } e_data = {{NULL}}; /* Shaders */ +extern char datatoc_common_world_clip_lib_glsl[]; extern char datatoc_common_hair_lib_glsl[]; extern char datatoc_workbench_forward_composite_frag_glsl[]; @@ -85,12 +87,15 @@ static char *workbench_build_forward_vert(bool is_hair) { char *str = NULL; if (!is_hair) { - return BLI_strdup(datatoc_workbench_prepass_vert_glsl); + return BLI_string_joinN( + datatoc_common_world_clip_lib_glsl, + datatoc_workbench_prepass_vert_glsl); } DynStr *ds = BLI_dynstr_new(); BLI_dynstr_append(ds, datatoc_common_hair_lib_glsl); + BLI_dynstr_append(ds, datatoc_common_world_clip_lib_glsl); BLI_dynstr_append(ds, datatoc_workbench_prepass_vert_glsl); str = BLI_dynstr_get_cstring(ds); diff --git a/source/blender/draw/engines/workbench/workbench_materials.c b/source/blender/draw/engines/workbench/workbench_materials.c index ce71189f344..d19f9293af9 100644 --- a/source/blender/draw/engines/workbench/workbench_materials.c +++ b/source/blender/draw/engines/workbench/workbench_materials.c @@ -110,7 +110,7 @@ char *workbench_material_build_defines(WORKBENCH_PrivateData *wpd, bool use_text if (is_hair) { BLI_dynstr_appendf(ds, "#define HAIR_SHADER\n"); } - if (wpd->world_clip_planes_len) { + if (wpd->world_clip_planes != NULL) { BLI_dynstr_appendf(ds, "#define USE_WORLD_CLIP_PLANES\n"); } @@ -171,7 +171,7 @@ int workbench_material_get_prepass_shader_index( SET_FLAG_FROM_TEST(index, NORMAL_VIEWPORT_PASS_ENABLED(wpd), 1 << 3); SET_FLAG_FROM_TEST(index, MATCAP_ENABLED(wpd), 1 << 4); SET_FLAG_FROM_TEST(index, use_textures, 1 << 5); - SET_FLAG_FROM_TEST(index, wpd->world_clip_planes_len != 0, 1 << 6); + SET_FLAG_FROM_TEST(index, wpd->world_clip_planes != NULL, 1 << 6); return index; } @@ -241,9 +241,8 @@ void workbench_material_shgroup_uniform( DRW_shgroup_uniform_float(grp, "materialRoughness", &material->roughness, 1); } - if (wpd->world_clip_planes_len) { - DRW_shgroup_uniform_vec4(grp, "WorldClipPlanes", wpd->world_clip_planes[0], wpd->world_clip_planes_len); - DRW_shgroup_uniform_int(grp, "WorldClipPlanesLen", &wpd->world_clip_planes_len, 1); + if (wpd->world_clip_planes != NULL) { + DRW_shgroup_uniform_vec4(grp, "WorldClipPlanes", wpd->world_clip_planes[0], 6); DRW_shgroup_state_enable(grp, DRW_STATE_CLIP_PLANES); } } diff --git a/source/blender/draw/engines/workbench/workbench_private.h b/source/blender/draw/engines/workbench/workbench_private.h index a4cfd297516..82d84fef67a 100644 --- a/source/blender/draw/engines/workbench/workbench_private.h +++ b/source/blender/draw/engines/workbench/workbench_private.h @@ -200,8 +200,7 @@ typedef struct WORKBENCH_PrivateData { bool shadow_changed; bool is_playback; - float world_clip_planes[6][4]; - int world_clip_planes_len; + float (*world_clip_planes)[4]; /* Volumes */ bool volumes_do; diff --git a/source/blender/draw/intern/DRW_render.h b/source/blender/draw/intern/DRW_render.h index 96525a47c77..cb5b8074f4b 100644 --- a/source/blender/draw/intern/DRW_render.h +++ b/source/blender/draw/intern/DRW_render.h @@ -533,6 +533,7 @@ void DRW_state_invert_facing(void); void DRW_state_clip_planes_len_set(uint plane_len); void DRW_state_clip_planes_reset(void); +void DRW_state_clip_planes_set_from_rv3d(struct RegionView3D *rv3d); /* Culling, return true if object is inside view frustum. */ bool DRW_culling_sphere_test(BoundSphere *bsphere); diff --git a/source/blender/draw/intern/draw_common.c b/source/blender/draw/intern/draw_common.c index 250b0a1f1ab..bb247832d44 100644 --- a/source/blender/draw/intern/draw_common.c +++ b/source/blender/draw/intern/draw_common.c @@ -302,7 +302,6 @@ void DRW_shgroup_world_clip_planes_from_rv3d(DRWShadingGroup *shgrp, const Regio { int world_clip_planes_len = (rv3d->viewlock & RV3D_BOXCLIP) ? 4 : 6; DRW_shgroup_uniform_vec4(shgrp, "WorldClipPlanes", rv3d->clip[0], world_clip_planes_len); - DRW_shgroup_uniform_int_copy(shgrp, "WorldClipPlanesLen", world_clip_planes_len); DRW_shgroup_state_enable(shgrp, DRW_STATE_CLIP_PLANES); } diff --git a/source/blender/draw/intern/draw_manager_exec.c b/source/blender/draw/intern/draw_manager_exec.c index e5654ab2a64..21647d54eea 100644 --- a/source/blender/draw/intern/draw_manager_exec.c +++ b/source/blender/draw/intern/draw_manager_exec.c @@ -447,6 +447,19 @@ void DRW_state_clip_planes_reset(void) DST.clip_planes_len = 0; } +void DRW_state_clip_planes_set_from_rv3d(RegionView3D *rv3d) +{ + int max_len = 6; + int real_len = (rv3d->viewlock & RV3D_BOXCLIP) ? 4 : max_len; + while (real_len < max_len) { + /* Fill in dummy values that wont change results (6 is hard coded in shaders). */ + copy_v4_v4(rv3d->clip[real_len], rv3d->clip[3]); + real_len++; + } + + DRW_state_clip_planes_len_set(max_len); +} + /** \} */ /* -------------------------------------------------------------------- */ diff --git a/source/blender/draw/modes/edit_mesh_mode.c b/source/blender/draw/modes/edit_mesh_mode.c index 1a3d7fb4cb4..59aa4ea5ff0 100644 --- a/source/blender/draw/modes/edit_mesh_mode.c +++ b/source/blender/draw/modes/edit_mesh_mode.c @@ -42,6 +42,7 @@ #include "BKE_object.h" #include "BLI_dynstr.h" +#include "BLI_string_utils.h" extern struct GPUUniformBuffer *globals_ubo; /* draw_common.c */ @@ -49,6 +50,8 @@ extern struct GlobalsUboStorage ts; /* draw_common.c */ extern struct GPUTexture *globals_weight_ramp; /* draw_common.c */ +extern char datatoc_common_world_clip_lib_glsl[]; + extern char datatoc_paint_weight_vert_glsl[]; extern char datatoc_paint_weight_frag_glsl[]; @@ -229,6 +232,7 @@ static char *EDIT_MESH_sh_lib(void) BLI_dynstr_append(ds, datatoc_common_globals_lib_glsl); BLI_dynstr_append(ds, datatoc_edit_mesh_overlay_common_lib_glsl); + BLI_dynstr_append(ds, datatoc_common_world_clip_lib_glsl); str = BLI_dynstr_get_cstring(ds); BLI_dynstr_free(ds); @@ -295,15 +299,19 @@ static void EDIT_MESH_engine_init(void *vedata) }); if (is_clip) { - DRW_state_clip_planes_len_set((draw_ctx->rv3d->viewlock & RV3D_BOXCLIP) ? 4 : 6); + DRW_state_clip_planes_set_from_rv3d(draw_ctx->rv3d); } if (!sh_data->weight_face) { + char *lib = BLI_string_joinN( + datatoc_common_world_clip_lib_glsl, + datatoc_common_globals_lib_glsl); sh_data->weight_face = DRW_shader_create_with_lib( datatoc_paint_weight_vert_glsl, NULL, datatoc_paint_weight_frag_glsl, - datatoc_common_globals_lib_glsl, + lib, is_clip ? DEF_WORLD_CLIP_STR : NULL); + MEM_freeN(lib); } if (!sh_data->overlay_vert) { @@ -322,50 +330,61 @@ static void EDIT_MESH_engine_init(void *vedata) MEM_freeN(lib); } if (!sh_data->overlay_facedot) { + char *lib = BLI_string_joinN( + datatoc_common_world_clip_lib_glsl, + datatoc_common_globals_lib_glsl); const char *defs = DEF_WORLD_CLIP_STR "#define VERTEX_FACING\n" ; sh_data->overlay_facedot = DRW_shader_create_with_lib( datatoc_edit_mesh_overlay_facedot_vert_glsl, NULL, datatoc_edit_mesh_overlay_facedot_frag_glsl, - datatoc_common_globals_lib_glsl, + lib, defs + (is_clip ? 0 : strlen(DEF_WORLD_CLIP_STR))); + MEM_freeN(lib); } if (!sh_data->overlay_mix) { sh_data->overlay_mix = DRW_shader_create_fullscreen(datatoc_edit_mesh_overlay_mix_frag_glsl, NULL); } if (!sh_data->overlay_facefill) { + char *lib = BLI_string_joinN( + datatoc_common_world_clip_lib_glsl, + datatoc_common_globals_lib_glsl); sh_data->overlay_facefill = DRW_shader_create_with_lib( datatoc_edit_mesh_overlay_facefill_vert_glsl, NULL, datatoc_edit_mesh_overlay_facefill_frag_glsl, - datatoc_common_globals_lib_glsl, + lib, is_clip ? DEF_WORLD_CLIP_STR : NULL); + MEM_freeN(lib); } if (!sh_data->normals_face) { const char *defs = DEF_WORLD_CLIP_STR "#define FACE_NORMALS\n"; - sh_data->normals_face = DRW_shader_create( + sh_data->normals_face = DRW_shader_create_with_lib( datatoc_edit_normals_vert_glsl, datatoc_edit_normals_geom_glsl, datatoc_gpu_shader_uniform_color_frag_glsl, + datatoc_common_world_clip_lib_glsl, defs + (is_clip ? 0 : strlen(DEF_WORLD_CLIP_STR))); } if (!sh_data->normals_loop) { const char *defs = DEF_WORLD_CLIP_STR "#define LOOP_NORMALS\n"; - sh_data->normals_loop = DRW_shader_create( + sh_data->normals_loop = DRW_shader_create_with_lib( datatoc_edit_normals_vert_glsl, datatoc_edit_normals_geom_glsl, datatoc_gpu_shader_uniform_color_frag_glsl, + datatoc_common_world_clip_lib_glsl, defs + (is_clip ? 0 : strlen(DEF_WORLD_CLIP_STR))); } if (!sh_data->normals) { - sh_data->normals = DRW_shader_create( + sh_data->normals = DRW_shader_create_with_lib( datatoc_edit_normals_vert_glsl, datatoc_edit_normals_geom_glsl, datatoc_gpu_shader_uniform_color_frag_glsl, + datatoc_common_world_clip_lib_glsl, is_clip ? DEF_WORLD_CLIP_STR : NULL); } if (!sh_data->depth) { diff --git a/source/blender/draw/modes/overlay_mode.c b/source/blender/draw/modes/overlay_mode.c index 2fc4cf3a765..16e008d349d 100644 --- a/source/blender/draw/modes/overlay_mode.c +++ b/source/blender/draw/modes/overlay_mode.c @@ -82,6 +82,8 @@ static struct { OVERLAY_ShaderData sh_data[2]; } e_data = {NULL}; +extern char datatoc_common_world_clip_lib_glsl[]; + /* Shaders */ extern char datatoc_overlay_face_orientation_frag_glsl[]; extern char datatoc_overlay_face_orientation_vert_glsl[]; @@ -112,7 +114,7 @@ static void overlay_engine_init(void *vedata) const bool is_clip = (draw_ctx->rv3d->rflag & RV3D_CLIPPING) != 0; if (is_clip) { - DRW_state_clip_planes_len_set((draw_ctx->rv3d->viewlock & RV3D_BOXCLIP) ? 4 : 6); + DRW_state_clip_planes_set_from_rv3d(draw_ctx->rv3d); } if (!stl->g_data) { @@ -123,30 +125,34 @@ static void overlay_engine_init(void *vedata) if (!sh_data->face_orientation_sh) { /* Face orientation */ - sh_data->face_orientation_sh = DRW_shader_create( + sh_data->face_orientation_sh = DRW_shader_create_with_lib( datatoc_overlay_face_orientation_vert_glsl, NULL, datatoc_overlay_face_orientation_frag_glsl, + datatoc_common_world_clip_lib_glsl, is_clip ? NULL : DEF_WORLD_CLIP_STR); } if (!sh_data->face_wireframe_sh) { - sh_data->select_wireframe_sh = DRW_shader_create( + sh_data->select_wireframe_sh = DRW_shader_create_with_lib( datatoc_overlay_face_wireframe_vert_glsl, datatoc_overlay_face_wireframe_geom_glsl, datatoc_gpu_shader_depth_only_frag_glsl, + datatoc_common_world_clip_lib_glsl, DEF_WORLD_CLIP_STR "#define SELECT_EDGES\n" + (is_clip ? 0 : strlen(DEF_WORLD_CLIP_STR))); - sh_data->face_wireframe_sh = DRW_shader_create( + sh_data->face_wireframe_sh = DRW_shader_create_with_lib( datatoc_overlay_face_wireframe_vert_glsl, NULL, datatoc_overlay_face_wireframe_frag_glsl, + datatoc_common_world_clip_lib_glsl, is_clip ? DEF_WORLD_CLIP_STR : NULL); - sh_data->face_wireframe_sculpt_sh = DRW_shader_create( + sh_data->face_wireframe_sculpt_sh = DRW_shader_create_with_lib( datatoc_overlay_face_wireframe_vert_glsl, datatoc_overlay_face_wireframe_geom_glsl, datatoc_overlay_face_wireframe_frag_glsl, + datatoc_common_world_clip_lib_glsl, DEF_WORLD_CLIP_STR "#define USE_SCULPT\n" + (is_clip ? 0 : strlen(DEF_WORLD_CLIP_STR))); } diff --git a/source/blender/draw/modes/shaders/common_world_clip_lib.glsl b/source/blender/draw/modes/shaders/common_world_clip_lib.glsl new file mode 100644 index 00000000000..b889780751e --- /dev/null +++ b/source/blender/draw/modes/shaders/common_world_clip_lib.glsl @@ -0,0 +1,25 @@ +#ifdef USE_WORLD_CLIP_PLANES +#ifdef GPU_VERTEX_SHADER +uniform vec4 WorldClipPlanes[6]; +void world_clip_planes_calc_clip_distance(vec3 wpos) +{ + gl_ClipDistance[0] = dot(WorldClipPlanes[0].xyz, wpos) + WorldClipPlanes[0].w; + gl_ClipDistance[1] = dot(WorldClipPlanes[1].xyz, wpos) + WorldClipPlanes[1].w; + gl_ClipDistance[2] = dot(WorldClipPlanes[2].xyz, wpos) + WorldClipPlanes[2].w; + gl_ClipDistance[3] = dot(WorldClipPlanes[3].xyz, wpos) + WorldClipPlanes[3].w; + gl_ClipDistance[4] = dot(WorldClipPlanes[4].xyz, wpos) + WorldClipPlanes[4].w; + gl_ClipDistance[5] = dot(WorldClipPlanes[5].xyz, wpos) + WorldClipPlanes[5].w; +} +#endif + +#define world_clip_planes_set_clip_distance(c) \ +{ \ + gl_ClipDistance[0] = (c)[0]; \ + gl_ClipDistance[1] = (c)[1]; \ + gl_ClipDistance[2] = (c)[2]; \ + gl_ClipDistance[3] = (c)[3]; \ + gl_ClipDistance[4] = (c)[4]; \ + gl_ClipDistance[5] = (c)[5]; \ +} + +#endif diff --git a/source/blender/draw/modes/shaders/edit_mesh_overlay_facedot_vert.glsl b/source/blender/draw/modes/shaders/edit_mesh_overlay_facedot_vert.glsl index 2a54ca70684..a66560cd8d9 100644 --- a/source/blender/draw/modes/shaders/edit_mesh_overlay_facedot_vert.glsl +++ b/source/blender/draw/modes/shaders/edit_mesh_overlay_facedot_vert.glsl @@ -2,11 +2,6 @@ uniform mat4 ModelViewProjectionMatrix; uniform mat4 ModelMatrix; -#ifdef USE_WORLD_CLIP_PLANES -uniform vec4 WorldClipPlanes[6]; -uniform int WorldClipPlanesLen; -#endif - in vec3 pos; in vec4 norAndFlag; @@ -36,11 +31,6 @@ void main() #endif #ifdef USE_WORLD_CLIP_PLANES - { - vec3 worldPosition = (ModelMatrix * vec4(pos, 1.0)).xyz; - for (int i = 0; i < WorldClipPlanesLen; i++) { - gl_ClipDistance[i] = dot(WorldClipPlanes[i].xyz, worldPosition) + WorldClipPlanes[i].w; - } - } + world_clip_planes_calc_clip_distance((ModelMatrix * vec4(pos, 1.0)).xyz); #endif } diff --git a/source/blender/draw/modes/shaders/edit_mesh_overlay_facefill_vert.glsl b/source/blender/draw/modes/shaders/edit_mesh_overlay_facefill_vert.glsl index fa808b4fdb9..95630fc2e0f 100644 --- a/source/blender/draw/modes/shaders/edit_mesh_overlay_facefill_vert.glsl +++ b/source/blender/draw/modes/shaders/edit_mesh_overlay_facefill_vert.glsl @@ -3,11 +3,6 @@ uniform mat4 ModelViewProjectionMatrix; uniform mat4 ModelMatrix; uniform ivec4 dataMask = ivec4(0xFF); -#ifdef USE_WORLD_CLIP_PLANES -uniform vec4 WorldClipPlanes[6]; -uniform int WorldClipPlanesLen; -#endif - in vec3 pos; in ivec4 data; @@ -33,11 +28,6 @@ void main() faceColor = colorFace; #ifdef USE_WORLD_CLIP_PLANES - { - vec3 worldPosition = (ModelMatrix * vec4(pos, 1.0)).xyz; - for (int i = 0; i < WorldClipPlanesLen; i++) { - gl_ClipDistance[i] = dot(WorldClipPlanes[i].xyz, worldPosition) + WorldClipPlanes[i].w; - } - } + world_clip_planes_calc_clip_distance((ModelMatrix * vec4(pos, 1.0)).xyz); #endif } diff --git a/source/blender/draw/modes/shaders/edit_mesh_overlay_geom_edge.glsl b/source/blender/draw/modes/shaders/edit_mesh_overlay_geom_edge.glsl index e8987b59c45..76c53b3cf86 100644 --- a/source/blender/draw/modes/shaders/edit_mesh_overlay_geom_edge.glsl +++ b/source/blender/draw/modes/shaders/edit_mesh_overlay_geom_edge.glsl @@ -9,10 +9,6 @@ uniform mat4 ProjectionMatrix; uniform mat4 ViewProjectionMatrixInverse; uniform vec2 viewportSize; -#ifdef USE_WORLD_CLIP_PLANES -uniform int WorldClipPlanesLen; -#endif - in vec4 pPos[]; in ivec4 vData[]; #ifdef VERTEX_FACING @@ -63,9 +59,7 @@ void doVertex(int v, vec4 pos) gl_Position = pos; #ifdef USE_WORLD_CLIP_PLANES - for (int i = 0; i < WorldClipPlanesLen; i++) { - gl_ClipDistance[i] = gl_in[v].gl_ClipDistance[i]; - } + world_clip_planes_set_clip_distance(gl_in[v].gl_ClipDistance); #endif EmitVertex(); diff --git a/source/blender/draw/modes/shaders/edit_mesh_overlay_geom_tri.glsl b/source/blender/draw/modes/shaders/edit_mesh_overlay_geom_tri.glsl index 3fcc3a7240f..1c88f1ff959 100644 --- a/source/blender/draw/modes/shaders/edit_mesh_overlay_geom_tri.glsl +++ b/source/blender/draw/modes/shaders/edit_mesh_overlay_geom_tri.glsl @@ -15,10 +15,6 @@ uniform mat4 ProjectionMatrix; uniform vec2 viewportSize; uniform bool isXray = false; -#ifdef USE_WORLD_CLIP_PLANES -uniform int WorldClipPlanesLen; -#endif - in vec4 pPos[]; #ifdef USE_WORLD_CLIP_PLANES /* Worldspace position. */ @@ -77,9 +73,7 @@ void doVertex(int v) gl_Position = pPos[v]; #ifdef USE_WORLD_CLIP_PLANES - for (int i = 0; i < WorldClipPlanesLen; i++) { - gl_ClipDistance[i] = gl_in[v].gl_ClipDistance[i]; - } + world_clip_planes_set_clip_distance(gl_in[v].gl_ClipDistance); #endif EmitVertex(); @@ -98,9 +92,7 @@ void doVertexOfs(int v, vec2 fixvec) gl_Position = pPos[v] + vec4(fixvec * pPos[v].w, z_ofs, 0.0); #ifdef USE_WORLD_CLIP_PLANES - for (int i = 0; i < WorldClipPlanesLen; i++) { - gl_ClipDistance[i] = gl_in[v].gl_ClipDistance[i]; - } + world_clip_planes_set_clip_distance(gl_in[v].gl_ClipDistance); #endif EmitVertex(); diff --git a/source/blender/draw/modes/shaders/edit_mesh_overlay_points_vert.glsl b/source/blender/draw/modes/shaders/edit_mesh_overlay_points_vert.glsl index 53a56097234..687e5b0a0fc 100644 --- a/source/blender/draw/modes/shaders/edit_mesh_overlay_points_vert.glsl +++ b/source/blender/draw/modes/shaders/edit_mesh_overlay_points_vert.glsl @@ -6,11 +6,6 @@ uniform mat4 ModelViewProjectionMatrix; uniform mat4 ModelMatrix; uniform float ofs = 3e-5; -#ifdef USE_WORLD_CLIP_PLANES -uniform vec4 WorldClipPlanes[6]; -uniform int WorldClipPlanesLen; -#endif - in vec3 pos; in ivec4 data; #ifdef VERTEX_FACING @@ -56,11 +51,6 @@ void main() } #ifdef USE_WORLD_CLIP_PLANES - { - vec3 worldPosition = (ModelMatrix * vec4(pos, 1.0)).xyz; - for (int i = 0; i < WorldClipPlanesLen; i++) { - gl_ClipDistance[i] = dot(WorldClipPlanes[i].xyz, worldPosition) + WorldClipPlanes[i].w; - } - } + world_clip_planes_calc_clip_distance((ModelMatrix * vec4(pos, 1.0)).xyz); #endif } diff --git a/source/blender/draw/modes/shaders/edit_mesh_overlay_vert.glsl b/source/blender/draw/modes/shaders/edit_mesh_overlay_vert.glsl index d4d7c455b1b..13431168fb0 100644 --- a/source/blender/draw/modes/shaders/edit_mesh_overlay_vert.glsl +++ b/source/blender/draw/modes/shaders/edit_mesh_overlay_vert.glsl @@ -9,12 +9,6 @@ uniform mat4 ModelViewProjectionMatrix; uniform mat4 ModelMatrix; uniform ivec4 dataMask = ivec4(0xFF); -#ifdef USE_WORLD_CLIP_PLANES -uniform vec4 WorldClipPlanes[6]; -uniform int WorldClipPlanesLen; -#endif - - in vec3 pos; #ifdef VERTEX_FACING in vec3 vnor; @@ -43,12 +37,7 @@ void main() # endif # ifdef USE_WORLD_CLIP_PLANES - { - vec3 worldPosition = (ModelMatrix * vec4(pos, 1.0)).xyz; - for (int i = 0; i < WorldClipPlanesLen; i++) { - gl_ClipDistance[i] = dot(WorldClipPlanes[i].xyz, worldPosition) + WorldClipPlanes[i].w; - } - } + world_clip_planes_calc_clip_distance((ModelMatrix * vec4(pos, 1.0)).xyz); # endif } @@ -115,12 +104,7 @@ void main() # endif # ifdef USE_WORLD_CLIP_PLANES - { - vec3 worldPosition = (ModelMatrix * vec4(pos, 1.0)).xyz; - for (int i = 0; i < WorldClipPlanesLen; i++) { - gl_ClipDistance[i] = dot(WorldClipPlanes[i].xyz, worldPosition) + WorldClipPlanes[i].w; - } - } + world_clip_planes_calc_clip_distance((ModelMatrix * vec4(pos, 1.0)).xyz); # endif } diff --git a/source/blender/draw/modes/shaders/edit_normals_geom.glsl b/source/blender/draw/modes/shaders/edit_normals_geom.glsl index 50214c75e6a..91a57a79eb0 100644 --- a/source/blender/draw/modes/shaders/edit_normals_geom.glsl +++ b/source/blender/draw/modes/shaders/edit_normals_geom.glsl @@ -2,10 +2,6 @@ layout(points) in; layout(line_strip, max_vertices=2) out; -#ifdef USE_WORLD_CLIP_PLANES -uniform int WorldClipPlanesLen; -#endif - flat in vec4 v1[1]; flat in vec4 v2[1]; @@ -14,9 +10,7 @@ void main() for (int v = 0; v < 2; v++) { gl_Position = (v == 0) ? v1[0] : v2[0]; #ifdef USE_WORLD_CLIP_PLANES - for (int i = 0; i < WorldClipPlanesLen; i++) { - gl_ClipDistance[i] = gl_in[0].gl_ClipDistance[i]; - } + world_clip_planes_set_clip_distance(gl_in[0].gl_ClipDistance); #endif EmitVertex(); } diff --git a/source/blender/draw/modes/shaders/edit_normals_vert.glsl b/source/blender/draw/modes/shaders/edit_normals_vert.glsl index 99741de63bb..8d73a2f5ad2 100644 --- a/source/blender/draw/modes/shaders/edit_normals_vert.glsl +++ b/source/blender/draw/modes/shaders/edit_normals_vert.glsl @@ -5,11 +5,6 @@ uniform mat4 ProjectionMatrix; uniform mat4 ModelMatrix; uniform float normalSize; -#ifdef USE_WORLD_CLIP_PLANES -uniform vec4 WorldClipPlanes[6]; -uniform int WorldClipPlanesLen; -#endif - in vec3 pos; #ifdef LOOP_NORMALS @@ -34,11 +29,6 @@ void main() vec3 n = normalize(NormalMatrix * nor); /* viewspace */ v2 = v1 + ProjectionMatrix * vec4(n * normalSize, 0.0); #ifdef USE_WORLD_CLIP_PLANES - { - vec3 worldPosition = (ModelMatrix * vec4(pos, 1.0)).xyz; - for (int i = 0; i < WorldClipPlanesLen; i++) { - gl_ClipDistance[i] = dot(WorldClipPlanes[i].xyz, worldPosition) + WorldClipPlanes[i].w; - } - } + world_clip_planes_calc_clip_distance((ModelMatrix * vec4(pos, 1.0)).xyz); #endif } diff --git a/source/blender/draw/modes/shaders/overlay_face_orientation_vert.glsl b/source/blender/draw/modes/shaders/overlay_face_orientation_vert.glsl index 2d025bc65ee..f9f2679fe81 100644 --- a/source/blender/draw/modes/shaders/overlay_face_orientation_vert.glsl +++ b/source/blender/draw/modes/shaders/overlay_face_orientation_vert.glsl @@ -1,11 +1,6 @@ uniform mat4 ModelViewProjectionMatrix; uniform mat4 ModelMatrix; -#ifdef USE_WORLD_CLIP_PLANES -uniform vec4 WorldClipPlanes[6]; -uniform int WorldClipPlanesLen; -#endif - in vec3 pos; void main() @@ -13,11 +8,6 @@ void main() gl_Position = ModelViewProjectionMatrix * vec4(pos, 1.0); #ifdef USE_WORLD_CLIP_PLANES - { - vec3 worldPosition = (ModelMatrix * vec4(pos, 1.0)).xyz; - for (int i = 0; i < WorldClipPlanesLen; i++) { - gl_ClipDistance[i] = dot(WorldClipPlanes[i].xyz, worldPosition) + WorldClipPlanes[i].w; - } - } + world_clip_planes_calc_clip_distance((ModelMatrix * vec4(pos, 1.0)).xyz); #endif } diff --git a/source/blender/draw/modes/shaders/overlay_face_wireframe_geom.glsl b/source/blender/draw/modes/shaders/overlay_face_wireframe_geom.glsl index 2f3acc2a050..d4d53b7d24d 100644 --- a/source/blender/draw/modes/shaders/overlay_face_wireframe_geom.glsl +++ b/source/blender/draw/modes/shaders/overlay_face_wireframe_geom.glsl @@ -8,10 +8,6 @@ layout(line_strip, max_vertices = 6) out; layout(triangle_strip, max_vertices = 3) out; #endif -#ifdef USE_WORLD_CLIP_PLANES -uniform int WorldClipPlanesLen; -#endif - in float facing_g[]; in float edgeSharpness_g[]; @@ -25,9 +21,7 @@ void vert_from_gl_in(int v) { gl_Position = gl_in[v].gl_Position; #ifdef USE_WORLD_CLIP_PLANES - for (int i = 0; i < WorldClipPlanesLen; i++) { - gl_ClipDistance[i] = gl_in[v].gl_ClipDistance[i]; - } + world_clip_planes_set_clip_distance(gl_in[v].gl_ClipDistance); #endif } diff --git a/source/blender/draw/modes/shaders/overlay_face_wireframe_vert.glsl b/source/blender/draw/modes/shaders/overlay_face_wireframe_vert.glsl index 3c3869db7b4..cb07c535200 100644 --- a/source/blender/draw/modes/shaders/overlay_face_wireframe_vert.glsl +++ b/source/blender/draw/modes/shaders/overlay_face_wireframe_vert.glsl @@ -5,11 +5,6 @@ uniform mat3 NormalMatrix; uniform vec2 wireStepParam; -#ifdef USE_WORLD_CLIP_PLANES -uniform vec4 WorldClipPlanes[6]; -uniform int WorldClipPlanesLen; -#endif - vec3 get_edge_sharpness(vec3 wd) { bvec3 do_edge = greaterThan(wd, vec3(0.0)); @@ -84,12 +79,7 @@ void main() facing = normalize(NormalMatrix * nor).z; #ifdef USE_WORLD_CLIP_PLANES - { - vec3 worldPosition = (ModelMatrix * vec4(pos, 1.0)).xyz; - for (int i = 0; i < WorldClipPlanesLen; i++) { - gl_ClipDistance[i] = dot(WorldClipPlanes[i].xyz, worldPosition) + WorldClipPlanes[i].w; - } - } + world_clip_planes_calc_clip_distance((ModelMatrix * vec4(pos, 1.0)).xyz); #endif } diff --git a/source/blender/draw/modes/shaders/paint_weight_vert.glsl b/source/blender/draw/modes/shaders/paint_weight_vert.glsl index ab0fb775e54..d111f3dc0a8 100644 --- a/source/blender/draw/modes/shaders/paint_weight_vert.glsl +++ b/source/blender/draw/modes/shaders/paint_weight_vert.glsl @@ -2,11 +2,6 @@ uniform mat4 ModelViewProjectionMatrix; uniform mat4 ModelMatrix; -#ifdef USE_WORLD_CLIP_PLANES -uniform vec4 WorldClipPlanes[6]; -uniform int WorldClipPlanesLen; -#endif - in float weight; in vec3 pos; @@ -20,11 +15,6 @@ void main() weight_interp = max(vec2(weight, -weight), 0.0); #ifdef USE_WORLD_CLIP_PLANES - { - vec3 worldPosition = (ModelMatrix * vec4(pos, 1.0)).xyz; - for (int i = 0; i < WorldClipPlanesLen; i++) { - gl_ClipDistance[i] = dot(WorldClipPlanes[i].xyz, worldPosition) + WorldClipPlanes[i].w; - } - } + world_clip_planes_calc_clip_distance((ModelMatrix * vec4(pos, 1.0)).xyz); #endif } |