Fix clipping shaders with some AMD/Intel drivers
authorCampbell Barton <ideasman42@gmail.com>
Mon, 21 Jan 2019 12:51:34 +0000 (23:51 +1100)
committerCampbell Barton <ideasman42@gmail.com>
Mon, 21 Jan 2019 12:55:53 +0000 (23:55 +1100)
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.

25 files changed:
source/blender/draw/CMakeLists.txt
source/blender/draw/engines/workbench/shaders/workbench_prepass_vert.glsl
source/blender/draw/engines/workbench/workbench_data.c
source/blender/draw/engines/workbench/workbench_deferred.c
source/blender/draw/engines/workbench/workbench_forward.c
source/blender/draw/engines/workbench/workbench_materials.c
source/blender/draw/engines/workbench/workbench_private.h
source/blender/draw/intern/DRW_render.h
source/blender/draw/intern/draw_common.c
source/blender/draw/intern/draw_manager_exec.c
source/blender/draw/modes/edit_mesh_mode.c
source/blender/draw/modes/overlay_mode.c
source/blender/draw/modes/shaders/common_world_clip_lib.glsl [new file with mode: 0644]
source/blender/draw/modes/shaders/edit_mesh_overlay_facedot_vert.glsl
source/blender/draw/modes/shaders/edit_mesh_overlay_facefill_vert.glsl
source/blender/draw/modes/shaders/edit_mesh_overlay_geom_edge.glsl
source/blender/draw/modes/shaders/edit_mesh_overlay_geom_tri.glsl
source/blender/draw/modes/shaders/edit_mesh_overlay_points_vert.glsl
source/blender/draw/modes/shaders/edit_mesh_overlay_vert.glsl
source/blender/draw/modes/shaders/edit_normals_geom.glsl
source/blender/draw/modes/shaders/edit_normals_vert.glsl
source/blender/draw/modes/shaders/overlay_face_orientation_vert.glsl
source/blender/draw/modes/shaders/overlay_face_wireframe_geom.glsl
source/blender/draw/modes/shaders/overlay_face_wireframe_vert.glsl
source/blender/draw/modes/shaders/paint_weight_vert.glsl

index 8ba9058f210af6663b69a66f014f26c56addaac0..a305d18a5920c001057235a54a16e1da2242a58b 100644 (file)
@@ -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_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)
 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)
index e821581298df06c4a8c08cf0c9b8b469bd10f989..66372f82b8910f3ca7f1735e25d370aaa58feeeb 100644 (file)
@@ -6,11 +6,6 @@ uniform mat4 ViewProjectionMatrix;
 uniform mat4 ViewMatrixInverse;
 uniform mat3 NormalMatrix;
 
 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;
 #ifndef HAIR_SHADER
 in vec3 pos;
 in vec3 nor;
@@ -76,12 +71,7 @@ void main()
 #endif
 
 #ifdef USE_WORLD_CLIP_PLANES
 #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
 
 }
 #endif
 
 }
index 60bcae3eee3967d0830d8a3320bc5f29e677d46f..3878721003646ec6b0f97924e0044957895a729c 100644 (file)
@@ -91,12 +91,11 @@ void workbench_private_data_init(WORKBENCH_PrivateData *wpd)
        {
                RegionView3D *rv3d = draw_ctx->rv3d;
                if (rv3d->rflag & RV3D_CLIPPING) {
        {
                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 {
                }
                else {
-                       wpd->world_clip_planes_len = 0;
+                       wpd->world_clip_planes = NULL;
                }
        }
 
                }
        }
 
index 3f537f6c6d09fbeab49d6783fb04c71e0452f4fd..dce30a7056b2c33c86ba8cbf582342440cc025f4 100644 (file)
@@ -90,6 +90,7 @@ static struct {
 
 /* Shaders */
 extern char datatoc_common_hair_lib_glsl[];
 
 /* 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[];
 
 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) {
 {
        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);
        }
 
        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);
        BLI_dynstr_append(ds, datatoc_workbench_prepass_vert_glsl);
 
        str = BLI_dynstr_get_cstring(ds);
index 94cbb20ef5f6a86f1fefca85fe79fb0673659c4c..485348f65f3f78fac05587069f95848ff2a570f5 100644 (file)
@@ -29,6 +29,7 @@
 
 #include "BLI_alloca.h"
 #include "BLI_dynstr.h"
 
 #include "BLI_alloca.h"
 #include "BLI_dynstr.h"
+#include "BLI_string_utils.h"
 #include "BLI_utildefines.h"
 
 #include "BKE_node.h"
 #include "BLI_utildefines.h"
 
 #include "BKE_node.h"
@@ -66,6 +67,7 @@ static struct {
 } e_data = {{NULL}};
 
 /* Shaders */
 } 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[];
 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) {
 {
        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);
        }
 
        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);
        BLI_dynstr_append(ds, datatoc_workbench_prepass_vert_glsl);
 
        str = BLI_dynstr_get_cstring(ds);
index ce71189f344e6813b646b1e744b4896b94822bdc..d19f9293af965b6683172baaf2ab5e99469131da 100644 (file)
@@ -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 (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");
        }
 
                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, 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;
 }
 
        return index;
 }
 
