diff options
Diffstat (limited to 'source')
-rw-r--r-- | source/blender/draw/intern/DRW_render.h | 10 | ||||
-rw-r--r-- | source/blender/draw/intern/draw_builtin_shader.c | 11 | ||||
-rw-r--r-- | source/blender/draw/intern/draw_common.c | 9 | ||||
-rw-r--r-- | source/blender/draw/intern/draw_common.h | 12 | ||||
-rw-r--r-- | source/blender/draw/modes/object_mode.c | 6 | ||||
-rw-r--r-- | source/blender/gpu/shaders/gpu_shader_instance_camera_vert.glsl | 7 |
6 files changed, 38 insertions, 17 deletions
diff --git a/source/blender/draw/intern/DRW_render.h b/source/blender/draw/intern/DRW_render.h index 395d9483deb..884b35c4acb 100644 --- a/source/blender/draw/intern/DRW_render.h +++ b/source/blender/draw/intern/DRW_render.h @@ -94,16 +94,6 @@ typedef struct BoundSphere { float center[3], radius; } BoundSphere; -/** - * Support selecting shaders with different options compiled in. - * Needed for clipping support because it means using a separate set of shaders. - */ -typedef enum eDRW_ShaderSlot { - DRW_SHADER_SLOT_DEFAULT = 0, - DRW_SHADER_SLOT_CLIPPED = 1, -} eDRW_ShaderSlot; -#define DRW_SHADER_SLOT_LEN 2 - /* declare members as empty (unused) */ typedef char DRWViewportEmptyList; diff --git a/source/blender/draw/intern/draw_builtin_shader.c b/source/blender/draw/intern/draw_builtin_shader.c index 5c0c005cb9d..6a70b91d67a 100644 --- a/source/blender/draw/intern/draw_builtin_shader.c +++ b/source/blender/draw/intern/draw_builtin_shader.c @@ -44,6 +44,8 @@ extern char datatoc_drw_shader_3D_smooth_color_vert_glsl[]; extern char datatoc_gpu_shader_uniform_color_frag_glsl[]; extern char datatoc_gpu_shader_3D_smooth_color_frag_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[]; /* cache of built-in shaders (each is created on first use) */ static struct { @@ -88,6 +90,15 @@ static GPUShader *drw_shader_get_builtin_shader_clipped(eGPUBuiltinShader shader .frag = (const char *[]){datatoc_gpu_shader_depth_only_frag_glsl, NULL}, .defs = (const char *[]){world_clip_def, NULL}}); break; + case GPU_SHADER_CAMERA: + if (r_test_only) { + break; + } + shader = DRW_shader_create_from_arrays({ + .vert = (const char *[]){world_clip_lib, datatoc_gpu_shader_instance_camera_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) { diff --git a/source/blender/draw/intern/draw_common.c b/source/blender/draw/intern/draw_common.c index 437e6f63095..e7a129071b6 100644 --- a/source/blender/draw/intern/draw_common.c +++ b/source/blender/draw/intern/draw_common.c @@ -38,6 +38,7 @@ #include "BKE_colorband.h" #include "draw_common.h" +#include "draw_builtin_shader.h" #if 0 #define UI_COLOR_RGB_FROM_U8(r, g, b, v4) \ @@ -515,9 +516,9 @@ DRWShadingGroup *shgroup_instance_outline(DRWPass *pass, struct GPUBatch *geom, return grp; } -DRWShadingGroup *shgroup_camera_instance(DRWPass *pass, struct GPUBatch *geom) +DRWShadingGroup *shgroup_camera_instance(DRWPass *pass, struct GPUBatch *geom, eDRW_ShaderSlot shader_slot) { - GPUShader *sh_inst = GPU_shader_get_builtin_shader(GPU_SHADER_CAMERA); + GPUShader *sh_inst = DRW_shader_get_builtin_shader(GPU_SHADER_CAMERA, shader_slot); DRW_shgroup_instance_format(g_formats.instance_camera, { {"color", DRW_ATTRIB_FLOAT, 3}, @@ -528,7 +529,9 @@ DRWShadingGroup *shgroup_camera_instance(DRWPass *pass, struct GPUBatch *geom) }); DRWShadingGroup *grp = DRW_shgroup_instance_create(sh_inst, pass, geom, g_formats.instance_camera); - + if (shader_slot == DRW_SHADER_SLOT_CLIPPED) { + DRW_shgroup_world_clip_planes_from_rv3d(grp, DRW_context_state_get()->rv3d); + } return grp; } diff --git a/source/blender/draw/intern/draw_common.h b/source/blender/draw/intern/draw_common.h index 854a8abbea9..2190db8bf31 100644 --- a/source/blender/draw/intern/draw_common.h +++ b/source/blender/draw/intern/draw_common.h @@ -39,6 +39,16 @@ struct ModifierData; struct ParticleSystem; struct PTCacheEdit; +/** + * Support selecting shaders with different options compiled in. + * Needed for clipping support because it means using a separate set of shaders. + */ +typedef enum eDRW_ShaderSlot { + DRW_SHADER_SLOT_DEFAULT = 0, + DRW_SHADER_SLOT_CLIPPED = 1, +} eDRW_ShaderSlot; +#define DRW_SHADER_SLOT_LEN 2 + #define UBO_FIRST_COLOR colorWire #define UBO_LAST_COLOR colorGridAxisZ @@ -144,7 +154,7 @@ struct DRWShadingGroup *shgroup_instance_scaled(struct DRWPass *pass, struct GPU 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_outline(struct DRWPass *pass, struct GPUBatch *geom, int *baseid); -struct DRWShadingGroup *shgroup_camera_instance(struct DRWPass *pass, struct GPUBatch *geom); +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); struct DRWShadingGroup *shgroup_spot_instance(struct DRWPass *pass, struct GPUBatch *geom); struct DRWShadingGroup *shgroup_instance_mball_handles(struct DRWPass *pass); diff --git a/source/blender/draw/modes/object_mode.c b/source/blender/draw/modes/object_mode.c index 0757403ad01..52a173e433f 100644 --- a/source/blender/draw/modes/object_mode.c +++ b/source/blender/draw/modes/object_mode.c @@ -1243,13 +1243,13 @@ static void OBJECT_cache_init(void *vedata) /* Camera */ geom = DRW_cache_camera_get(); - sgl->camera = shgroup_camera_instance(sgl->non_meshes, geom); + sgl->camera = shgroup_camera_instance(sgl->non_meshes, geom, draw_ctx->shader_slot); geom = DRW_cache_camera_frame_get(); - sgl->camera_frame = shgroup_camera_instance(sgl->non_meshes, geom); + sgl->camera_frame = shgroup_camera_instance(sgl->non_meshes, geom, draw_ctx->shader_slot); geom = DRW_cache_camera_tria_get(); - sgl->camera_tria = shgroup_camera_instance(sgl->non_meshes, geom); + 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); diff --git a/source/blender/gpu/shaders/gpu_shader_instance_camera_vert.glsl b/source/blender/gpu/shaders/gpu_shader_instance_camera_vert.glsl index 805ecd6085f..07328385838 100644 --- a/source/blender/gpu/shaders/gpu_shader_instance_camera_vert.glsl +++ b/source/blender/gpu/shaders/gpu_shader_instance_camera_vert.glsl @@ -1,5 +1,8 @@ uniform mat4 ViewProjectionMatrix; +#ifdef USE_WORLD_CLIP_PLANES +uniform mat4 ModelMatrix; +#endif /* ---- Instantiated Attribs ---- */ in float pos; @@ -47,4 +50,8 @@ void main() gl_Position = ViewProjectionMatrix * InstanceModelMatrix * vec4(pPos, 1.0); finalColor = vec4(color, 1.0); + +#ifdef USE_WORLD_CLIP_PLANES + world_clip_planes_calc_clip_distance((ModelMatrix * InstanceModelMatrix * vec4(pPos, 1.0)).xyz); +#endif } |