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 8ba9058..a305d18 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_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)
index e821581..66372f8 100644 (file)
@@ -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
 
 }
index 60bcae3..3878721 100644 (file)
@@ -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;
                }
        }
 
index 3f537f6..dce30a7 100644 (file)
@@ -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);
index 94cbb20..485348f 100644 (file)
@@ -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);
index ce71189..d19f929 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 (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);
        }
 }
index a4cfd29..82d84fe 100644 (file)
@@ -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;
index 96525a4..cb5b807 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_set_from_rv3d(struct RegionView3D *rv3d);
 
 /* Culling, return true if object is inside view frustum. */
 bool DRW_culling_sphere_test(BoundSphere *bsphere);
index 250b0a1..bb24783 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);
-       DRW_shgroup_uniform_int_copy(shgrp, "WorldClipPlanesLen", world_clip_planes_len);
        DRW_shgroup_state_enable(shgrp, DRW_STATE_CLIP_PLANES);
 }
 
index e5654ab..21647d5 100644 (file)
@@ -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);
+}
+
 /** \} */
 
 /* -------------------------------------------------------------------- */
index 1a3d7fb..59aa4ea 100644 (file)
@@ -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) {
index 2fc4cf3..16e008d 100644 (file)
@@ -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 (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 2a54ca7..a66560c 100644 (file)
@@ -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
 }
index fa808b4..95630fc 100644 (file)
@@ -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
 }
index e8987b5..76c53b3 100644 (file)
@@ -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();
index 3fcc3a7..1c88f1f 100644 (file)
@@ -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();
index 53a5609..687e5b0 100644 (file)
@@ -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
 }
index d4d7c45..1343116 100644 (file)
@@ -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
 }
 
index 50214c7..91a57a7 100644 (file)
@@ -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();
        }
index 99741de..8d73a2f 100644 (file)
@@ -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
 }
index 2d025bc..f9f2679 100644 (file)
@@ -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
 }
index 2f3acc2..d4d53b7 100644 (file)
@@ -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
 }
 
index 3c3869d..cb07c53 100644 (file)
@@ -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
 }
 
index ab0fb77..d111f3d 100644 (file)
@@ -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
 }