@@ -241,9 +241,8 @@ void workbench_material_shgroup_uniform(
                DRW_shgroup_uniform_float(grp, "materialRoughness", &material->roughness, 1);
        }
 
                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);
        }
 }
                DRW_shgroup_state_enable(grp, DRW_STATE_CLIP_PLANES);
        }
 }
index a4cfd297516bbfd0e37ffbdcbf01f6d127369c0e..82d84fef67a25f013fff51ba6c25636f1addfe4e 100644 (file)
@@ -200,8 +200,7 @@ typedef struct WORKBENCH_PrivateData {
        bool shadow_changed;
        bool is_playback;
 
        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;
 
        /* Volumes */
        bool volumes_do;
index 96525a47c77b307416cc3718e1c4e555f3536bb7..cb5b8074f4b0f4c0ab935829b1ac09e57bc6adbb 100644 (file)
@@ -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_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);
 
 /* Culling, return true if object is inside view frustum. */
 bool DRW_culling_sphere_test(BoundSphere *bsphere);
index 250b0a1f1abae26502b27443c5797fa151247475..bb247832d44dd10da8241ccb06e3773cee18f5f8 100644 (file)
@@ -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);
 {
        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);
 }
 
        DRW_shgroup_state_enable(shgrp, DRW_STATE_CLIP_PLANES);
 }
 
index e5654ab2a64e1f255f2d9f4e567cf4300260a8c6..21647d54eea8f99ef748070c6a78baa05f3a91d2 100644 (file)
@@ -447,6 +447,19 @@ void DRW_state_clip_planes_reset(void)
        DST.clip_planes_len = 0;
 }
 
        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);
+}
+
 /** \} */
 
 /* -------------------------------------------------------------------- */
 /** \} */
 
 /* -------------------------------------------------------------------- */
index 1a3d7fb4cb4ef3b2b8017970ad789e01e24a52bd..59aa4ea5ff00fc1f8c9035a14c71679ac77f744c 100644 (file)
@@ -42,6 +42,7 @@
 #include "BKE_object.h"
 
 #include "BLI_dynstr.h"
 #include "BKE_object.h"
 
 #include "BLI_dynstr.h"
+#include "BLI_string_utils.h"
 
 
 extern struct GPUUniformBuffer *globals_ubo; /* draw_common.c */
 
 
 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 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[];
 
 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_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);
 
        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) {
        });
 
        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) {
        }
 
        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,
                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);
                        is_clip ? DEF_WORLD_CLIP_STR : NULL);
+               MEM_freeN(lib);
        }
 
        if (!sh_data->overlay_vert) {
        }
 
        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) {
                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,
                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)));
                        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) {
        }
        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,
                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);
                        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";
        }
        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_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";
                        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_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) {
                        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_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) {
                        is_clip ? DEF_WORLD_CLIP_STR : NULL);
        }
        if (!sh_data->depth) {
index 2fc4cf3a765c44587b3d8c5c5630da1ab15756ad..16e008d349dcdc7f73aedd7bf1508e49a2093099 100644 (file)
@@ -82,6 +82,8 @@ static struct {
        OVERLAY_ShaderData sh_data[2];
 } e_data = {NULL};
 
        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[];
 /* 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) {
        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) {
        }
 
        if (!stl->g_data) {
@@ -123,30 +125,34 @@ static void overlay_engine_init(void *vedata)
 
        if (!sh_data->face_orientation_sh) {
                /* Face orientation */
 
        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_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) {
                        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_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)));
 
                        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_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);
 
                        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_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)));
        }
                        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 (file)
index 0000000..b889780
--- /dev/null
@@ -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
index 2a54ca706844e9dd9f829a7871868e6af9f902cb..a66560cd8d97a9aef39a5b9f0a6b03d3544e2a4d 100644 (file)
@@ -2,11 +2,6 @@
 uniform mat4 ModelViewProjectionMatrix;
 uniform mat4 ModelMatrix;
 
 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;
 
 in vec3 pos;
 in vec4 norAndFlag;
 
@@ -36,11 +31,6 @@ void main()
 #endif
 
 #ifdef USE_WORLD_CLIP_PLANES
 #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
 }
 #endif
 }
index fa808b4fdb93dd89608e1954147d25ffe6726b94..95630fc2e0f542a7ac77ec1bf33285103db2feb6 100644 (file)
@@ -3,11 +3,6 @@ uniform mat4 ModelViewProjectionMatrix;
 uniform mat4 ModelMatrix;
 uniform ivec4 dataMask = ivec4(0xFF);
 
 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;
 
 in vec3 pos;
 in ivec4 data;
 
@@ -33,11 +28,6 @@ void main()
                faceColor = colorFace;
 
 #ifdef USE_WORLD_CLIP_PLANES
                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
 }
 #endif
 }
index e8987b59c45f116f1110b59a5f6572af50a4d37c..76c53b3cf868d2d07ea90ba3c16e2aa72c49200f 100644 (file)
@@ -9,10 +9,6 @@ uniform mat4 ProjectionMatrix;
 uniform mat4 ViewProjectionMatrixInverse;
 uniform vec2 viewportSize;
 
 uniform mat4 ViewProjectionMatrixInverse;
 uniform vec2 viewportSize;
 
