DRW: support clipping for empty object
authorCampbell Barton <ideasman42@gmail.com>
Sat, 26 Jan 2019 04:00:03 +0000 (15:00 +1100)
committerCampbell Barton <ideasman42@gmail.com>
Sat, 26 Jan 2019 04:49:14 +0000 (15:49 +1100)
source/blender/draw/intern/draw_builtin_shader.c
source/blender/draw/intern/draw_common.c
source/blender/draw/intern/draw_common.h
source/blender/draw/modes/object_mode.c
source/blender/draw/modes/shaders/object_empty_axes_vert.glsl
source/blender/draw/modes/shaders/object_empty_image_vert.glsl
source/blender/gpu/shaders/gpu_shader_instance_camera_vert.glsl
source/blender/gpu/shaders/gpu_shader_instance_variying_size_variying_color_vert.glsl

index 889dbaed3da3b178d613aab5168a7c9615c09e80..68866ad29031cfaf42bb8b7ec5040aece2657908 100644 (file)
@@ -44,6 +44,7 @@ extern char datatoc_gpu_shader_3D_vert_glsl[];
 extern char datatoc_gpu_shader_depth_only_frag_glsl[];
 extern char datatoc_gpu_shader_flat_color_frag_glsl[];
 extern char datatoc_gpu_shader_instance_camera_vert_glsl[];
+extern char datatoc_gpu_shader_instance_variying_size_variying_color_vert_glsl[];
 extern char datatoc_gpu_shader_uniform_color_frag_glsl[];
 
 /* cache of built-in shaders (each is created on first use) */
@@ -98,6 +99,25 @@ static GPUShader *drw_shader_get_builtin_shader_clipped(eGPUBuiltinShader shader
                                .frag = (const char *[]){datatoc_gpu_shader_flat_color_frag_glsl, NULL},
                                .defs = (const char *[]){world_clip_def, NULL}});
                        break;