-#ifdef USE_WORLD_CLIP_PLANES
-uniform int  WorldClipPlanesLen;
-#endif
-
 in vec4 pPos[];
 in ivec4 vData[];
 #ifdef VERTEX_FACING
 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
        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();
 #endif
 
        EmitVertex();
index 3fcc3a7240f7514291d4cd26b1511bf3e82c15c5..1c88f1ff95981be33bb540a1bf2c2cb896677d71 100644 (file)
@@ -15,10 +15,6 @@ uniform mat4 ProjectionMatrix;
 uniform vec2 viewportSize;
 uniform bool isXray = false;
 
 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. */
 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
        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();
 #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
        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();
 #endif
 
        EmitVertex();
index 53a560972349b8cb9489bcb52376832df363f5c9..687e5b0a0fc602713c63653e00c0fb21a14864d6 100644 (file)
@@ -6,11 +6,6 @@ uniform mat4 ModelViewProjectionMatrix;
 uniform mat4 ModelMatrix;
 uniform float ofs = 3e-5;
 
 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
 in vec3 pos;
 in ivec4 data;
 #ifdef VERTEX_FACING
@@ -56,11 +51,6 @@ void main()
        }
 
 #ifdef USE_WORLD_CLIP_PLANES
        }
 
 #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
 }
 #endif
 }
index d4d7c455b1b167d39cb1248b45b2d0ed69ad1762..13431168fb0bc5cac95431a730de7ab2305a22d0 100644 (file)
@@ -9,12 +9,6 @@ uniform mat4 ModelViewProjectionMatrix;
 uniform mat4 ModelMatrix;
 uniform ivec4 dataMask = ivec4(0xFF);
 
 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;
 in vec3 pos;
 #ifdef VERTEX_FACING
 in vec3 vnor;
@@ -43,12 +37,7 @@ void main()
 #  endif
 
 #  ifdef USE_WORLD_CLIP_PLANES
 #  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
 }
 
 #  endif
 }
 
@@ -115,12 +104,7 @@ void main()
 #  endif
 
 #  ifdef USE_WORLD_CLIP_PLANES
 #  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
 }
 
 #  endif
 }
 
index 50214c75e6ab4369d6a99148c4d2c455107cbb27..91a57a79eb019b2514b2b69f535831c804d0e856 100644 (file)
@@ -2,10 +2,6 @@
 layout(points) in;
 layout(line_strip, max_vertices=2) out;
 
 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];
 
 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 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();
        }
 #endif
                EmitVertex();
        }
index 99741de63bb2a7168d3d859410dc1d41ff417412..8d73a2f5ad2f440d55eba3bd718bc8291959a89a 100644 (file)
@@ -5,11 +5,6 @@ uniform mat4 ProjectionMatrix;
 uniform mat4 ModelMatrix;
 uniform float normalSize;
 
 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
 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 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
 }
 #endif
 }
index 2d025bc65eea3c76121a57d26c20a6c693b00d26..f9f2679fe81fa6e547eaa15f5de95109fbcef1e1 100644 (file)
@@ -1,11 +1,6 @@
 uniform mat4 ModelViewProjectionMatrix;
 uniform mat4 ModelMatrix;
 
 uniform mat4 ModelViewProjectionMatrix;
 uniform mat4 ModelMatrix;
 
-#ifdef USE_WORLD_CLIP_PLANES
-uniform vec4 WorldClipPlanes[6];
-uniform int  WorldClipPlanesLen;
-#endif
-
 in vec3 pos;
 
 void main()
 in vec3 pos;
 
 void main()
@@ -13,11 +8,6 @@ void main()
        gl_Position = ModelViewProjectionMatrix * vec4(pos, 1.0);
 
 #ifdef USE_WORLD_CLIP_PLANES
        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
 }
 #endif
 }
index 2f3acc2a050c51038fed7645d46cd43ce2493497..d4d53b7d24d2ed4b6d8fc6f26bbef8067cb50e9c 100644 (file)
@@ -8,10 +8,6 @@ layout(line_strip, max_vertices = 6) out;
 layout(triangle_strip, max_vertices = 3) out;
 #endif
 
 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[];
 
 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
 {
        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
 }
 
 #endif
 }
 
index 3c3869db7b48807fcbfd7400f1e71919709e6be3..cb07c53520068a9bba9a4470d0bbd9d098f78824 100644 (file)
@@ -5,11 +5,6 @@ uniform mat3 NormalMatrix;
 
 uniform vec2 wireStepParam;
 
 
 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));
 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
        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
 }
 
 #endif
 }
 
index ab0fb775e5420c34cfc9a7932b593831d2454d84..d111f3dc0a87a8a789e67cc56dc27e459a0aa6d4 100644 (file)
@@ -2,11 +2,6 @@
 uniform mat4 ModelViewProjectionMatrix;
 uniform mat4 ModelMatrix;
 
 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;
 
 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
        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
 }
 #endif
 }