+
+               case GPU_SHADER_INSTANCE_VARIYING_COLOR_VARIYING_SIZE:
+                       if (r_test_only) {
+                               break;
+                       }
+                       shader = DRW_shader_create_from_arrays({
+                               .vert = (const char *[]){world_clip_lib, datatoc_gpu_shader_instance_variying_size_variying_color_vert_glsl, NULL},
+                               .frag = (const char *[]){datatoc_gpu_shader_flat_color_frag_glsl, NULL},
+                               .defs = (const char *[]){world_clip_def, "#define UNIFORM_SCALE\n", NULL}});
+                       break;
+               case GPU_SHADER_INSTANCE_VARIYING_COLOR_VARIYING_SCALE:
+                       if (r_test_only) {
+                               break;
+                       }
+                       shader = DRW_shader_create_from_arrays({
+                               .vert = (const char *[]){world_clip_lib, datatoc_gpu_shader_instance_variying_size_variying_color_vert_glsl, NULL},
+                               .frag = (const char *[]){datatoc_gpu_shader_flat_color_frag_glsl, NULL},
+                               .defs = (const char *[]){world_clip_def, NULL}});
+                       break;
                default:
                        /* Unsupported, caller asserts. */
                        if (r_test_only) {
index e7a129071b673de9db99fa56bc61ac0883fa853b..45cfca4e7d56d1e45d083c9773de09c1e6cbd381 100644 (file)
@@ -236,6 +236,7 @@ extern char datatoc_armature_stick_frag_glsl[];
 extern char datatoc_armature_dof_vert_glsl[];
 
 extern char datatoc_common_globals_lib_glsl[];
+extern char datatoc_common_world_clip_lib_glsl[];
 
 extern char datatoc_gpu_shader_flat_color_frag_glsl[];
 extern char datatoc_gpu_shader_3D_smooth_color_frag_glsl[];
@@ -244,7 +245,7 @@ extern char datatoc_gpu_shader_point_varying_color_frag_glsl[];
 extern char datatoc_object_mball_handles_vert_glsl[];
 extern char datatoc_object_empty_axes_vert_glsl[];
 
-static struct {
+typedef struct COMMON_Shaders {
        struct GPUShader *shape_outline;
        struct GPUShader *shape_solid;
        struct GPUShader *bone_axes;
@@ -264,7 +265,9 @@ static struct {
        struct GPUShader *empty_axes_sh;
 
        struct GPUShader *mball_handles;
-} g_shaders = {NULL};
+} COMMON_Shaders;
+
+static COMMON_Shaders g_shaders[DRW_SHADER_SLOT_LEN] = {{NULL}};
 
 static struct {
        struct GPUVertFormat *instance_screenspace;
@@ -295,9 +298,11 @@ void DRW_globals_free(void)
                MEM_SAFE_FREE(*format);
        }
 
-       struct GPUShader **shader = &g_shaders.shape_outline;
-       for (int i = 0; i < sizeof(g_shaders) / sizeof(void *); ++i, ++shader) {
-               DRW_SHADER_FREE_SAFE(*shader);
+       for (int j = 0; j < DRW_SHADER_SLOT_LEN; j++) {
+               struct GPUShader **shader = &g_shaders[j].shape_outline;
+               for (int i = 0; i < sizeof(g_shaders[j]) / sizeof(void *); ++i, ++shader) {
+                       DRW_SHADER_FREE_SAFE(*shader);
+               }
        }
 }
 
@@ -434,9 +439,9 @@ DRWShadingGroup *shgroup_instance_screen_aligned(DRWPass *pass, struct GPUBatch
        return grp;
 }
 
-DRWShadingGroup *shgroup_instance_scaled(DRWPass *pass, struct GPUBatch *geom)
+DRWShadingGroup *shgroup_instance_scaled(DRWPass *pass, struct GPUBatch *geom, eDRW_ShaderSlot shader_slot)
 {
-       GPUShader *sh_inst = GPU_shader_get_builtin_shader(GPU_SHADER_INSTANCE_VARIYING_COLOR_VARIYING_SCALE);
+       GPUShader *sh_inst = DRW_shader_get_builtin_shader(GPU_SHADER_INSTANCE_VARIYING_COLOR_VARIYING_SCALE, shader_slot);
 
        DRW_shgroup_instance_format(g_formats.instance_scaled, {
                {"color",               DRW_ATTRIB_FLOAT, 3},
@@ -445,13 +450,15 @@ DRWShadingGroup *shgroup_instance_scaled(DRWPass *pass, struct GPUBatch *geom)
        });
 
        DRWShadingGroup *grp = DRW_shgroup_instance_create(sh_inst, pass, geom, g_formats.instance_scaled);
-
+       if (shader_slot == DRW_SHADER_SLOT_CLIPPED) {
+               DRW_shgroup_world_clip_planes_from_rv3d(grp, DRW_context_state_get()->rv3d);
+       }
        return grp;
 }
 
-DRWShadingGroup *shgroup_instance(DRWPass *pass, struct GPUBatch *geom)
+DRWShadingGroup *shgroup_instance(DRWPass *pass, struct GPUBatch *geom, eDRW_ShaderSlot shader_slot)
 {
-       GPUShader *sh_inst = GPU_shader_get_builtin_shader(GPU_SHADER_INSTANCE_VARIYING_COLOR_VARIYING_SIZE);
+       GPUShader *sh_inst = DRW_shader_get_builtin_shader(GPU_SHADER_INSTANCE_VARIYING_COLOR_VARIYING_SIZE, shader_slot);
 
        DRW_shgroup_instance_format(g_formats.instance_sized, {
                {"color",               DRW_ATTRIB_FLOAT, 4},
@@ -461,13 +468,15 @@ DRWShadingGroup *shgroup_instance(DRWPass *pass, struct GPUBatch *geom)
 
        DRWShadingGroup *grp = DRW_shgroup_instance_create(sh_inst, pass, geom, g_formats.instance_sized);
        DRW_shgroup_state_disable(grp, DRW_STATE_BLEND);
-
+       if (shader_slot == DRW_SHADER_SLOT_CLIPPED) {
+               DRW_shgroup_world_clip_planes_from_rv3d(grp, DRW_context_state_get()->rv3d);
+       }
        return grp;
 }
 
-DRWShadingGroup *shgroup_instance_alpha(DRWPass *pass, struct GPUBatch *geom)
+DRWShadingGroup *shgroup_instance_alpha(DRWPass *pass, struct GPUBatch *geom, eDRW_ShaderSlot shader_slot)
 {
-       GPUShader *sh_inst = GPU_shader_get_builtin_shader(GPU_SHADER_INSTANCE_VARIYING_COLOR_VARIYING_SIZE);
+       GPUShader *sh_inst = DRW_shader_get_builtin_shader(GPU_SHADER_INSTANCE_VARIYING_COLOR_VARIYING_SIZE, shader_slot);
 
        DRW_shgroup_instance_format(g_formats.instance_sized, {
                {"color",               DRW_ATTRIB_FLOAT, 4},
@@ -476,16 +485,22 @@ DRWShadingGroup *shgroup_instance_alpha(DRWPass *pass, struct GPUBatch *geom)
        });
 
        DRWShadingGroup *grp = DRW_shgroup_instance_create(sh_inst, pass, geom, g_formats.instance_sized);
-
+       if (shader_slot == DRW_SHADER_SLOT_CLIPPED) {
+               DRW_shgroup_world_clip_planes_from_rv3d(grp, DRW_context_state_get()->rv3d);
+       }
        return grp;
 }
 
-DRWShadingGroup *shgroup_instance_empty_axes(DRWPass *pass, struct GPUBatch *geom)
+DRWShadingGroup *shgroup_instance_empty_axes(DRWPass *pass, struct GPUBatch *geom, eDRW_ShaderSlot shader_slot)
 {
-       if (g_shaders.empty_axes_sh == NULL) {
-               g_shaders.empty_axes_sh = DRW_shader_create(
-                       datatoc_object_empty_axes_vert_glsl, NULL,
-                       datatoc_gpu_shader_flat_color_frag_glsl, NULL);
+       COMMON_Shaders *sh_data = &g_shaders[shader_slot];
+       const char *world_clip_lib_or_empty = (shader_slot == DRW_SHADER_SLOT_CLIPPED) ? datatoc_common_world_clip_lib_glsl : "";
+       const char *world_clip_def_or_empty = (shader_slot == DRW_SHADER_SLOT_CLIPPED) ? "#define USE_WORLD_CLIP_PLANES\n" : "";
+       if (sh_data->empty_axes_sh == NULL) {
+               sh_data->empty_axes_sh = DRW_shader_create_from_arrays({
+                       .vert = (const char *[]){world_clip_lib_or_empty, datatoc_object_empty_axes_vert_glsl, NULL},
+                       .frag = (const char *[]){datatoc_gpu_shader_flat_color_frag_glsl, NULL},
+                       .defs = (const char *[]){world_clip_def_or_empty, NULL}});
        }
 
        DRW_shgroup_instance_format(g_formats.instance_sized, {
@@ -494,9 +509,11 @@ DRWShadingGroup *shgroup_instance_empty_axes(DRWPass *pass, struct GPUBatch *geo
                {"InstanceModelMatrix", DRW_ATTRIB_FLOAT, 16}
        });
 
-       DRWShadingGroup *grp = DRW_shgroup_instance_create(g_shaders.empty_axes_sh, pass, geom, g_formats.instance_sized);
+       DRWShadingGroup *grp = DRW_shgroup_instance_create(sh_data->empty_axes_sh, pass, geom, g_formats.instance_sized);
        DRW_shgroup_uniform_vec3(grp, "screenVecs[0]", DRW_viewport_screenvecs_get(), 2);
-
+       if (shader_slot == DRW_SHADER_SLOT_CLIPPED) {
+               DRW_shgroup_world_clip_planes_from_rv3d(grp, DRW_context_state_get()->rv3d);
+       }
        return grp;
 }
 
@@ -574,10 +591,11 @@ DRWShadingGroup *shgroup_spot_instance(DRWPass *pass, struct GPUBatch *geom)
 
 DRWShadingGroup *shgroup_instance_bone_axes(DRWPass *pass)
 {
-       if (g_shaders.bone_axes == NULL) {
-               g_shaders.bone_axes = DRW_shader_create(
-                           datatoc_armature_axes_vert_glsl, NULL,
-                           datatoc_gpu_shader_flat_color_frag_glsl, NULL);
+       COMMON_Shaders *sh_data = &g_shaders[DRW_SHADER_SLOT_DEFAULT];
+       if (sh_data->bone_axes == NULL) {
+               sh_data->bone_axes = DRW_shader_create(
+                       datatoc_armature_axes_vert_glsl, NULL,
+                       datatoc_gpu_shader_flat_color_frag_glsl, NULL);
        }
 
        DRW_shgroup_instance_format(g_formats.instance_color, {
@@ -586,7 +604,7 @@ DRWShadingGroup *shgroup_instance_bone_axes(DRWPass *pass)
        });
 
        DRWShadingGroup *grp = DRW_shgroup_instance_create(
-               g_shaders.bone_axes,
+               sh_data->bone_axes,
                pass, DRW_cache_bone_arrows_get(),
                g_formats.instance_color);
        DRW_shgroup_uniform_vec3(grp, "screenVecs[0]", DRW_viewport_screenvecs_get(), 2);
@@ -596,10 +614,11 @@ DRWShadingGroup *shgroup_instance_bone_axes(DRWPass *pass)
 
 DRWShadingGroup *shgroup_instance_bone_envelope_outline(DRWPass *pass)
 {
-       if (g_shaders.bone_envelope_outline == NULL) {
-               g_shaders.bone_envelope_outline = DRW_shader_create(
-                           datatoc_armature_envelope_outline_vert_glsl, NULL,
-                           datatoc_gpu_shader_flat_color_frag_glsl, NULL);
+       COMMON_Shaders *sh_data = &g_shaders[DRW_SHADER_SLOT_DEFAULT];
+       if (sh_data->bone_envelope_outline == NULL) {
+               sh_data->bone_envelope_outline = DRW_shader_create(
+                       datatoc_armature_envelope_outline_vert_glsl, NULL,
+                       datatoc_gpu_shader_flat_color_frag_glsl, NULL);
        }
 
        DRW_shgroup_instance_format(g_formats.instance_bone_envelope_outline, {
@@ -610,7 +629,7 @@ DRWShadingGroup *shgroup_instance_bone_envelope_outline(DRWPass *pass)
        });
 
        DRWShadingGroup *grp = DRW_shgroup_instance_create(
-               g_shaders.bone_envelope_outline,
+               sh_data->bone_envelope_outline,
                pass, DRW_cache_bone_envelope_outline_get(),
                g_formats.instance_bone_envelope_outline);
        DRW_shgroup_uniform_vec2(grp, "viewportSize", DRW_viewport_size_get(), 1);
@@ -620,10 +639,11 @@ DRWShadingGroup *shgroup_instance_bone_envelope_outline(DRWPass *pass)
 
 DRWShadingGroup *shgroup_instance_bone_envelope_distance(DRWPass *pass)
 {
-       if (g_shaders.bone_envelope_distance == NULL) {
-               g_shaders.bone_envelope_distance = DRW_shader_create(
-                           datatoc_armature_envelope_solid_vert_glsl, NULL,
-                           datatoc_armature_envelope_distance_frag_glsl, NULL);
+       COMMON_Shaders *sh_data = &g_shaders[DRW_SHADER_SLOT_DEFAULT];
+       if (sh_data->bone_envelope_distance == NULL) {
+               sh_data->bone_envelope_distance = DRW_shader_create(
+                       datatoc_armature_envelope_solid_vert_glsl, NULL,
+                       datatoc_armature_envelope_distance_frag_glsl, NULL);
        }
 
        DRW_shgroup_instance_format(g_formats.instance_bone_envelope_distance, {
@@ -633,7 +653,7 @@ DRWShadingGroup *shgroup_instance_bone_envelope_distance(DRWPass *pass)
        });
 
        DRWShadingGroup *grp = DRW_shgroup_instance_create(
-               g_shaders.bone_envelope_distance,
+               sh_data->bone_envelope_distance,
                pass, DRW_cache_bone_envelope_solid_get(),
                g_formats.instance_bone_envelope_distance);
 
@@ -642,10 +662,11 @@ DRWShadingGroup *shgroup_instance_bone_envelope_distance(DRWPass *pass)
 
 DRWShadingGroup *shgroup_instance_bone_envelope_solid(DRWPass *pass, bool transp)
 {
-       if (g_shaders.bone_envelope == NULL) {
-               g_shaders.bone_envelope = DRW_shader_create(
-                           datatoc_armature_envelope_solid_vert_glsl, NULL,
-                           datatoc_armature_envelope_solid_frag_glsl, "#define SMOOTH_ENVELOPE\n");
+       COMMON_Shaders *sh_data = &g_shaders[DRW_SHADER_SLOT_DEFAULT];
+       if (sh_data->bone_envelope == NULL) {
+               sh_data->bone_envelope = DRW_shader_create(
+                       datatoc_armature_envelope_solid_vert_glsl, NULL,
+                       datatoc_armature_envelope_solid_frag_glsl, "#define SMOOTH_ENVELOPE\n");
        }
 
        DRW_shgroup_instance_format(g_formats.instance_bone_envelope, {
@@ -657,7 +678,7 @@ DRWShadingGroup *shgroup_instance_bone_envelope_solid(DRWPass *pass, bool transp
        });
 
        DRWShadingGroup *grp = DRW_shgroup_instance_create(
-               g_shaders.bone_envelope,
+               sh_data->bone_envelope,
                pass, DRW_cache_bone_envelope_solid_get(),
                g_formats.instance_bone_envelope);
        DRW_shgroup_uniform_float_copy(grp, "alpha", transp ? 0.6f : 1.0f);
@@ -667,10 +688,11 @@ DRWShadingGroup *shgroup_instance_bone_envelope_solid(DRWPass *pass, bool transp
 
 DRWShadingGroup *shgroup_instance_mball_handles(DRWPass *pass)
 {
-       if (g_shaders.mball_handles == NULL) {
-               g_shaders.mball_handles = DRW_shader_create(
-                           datatoc_object_mball_handles_vert_glsl, NULL,
-                           datatoc_gpu_shader_flat_color_frag_glsl, NULL);
+       COMMON_Shaders *sh_data = &g_shaders[DRW_SHADER_SLOT_DEFAULT];
+       if (sh_data->mball_handles == NULL) {
+               sh_data->mball_handles = DRW_shader_create(
+                       datatoc_object_mball_handles_vert_glsl, NULL,
+                       datatoc_gpu_shader_flat_color_frag_glsl, NULL);
        }
 
        DRW_shgroup_instance_format(g_formats.instance_mball_handles, {
@@ -680,7 +702,7 @@ DRWShadingGroup *shgroup_instance_mball_handles(DRWPass *pass)
        });
 
        DRWShadingGroup *grp = DRW_shgroup_instance_create(
-               g_shaders.mball_handles, pass,
+               sh_data->mball_handles, pass,
                DRW_cache_screenspace_circle_get(),
                g_formats.instance_mball_handles);
        DRW_shgroup_uniform_vec3(grp, "screen_vecs[0]", DRW_viewport_screenvecs_get(), 2);
@@ -691,12 +713,13 @@ DRWShadingGroup *shgroup_instance_mball_handles(DRWPass *pass)
 /* Only works with batches with adjacency infos. */
 DRWShadingGroup *shgroup_instance_bone_shape_outline(DRWPass *pass, struct GPUBatch *geom)
 {
-       if (g_shaders.shape_outline == NULL) {
-               g_shaders.shape_outline = DRW_shader_create(
-                           datatoc_armature_shape_outline_vert_glsl,
-                           datatoc_armature_shape_outline_geom_glsl,
-                           datatoc_gpu_shader_flat_color_frag_glsl,
-                           NULL);
+       COMMON_Shaders *sh_data = &g_shaders[DRW_SHADER_SLOT_DEFAULT];
+       if (sh_data->shape_outline == NULL) {
+               sh_data->shape_outline = DRW_shader_create(
+                       datatoc_armature_shape_outline_vert_glsl,
+                       datatoc_armature_shape_outline_geom_glsl,
+                       datatoc_gpu_shader_flat_color_frag_glsl,
+                       NULL);
        }
 
        DRW_shgroup_instance_format(g_formats.instance_bone_outline, {
@@ -705,7 +728,7 @@ DRWShadingGroup *shgroup_instance_bone_shape_outline(DRWPass *pass, struct GPUBa
        });
 
        DRWShadingGroup *grp = DRW_shgroup_instance_create(
-               g_shaders.shape_outline,
+               sh_data->shape_outline,
                pass, geom, g_formats.instance_bone_outline);
        DRW_shgroup_uniform_vec2(grp, "viewportSize", DRW_viewport_size_get(), 1);
 
@@ -714,10 +737,11 @@ DRWShadingGroup *shgroup_instance_bone_shape_outline(DRWPass *pass, struct GPUBa
 
 DRWShadingGroup *shgroup_instance_bone_shape_solid(DRWPass *pass, struct GPUBatch *geom, bool transp)
 {
-       if (g_shaders.shape_solid == NULL) {
-               g_shaders.shape_solid = DRW_shader_create(
-                           datatoc_armature_shape_solid_vert_glsl, NULL,
-                           datatoc_armature_shape_solid_frag_glsl, NULL);
+       COMMON_Shaders *sh_data = &g_shaders[DRW_SHADER_SLOT_DEFAULT];
+       if (sh_data->shape_solid == NULL) {
+               sh_data->shape_solid = DRW_shader_create(
+                       datatoc_armature_shape_solid_vert_glsl, NULL,
+                       datatoc_armature_shape_solid_frag_glsl, NULL);
        }
 
        DRW_shgroup_instance_format(g_formats.instance_bone, {
@@ -727,7 +751,7 @@ DRWShadingGroup *shgroup_instance_bone_shape_solid(DRWPass *pass, struct GPUBatc
        });
 
        DRWShadingGroup *grp = DRW_shgroup_instance_create(
-               g_shaders.shape_solid,
+               sh_data->shape_solid,
                pass, geom, g_formats.instance_bone);
        DRW_shgroup_uniform_float_copy(grp, "alpha", transp ? 0.6f : 1.0f);
 
@@ -736,10 +760,11 @@ DRWShadingGroup *shgroup_instance_bone_shape_solid(DRWPass *pass, struct GPUBatc
 
 DRWShadingGroup *shgroup_instance_bone_sphere_solid(DRWPass *pass, bool transp)
 {
-       if (g_shaders.bone_sphere == NULL) {
-               g_shaders.bone_sphere = DRW_shader_create(
-                           datatoc_armature_sphere_solid_vert_glsl, NULL,
-                           datatoc_armature_sphere_solid_frag_glsl, NULL);
+       COMMON_Shaders *sh_data = &g_shaders[DRW_SHADER_SLOT_DEFAULT];
+       if (sh_data->bone_sphere == NULL) {
+               sh_data->bone_sphere = DRW_shader_create(
+                       datatoc_armature_sphere_solid_vert_glsl, NULL,
+                       datatoc_armature_sphere_solid_frag_glsl, NULL);
        }
 
        DRW_shgroup_instance_format(g_formats.instance_bone, {
@@ -749,7 +774,7 @@ DRWShadingGroup *shgroup_instance_bone_sphere_solid(DRWPass *pass, bool transp)
        });
 
        DRWShadingGroup *grp = DRW_shgroup_instance_create(
-               g_shaders.bone_sphere,
+               sh_data->bone_sphere,
                pass, DRW_cache_bone_point_get(), g_formats.instance_bone);
        /* More transparent than the shape to be less distractive. */
        DRW_shgroup_uniform_float_copy(grp, "alpha", transp ? 0.4f : 1.0f);
@@ -759,10 +784,11 @@ DRWShadingGroup *shgroup_instance_bone_sphere_solid(DRWPass *pass, bool transp)
 
 DRWShadingGroup *shgroup_instance_bone_sphere_outline(DRWPass *pass)
 {
-       if (g_shaders.bone_sphere_outline == NULL) {
-               g_shaders.bone_sphere_outline = DRW_shader_create(
-                           datatoc_armature_sphere_outline_vert_glsl, NULL,
-                           datatoc_gpu_shader_flat_color_frag_glsl, NULL);
+       COMMON_Shaders *sh_data = &g_shaders[DRW_SHADER_SLOT_DEFAULT];
+       if (sh_data->bone_sphere_outline == NULL) {
+               sh_data->bone_sphere_outline = DRW_shader_create(
+                       datatoc_armature_sphere_outline_vert_glsl, NULL,
+                       datatoc_gpu_shader_flat_color_frag_glsl, NULL);
        }
 
        DRW_shgroup_instance_format(g_formats.instance_bone_outline, {
@@ -771,7 +797,7 @@ DRWShadingGroup *shgroup_instance_bone_sphere_outline(DRWPass *pass)
        });
 
        DRWShadingGroup *grp = DRW_shgroup_instance_create(
-               g_shaders.bone_sphere_outline,
+               sh_data->bone_sphere_outline,
                pass, DRW_cache_bone_point_wire_outline_get(),
                g_formats.instance_bone_outline);
        DRW_shgroup_uniform_vec2(grp, "viewportSize", DRW_viewport_size_get(), 1);
@@ -781,10 +807,11 @@ DRWShadingGroup *shgroup_instance_bone_sphere_outline(DRWPass *pass)
 
 DRWShadingGroup *shgroup_instance_bone_stick(DRWPass *pass)
 {
-       if (g_shaders.bone_stick == NULL) {
-               g_shaders.bone_stick = DRW_shader_create(
-                           datatoc_armature_stick_vert_glsl, NULL,
-                           datatoc_armature_stick_frag_glsl, NULL);
+       COMMON_Shaders *sh_data = &g_shaders[DRW_SHADER_SLOT_DEFAULT];
+       if (sh_data->bone_stick == NULL) {
+               sh_data->bone_stick = DRW_shader_create(
+                       datatoc_armature_stick_vert_glsl, NULL,
+                       datatoc_armature_stick_frag_glsl, NULL);
        }
 
        DRW_shgroup_instance_format(g_formats.instance_bone_stick, {
@@ -797,7 +824,7 @@ DRWShadingGroup *shgroup_instance_bone_stick(DRWPass *pass)
        });
 
        DRWShadingGroup *grp = DRW_shgroup_instance_create(
-               g_shaders.bone_stick,
+               sh_data->bone_stick,
                pass, DRW_cache_bone_stick_get(),
                g_formats.instance_bone_stick);
        DRW_shgroup_uniform_vec2(grp, "viewportSize", DRW_viewport_size_get(), 1);
@@ -808,10 +835,11 @@ DRWShadingGroup *shgroup_instance_bone_stick(DRWPass *pass)
 
 struct DRWShadingGroup *shgroup_instance_bone_dof(struct DRWPass *pass, struct GPUBatch *geom)
 {
-       if (g_shaders.bone_dofs == NULL) {
-               g_shaders.bone_dofs = DRW_shader_create(
-                           datatoc_armature_dof_vert_glsl, NULL,
-                           datatoc_gpu_shader_flat_color_frag_glsl, NULL);
+       COMMON_Shaders *sh_data = &g_shaders[DRW_SHADER_SLOT_DEFAULT];
+       if (sh_data->bone_dofs == NULL) {
+               sh_data->bone_dofs = DRW_shader_create(
+                       datatoc_armature_dof_vert_glsl, NULL,
+                       datatoc_gpu_shader_flat_color_frag_glsl, NULL);
        }
 
        DRW_shgroup_instance_format(g_formats.instance_bone_dof, {
@@ -822,7 +850,7 @@ struct DRWShadingGroup *shgroup_instance_bone_dof(struct DRWPass *pass, struct G
        });
 
        DRWShadingGroup *grp = DRW_shgroup_instance_create(
-               g_shaders.bone_dofs,
+               sh_data->bone_dofs,
                pass, geom,
                g_formats.instance_bone_dof);
 
@@ -831,48 +859,51 @@ struct DRWShadingGroup *shgroup_instance_bone_dof(struct DRWPass *pass, struct G
 
 struct GPUShader *mpath_line_shader_get(void)
 {
-       if (g_shaders.mpath_line_sh == NULL) {
-               g_shaders.mpath_line_sh = DRW_shader_create_with_lib(
+       COMMON_Shaders *sh_data = &g_shaders[DRW_SHADER_SLOT_DEFAULT];
+       if (sh_data->mpath_line_sh == NULL) {
+               sh_data->mpath_line_sh = DRW_shader_create_with_lib(
                        datatoc_animviz_mpath_lines_vert_glsl,
                        datatoc_animviz_mpath_lines_geom_glsl,
                        datatoc_gpu_shader_3D_smooth_color_frag_glsl,
                        datatoc_common_globals_lib_glsl,
                        NULL);
        }
-       return g_shaders.mpath_line_sh;
+       return sh_data->mpath_line_sh;
 }
 
 
 struct GPUShader *mpath_points_shader_get(void)
 {
-       if (g_shaders.mpath_points_sh == NULL) {
-               g_shaders.mpath_points_sh = DRW_shader_create_with_lib(
+       COMMON_Shaders *sh_data = &g_shaders[DRW_SHADER_SLOT_DEFAULT];
+       if (sh_data->mpath_points_sh == NULL) {
+               sh_data->mpath_points_sh = DRW_shader_create_with_lib(
                        datatoc_animviz_mpath_points_vert_glsl,
                        NULL,
                        datatoc_gpu_shader_point_varying_color_frag_glsl,
                        datatoc_common_globals_lib_glsl,
                        NULL);
        }
-       return g_shaders.mpath_points_sh;
+       return sh_data->mpath_points_sh;
 }
 
 struct GPUShader *volume_velocity_shader_get(bool use_needle)
 {
+       COMMON_Shaders *sh_data = &g_shaders[DRW_SHADER_SLOT_DEFAULT];
        if (use_needle) {
-               if (g_shaders.volume_velocity_needle_sh == NULL) {
-                       g_shaders.volume_velocity_needle_sh = DRW_shader_create(
+               if (sh_data->volume_velocity_needle_sh == NULL) {
+                       sh_data->volume_velocity_needle_sh = DRW_shader_create(
                                datatoc_volume_velocity_vert_glsl, NULL,
                                datatoc_gpu_shader_flat_color_frag_glsl, "#define USE_NEEDLE");
                }
-               return g_shaders.volume_velocity_needle_sh;
+               return sh_data->volume_velocity_needle_sh;
        }
        else {
-               if (g_shaders.volume_velocity_sh == NULL) {
-                       g_shaders.volume_velocity_sh = DRW_shader_create(
+               if (sh_data->volume_velocity_sh == NULL) {
+                       sh_data->volume_velocity_sh = DRW_shader_create(
                                datatoc_volume_velocity_vert_glsl, NULL,
                                datatoc_gpu_shader_flat_color_frag_glsl, NULL);
                }
-               return g_shaders.volume_velocity_sh;
+               return sh_data->volume_velocity_sh;
        }
 }
 
index 2190db8bf311e535ba38ec242648b64e71f235cf..3beab5fe7bbc68375c430220fd8db6c77cac4742 100644 (file)
@@ -149,10 +149,10 @@ struct DRWShadingGroup *shgroup_instance_screenspace(struct DRWPass *pass, struc
 struct DRWShadingGroup *shgroup_instance_solid(struct DRWPass *pass, struct GPUBatch *geom);
 struct DRWShadingGroup *shgroup_instance_wire(struct DRWPass *pass, struct GPUBatch *geom);
 struct DRWShadingGroup *shgroup_instance_screen_aligned(struct DRWPass *pass, struct GPUBatch *geom);
-struct DRWShadingGroup *shgroup_instance_empty_axes(struct DRWPass *pass, struct GPUBatch *geom);
-struct DRWShadingGroup *shgroup_instance_scaled(struct DRWPass *pass, struct GPUBatch *geom);
-struct DRWShadingGroup *shgroup_instance(struct DRWPass *pass, struct GPUBatch *geom);
-struct DRWShadingGroup *shgroup_instance_alpha(struct DRWPass *pass, struct GPUBatch *geom);
+struct DRWShadingGroup *shgroup_instance_empty_axes(struct DRWPass *pass, struct GPUBatch *geom, eDRW_ShaderSlot shader_slot);
+struct DRWShadingGroup *shgroup_instance_scaled(struct DRWPass *pass, struct GPUBatch *geom, eDRW_ShaderSlot shader_slot);
+struct DRWShadingGroup *shgroup_instance(struct DRWPass *pass, struct GPUBatch *geom, eDRW_ShaderSlot shader_slot);
+struct DRWShadingGroup *shgroup_instance_alpha(struct DRWPass *pass, struct GPUBatch *geom, eDRW_ShaderSlot shader_slot);
 struct DRWShadingGroup *shgroup_instance_outline(struct DRWPass *pass, struct GPUBatch *geom, int *baseid);
 struct DRWShadingGroup *shgroup_camera_instance(struct DRWPass *pass, struct GPUBatch *geom, eDRW_ShaderSlot shader_slot);
 struct DRWShadingGroup *shgroup_distance_lines_instance(struct DRWPass *pass, struct GPUBatch *geom);
index 837de9c9ca724ff5acce70f01ea45108db29e683..719e781f291b0ce9c1596349483d73bbc2357b24 100644 (file)
@@ -454,23 +454,21 @@ static void OBJECT_engine_init(void *vedata)
                sh_data->outline_fade_large = DRW_shader_create_fullscreen(datatoc_object_outline_expand_frag_glsl, "#define LARGE_OUTLINE\n");
 
                /* Empty images */
-#              define EMPTY_IMAGE_SHADER_DEFINES \
-                       "#define DEPTH_UNCHANGED " STRINGIFY(OB_EMPTY_IMAGE_DEPTH_DEFAULT) "\n" \
-                       "#define DEPTH_FRONT " STRINGIFY(OB_EMPTY_IMAGE_DEPTH_FRONT) "\n" \
-                       "#define DEPTH_BACK " STRINGIFY(OB_EMPTY_IMAGE_DEPTH_BACK) "\n"
-
-               sh_data->object_empty_image = DRW_shader_create(
-                       datatoc_object_empty_image_vert_glsl, NULL,
-                       datatoc_object_empty_image_frag_glsl,
-                       EMPTY_IMAGE_SHADER_DEFINES);
-
-               sh_data->object_empty_image_wire = DRW_shader_create(
-                       datatoc_object_empty_image_vert_glsl, NULL,
-                       datatoc_object_empty_image_frag_glsl,
-                       EMPTY_IMAGE_SHADER_DEFINES
-                       "#define USE_WIRE\n");
+               {
+                       const char *empty_image_defs = (
+                               "#define DEPTH_UNCHANGED " STRINGIFY(OB_EMPTY_IMAGE_DEPTH_DEFAULT) "\n"
+                               "#define DEPTH_FRONT " STRINGIFY(OB_EMPTY_IMAGE_DEPTH_FRONT) "\n"
+                               "#define DEPTH_BACK " STRINGIFY(OB_EMPTY_IMAGE_DEPTH_BACK) "\n");
 
-#              undef EMPTY_IMAGE_SHADER_DEFINES
+                       sh_data->object_empty_image = DRW_shader_create_from_arrays({
+                               .vert = (const char *[]){world_clip_lib_or_empty, datatoc_object_empty_image_vert_glsl, NULL},
+                               .frag = (const char *[]){datatoc_object_empty_image_frag_glsl, NULL},
+                               .defs = (const char *[]){world_clip_def_or_empty, empty_image_defs, NULL}});
+                       sh_data->object_empty_image_wire = DRW_shader_create_from_arrays({
+                               .vert = (const char *[]){world_clip_lib_or_empty, datatoc_object_empty_image_vert_glsl, NULL},
+                               .frag = (const char *[]){datatoc_object_empty_image_frag_glsl, NULL},
+                               .defs = (const char *[]){world_clip_def_or_empty, "#define USE_WIRE\n", empty_image_defs, NULL}});
+               }
 
                /* Grid */
                sh_data->grid = DRW_shader_create_with_lib(
@@ -924,7 +922,7 @@ static void image_calc_aspect(Image *ima, const int size[2], float r_image_aspec
 
 static void DRW_shgroup_empty_image(
         OBJECT_Shaders *sh_data, OBJECT_ShadingGroupList *sgl,
-        Object *ob, const float color[3], RegionView3D *rv3d)
+        Object *ob, const float color[3], RegionView3D *rv3d, eDRW_ShaderSlot shader_slot)
 {
        /* TODO: 'StereoViews', see draw_empty_image. */
 
@@ -964,6 +962,9 @@ static void DRW_shgroup_empty_image(
                DRW_shgroup_uniform_float(grp, "size", &ob->empty_drawsize, 1);
                DRW_shgroup_uniform_vec2(grp, "offset", ob->ima_ofs, 1);
                DRW_shgroup_uniform_vec4(grp, "objectColor", ob->col, 1);
+               if (shader_slot == DRW_SHADER_SLOT_CLIPPED) {
+                       DRW_shgroup_world_clip_planes_from_rv3d(grp, DRW_context_state_get()->rv3d);
+               }
                DRW_shgroup_call_add(grp, DRW_cache_image_plane_get(), ob->obmat);
        }
 
@@ -976,6 +977,9 @@ static void DRW_shgroup_empty_image(
                DRW_shgroup_uniform_float(grp, "size", &ob->empty_drawsize, 1);
                DRW_shgroup_uniform_vec2(grp, "offset", ob->ima_ofs, 1);
                DRW_shgroup_uniform_vec3(grp, "color", color, 1);
+               if (shader_slot == DRW_SHADER_SLOT_CLIPPED) {
+                       DRW_shgroup_world_clip_planes_from_rv3d(grp, DRW_context_state_get()->rv3d);
+               }
                DRW_shgroup_call_add(grp, DRW_cache_image_plane_wire_get(), ob->obmat);
        }
 }
@@ -1173,61 +1177,61 @@ static void OBJECT_cache_init(void *vedata)
 
                /* Empties */
                geom = DRW_cache_plain_axes_get();
-               sgl->plain_axes = shgroup_instance(sgl->non_meshes, geom);
+               sgl->plain_axes = shgroup_instance(sgl->non_meshes, geom, draw_ctx->shader_slot);
 
                geom = DRW_cache_empty_cube_get();
-               sgl->cube = shgroup_instance(sgl->non_meshes, geom);
+               sgl->cube = shgroup_instance(sgl->non_meshes, geom, draw_ctx->shader_slot);
 
                geom = DRW_cache_circle_get();
-               sgl->circle = shgroup_instance(sgl->non_meshes, geom);
+               sgl->circle = shgroup_instance(sgl->non_meshes, geom, draw_ctx->shader_slot);
 
                geom = DRW_cache_empty_sphere_get();
-               sgl->sphere = shgroup_instance(sgl->non_meshes, geom);
+               sgl->sphere = shgroup_instance(sgl->non_meshes, geom, draw_ctx->shader_slot);
 
                geom = DRW_cache_sphere_get();
                sgl->sphere_solid = shgroup_instance_solid(sgl->non_meshes, geom);
 
                geom = DRW_cache_empty_cylinder_get();
-               sgl->cylinder = shgroup_instance(sgl->non_meshes, geom);
+               sgl->cylinder = shgroup_instance(sgl->non_meshes, geom, draw_ctx->shader_slot);
 
                geom = DRW_cache_empty_capsule_cap_get();
-               sgl->capsule_cap = shgroup_instance(sgl->non_meshes, geom);
+               sgl->capsule_cap = shgroup_instance(sgl->non_meshes, geom, draw_ctx->shader_slot);
 
                geom = DRW_cache_empty_capsule_body_get();
-               sgl->capsule_body = shgroup_instance(sgl->non_meshes, geom);
+               sgl->capsule_body = shgroup_instance(sgl->non_meshes, geom, draw_ctx->shader_slot);
 
                geom = DRW_cache_empty_cone_get();
-               sgl->cone = shgroup_instance(sgl->non_meshes, geom);
+               sgl->cone = shgroup_instance(sgl->non_meshes, geom, draw_ctx->shader_slot);
 
                geom = DRW_cache_single_arrow_get();
-               sgl->single_arrow = shgroup_instance(sgl->non_meshes, geom);
+               sgl->single_arrow = shgroup_instance(sgl->non_meshes, geom, draw_ctx->shader_slot);
 
                geom = DRW_cache_single_line_get();
-               sgl->single_arrow_line = shgroup_instance(sgl->non_meshes, geom);
+               sgl->single_arrow_line = shgroup_instance(sgl->non_meshes, geom, draw_ctx->shader_slot);
 
                geom = DRW_cache_bone_arrows_get();
-               sgl->empty_axes = shgroup_instance_empty_axes(sgl->non_meshes, geom);
+               sgl->empty_axes = shgroup_instance_empty_axes(sgl->non_meshes, geom, draw_ctx->shader_slot);
 
                /* Force Field */
                geom = DRW_cache_field_wind_get();
-               sgl->field_wind = shgroup_instance_scaled(sgl->non_meshes, geom);
+               sgl->field_wind = shgroup_instance_scaled(sgl->non_meshes, geom, draw_ctx->shader_slot);
 
                geom = DRW_cache_field_force_get();
                sgl->field_force = shgroup_instance_screen_aligned(sgl->non_meshes, geom);
 
                geom = DRW_cache_field_vortex_get();
-               sgl->field_vortex = shgroup_instance_scaled(sgl->non_meshes, geom);
+               sgl->field_vortex = shgroup_instance_scaled(sgl->non_meshes, geom, draw_ctx->shader_slot);
 
                geom = DRW_cache_screenspace_circle_get();
                sgl->field_curve_sta = shgroup_instance_screen_aligned(sgl->non_meshes, geom);
 
                /* Grease Pencil */
                geom = DRW_cache_gpencil_axes_get();
-               sgl->gpencil_axes = shgroup_instance(sgl->non_meshes, geom);
+               sgl->gpencil_axes = shgroup_instance(sgl->non_meshes, geom, draw_ctx->shader_slot);
 
                /* Speaker */
                geom = DRW_cache_speaker_get();
-               sgl->speaker = shgroup_instance(sgl->non_meshes, geom);
+               sgl->speaker = shgroup_instance(sgl->non_meshes, geom, draw_ctx->shader_slot);
 
                /* Probe */
                static float probeSize = 14.0f;
@@ -1252,7 +1256,7 @@ static void OBJECT_cache_init(void *vedata)
                sgl->camera_tria = shgroup_camera_instance(sgl->non_meshes, geom, draw_ctx->shader_slot);
 
                geom = DRW_cache_plain_axes_get();
-               sgl->camera_focus = shgroup_instance(sgl->non_meshes, geom);
+               sgl->camera_focus = shgroup_instance(sgl->non_meshes, geom, draw_ctx->shader_slot);
 
                geom = DRW_cache_single_line_get();
                sgl->camera_clip = shgroup_distance_lines_instance(sgl->non_meshes, geom);
@@ -1263,19 +1267,19 @@ static void OBJECT_cache_init(void *vedata)
                sgl->camera_mist_points = shgroup_distance_lines_instance(sgl->non_meshes, geom);
 
                geom = DRW_cache_quad_get();
-               sgl->camera_stereo_plane = shgroup_instance_alpha(sgl->non_meshes, geom);
+               sgl->camera_stereo_plane = shgroup_instance_alpha(sgl->non_meshes, geom, draw_ctx->shader_slot);
 
                geom = DRW_cache_cube_get();
-               sgl->camera_stereo_volume = shgroup_instance_alpha(sgl->non_meshes, geom);
+               sgl->camera_stereo_volume = shgroup_instance_alpha(sgl->non_meshes, geom, draw_ctx->shader_slot);
 
                geom = DRW_cache_empty_cube_get();
-               sgl->camera_stereo_volume_wires = shgroup_instance(sgl->non_meshes, geom);
+               sgl->camera_stereo_volume_wires = shgroup_instance(sgl->non_meshes, geom, draw_ctx->shader_slot);
 
                BLI_listbase_clear(&sgl->camera_path);
 
                /* Texture Space */
                geom = DRW_cache_empty_cube_get();
-               sgl->texspace = shgroup_instance(sgl->non_meshes, geom);
+               sgl->texspace = shgroup_instance(sgl->non_meshes, geom, draw_ctx->shader_slot);
 
                /* Wires (for loose edges) */
                sh = DRW_shader_get_builtin_shader(GPU_SHADER_3D_UNIFORM_COLOR, draw_ctx->shader_slot);
@@ -1332,13 +1336,13 @@ static void OBJECT_cache_init(void *vedata)
                sgl->lamp_area_sphere = shgroup_instance_screen_aligned(sgl->non_meshes, geom);
 
                geom = DRW_cache_lamp_area_square_get();
-               sgl->lamp_area_square = shgroup_instance(sgl->non_meshes, geom);
+               sgl->lamp_area_square = shgroup_instance(sgl->non_meshes, geom, draw_ctx->shader_slot);
 
                geom = DRW_cache_lamp_area_disk_get();
-               sgl->lamp_area_disk = shgroup_instance(sgl->non_meshes, geom);
+               sgl->lamp_area_disk = shgroup_instance(sgl->non_meshes, geom, draw_ctx->shader_slot);
 
                geom = DRW_cache_lamp_hemi_get();
-               sgl->lamp_hemi = shgroup_instance(sgl->non_meshes, geom);
+               sgl->lamp_hemi = shgroup_instance(sgl->non_meshes, geom, draw_ctx->shader_slot);
 
                geom = DRW_cache_single_line_get();
                sgl->lamp_distance = shgroup_distance_lines_instance(sgl->non_meshes, geom);
@@ -1350,13 +1354,13 @@ static void OBJECT_cache_init(void *vedata)
                sgl->lamp_spot_cone = shgroup_spot_instance(sgl->non_meshes, geom);
 
                geom = DRW_cache_circle_get();
-               sgl->lamp_spot_blend = shgroup_instance(sgl->non_meshes, geom);
+               sgl->lamp_spot_blend = shgroup_instance(sgl->non_meshes, geom, draw_ctx->shader_slot);
 
                geom = DRW_cache_lamp_spot_square_get();
-               sgl->lamp_spot_pyramid = shgroup_instance(sgl->non_meshes, geom);
+               sgl->lamp_spot_pyramid = shgroup_instance(sgl->non_meshes, geom, draw_ctx->shader_slot);
 
                geom = DRW_cache_square_get();
-               sgl->lamp_spot_blend_rect = shgroup_instance(sgl->non_meshes, geom);
+               sgl->lamp_spot_blend_rect = shgroup_instance(sgl->non_meshes, geom, draw_ctx->shader_slot);
 
                /* -------- STIPPLES ------- */
 
@@ -1372,29 +1376,29 @@ static void OBJECT_cache_init(void *vedata)
                /* Force Field Limits */
                /* TODO port to shader stipple */
                geom = DRW_cache_field_tube_limit_get();
-               sgl->field_tube_limit = shgroup_instance_scaled(sgl->non_meshes, geom);
+               sgl->field_tube_limit = shgroup_instance_scaled(sgl->non_meshes, geom, draw_ctx->shader_slot);
 
                /* TODO port to shader stipple */
                geom = DRW_cache_field_cone_limit_get();
-               sgl->field_cone_limit = shgroup_instance_scaled(sgl->non_meshes, geom);
+               sgl->field_cone_limit = shgroup_instance_scaled(sgl->non_meshes, geom, draw_ctx->shader_slot);
 
                /* Spot shapes */
                state = DRW_STATE_WRITE_COLOR | DRW_STATE_DEPTH_LESS_EQUAL | DRW_STATE_BLEND | DRW_STATE_CULL_FRONT;
                sgl->spot_shapes = psl->spot_shapes[i] = DRW_pass_create("Spot Shape Pass", state);
 
                geom = DRW_cache_lamp_spot_volume_get();
-               sgl->lamp_spot_volume = shgroup_instance_alpha(sgl->spot_shapes, geom);
+               sgl->lamp_spot_volume = shgroup_instance_alpha(sgl->spot_shapes, geom, draw_ctx->shader_slot);
 
                geom = DRW_cache_lamp_spot_square_volume_get();
-               sgl->lamp_spot_volume_rect = shgroup_instance_alpha(sgl->spot_shapes, geom);
+               sgl->lamp_spot_volume_rect = shgroup_instance_alpha(sgl->spot_shapes, geom, draw_ctx->shader_slot);
 
                geom = DRW_cache_lamp_spot_volume_get();
-               sgl->lamp_spot_volume_outside = shgroup_instance_alpha(sgl->spot_shapes, geom);
+               sgl->lamp_spot_volume_outside = shgroup_instance_alpha(sgl->spot_shapes, geom, draw_ctx->shader_slot);
                DRW_shgroup_state_disable(sgl->lamp_spot_volume_outside, DRW_STATE_CULL_FRONT);
                DRW_shgroup_state_enable(sgl->lamp_spot_volume_outside, DRW_STATE_CULL_BACK);
 
                geom = DRW_cache_lamp_spot_square_volume_get();
-               sgl->lamp_spot_volume_rect_outside = shgroup_instance_alpha(sgl->spot_shapes, geom);
+               sgl->lamp_spot_volume_rect_outside = shgroup_instance_alpha(sgl->spot_shapes, geom, draw_ctx->shader_slot);
                DRW_shgroup_state_disable(sgl->lamp_spot_volume_rect_outside, DRW_STATE_CULL_FRONT);
                DRW_shgroup_state_enable(sgl->lamp_spot_volume_rect_outside, DRW_STATE_CULL_BACK);
        }
@@ -2107,7 +2111,7 @@ static void DRW_shgroup_empty_ex(
 
 static void DRW_shgroup_empty(
         OBJECT_Shaders *sh_data, OBJECT_ShadingGroupList *sgl,
-        Object *ob, ViewLayer *view_layer, RegionView3D *rv3d)
+        Object *ob, ViewLayer *view_layer, RegionView3D *rv3d, eDRW_ShaderSlot shader_slot)
 {
        float *color;
        DRW_object_wire_theme_get(ob, view_layer, &color);
@@ -2123,7 +2127,7 @@ static void DRW_shgroup_empty(
                        DRW_shgroup_empty_ex(sgl, ob->obmat, &ob->empty_drawsize, ob->empty_drawtype, color);
                        break;
                case OB_EMPTY_IMAGE:
-                       DRW_shgroup_empty_image(sh_data, sgl, ob, color, rv3d);
+                       DRW_shgroup_empty_image(sh_data, sgl, ob, color, rv3d, shader_slot);
                        break;
        }
 }
@@ -3041,7 +3045,7 @@ static void OBJECT_cache_populate(void *vedata, Object *ob)
                        if (hide_object_extra) {
                                break;
                        }
-                       DRW_shgroup_empty(sh_data, sgl, ob, view_layer, rv3d);
+                       DRW_shgroup_empty(sh_data, sgl, ob, view_layer, rv3d, draw_ctx->shader_slot);
                        break;
                case OB_GPENCIL:
                        if (hide_object_extra) {
index 10e8805ef55e62a763a047b8f48d2344699b9d6e..d4d7f9be582e92e36e8d3e954a3fe15827793429 100644 (file)
@@ -1,5 +1,7 @@
 
 uniform mat4 ViewProjectionMatrix;
+uniform mat4 ModelMatrix;
+
 uniform vec3 screenVecs[3];
 
 /* ---- Instantiated Attribs ---- */
@@ -23,7 +25,12 @@ void main()
        /* Scale uniformly by axis length */
        spos *= length(chosen_axis) * draw_size;
 
-       gl_Position = ViewProjectionMatrix * vec4(wpos + spos, 1.0);
+       vec4 pos = vec4(wpos + spos, 1.0);
+       gl_Position = ViewProjectionMatrix * pos;
 
        finalColor = vec4(color, 1.0);
+
+#ifdef USE_WORLD_CLIP_PLANES
+       world_clip_planes_calc_clip_distance((ModelMatrix * pos).xyz);
+#endif
 }
index 1c1525696fbe25d704d956004b20c235aea55c34..e5ea42c0661aedaae001537b79c3b1d747542b85 100644 (file)
@@ -1,4 +1,5 @@
 uniform mat4 ModelViewProjectionMatrix;
+uniform mat4 ModelMatrix;
 uniform float aspectX;
 uniform float aspectY;
 uniform float size;
@@ -20,9 +21,8 @@ out vec2 texCoord_interp;
 
 void main()
 {
-       gl_Position = ModelViewProjectionMatrix * vec4(
-               (pos + offset) * (size * vec2(aspectX, aspectY)),
-               0.0, 1.0);
+       vec4 pos_4d = vec4((pos + offset) * (size * vec2(aspectX, aspectY)), 0.0, 1.0);
+       gl_Position = ModelViewProjectionMatrix * pos_4d;
 #ifdef USE_WIRE
        gl_Position.z -= 1e-5;
        finalColor = vec4(color, 1.0);
@@ -30,4 +30,8 @@ void main()
        texCoord_interp = texCoord;
        finalColor = objectColor;
 #endif
+
+#ifdef USE_WORLD_CLIP_PLANES
+       world_clip_planes_calc_clip_distance((ModelMatrix * pos_4d).xyz);
+#endif
 }
index 073283858389d56cb3f31c22eb386a62effc3ef3..9a7815cc9d7ae4f47124436ecb43cc34d02bd177 100644 (file)
@@ -52,6 +52,6 @@ void main()
        finalColor = vec4(color, 1.0);
 
 #ifdef USE_WORLD_CLIP_PLANES
-       world_clip_planes_calc_clip_distance((ModelMatrix * InstanceModelMatrix * vec4(pPos, 1.0)).xyz);
+       world_clip_planes_calc_clip_distance((ModelMatrix * InstanceModelMatrix * vec4(pPos, 1.0)).xyz);
 #endif
 }
index 0d0413fef94c947059eae90225d3b80f21adf60b..fed00389fc14acfb78bf05bdd08815e6d9cf0177 100644 (file)
@@ -1,5 +1,6 @@
 
 uniform mat4 ViewProjectionMatrix;
+uniform mat4 ModelMatrix;
 
 /* ---- Instantiated Attribs ---- */
 in vec3 pos;
@@ -17,6 +18,12 @@ flat out vec4 finalColor;
 
 void main()
 {
-       gl_Position = ViewProjectionMatrix * InstanceModelMatrix * vec4(pos * size, 1.0);
        finalColor = color;
+
+       vec4 pos_4d = vec4(pos * size, 1.0);
+       gl_Position = ViewProjectionMatrix * InstanceModelMatrix * pos_4d;
+
+#ifdef USE_WORLD_CLIP_PLANES
+       world_clip_planes_calc_clip_distance((ModelMatrix * InstanceModelMatrix * pos_4d).xyz);
+#endif
 }