Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCampbell Barton <ideasman42@gmail.com>2019-01-29 11:57:35 +0300
committerCampbell Barton <ideasman42@gmail.com>2019-01-29 12:27:28 +0300
commit851d58b34f11f73403729d595116a1b189093821 (patch)
treed625e9c374953cc2630e4292aae3ac62df3f6894 /source/blender/draw
parent68ae1f4958e24906992a3207726c0031de9524b5 (diff)
DRW: support clipping for all lamp types
Diffstat (limited to 'source/blender/draw')
-rw-r--r--source/blender/draw/intern/draw_builtin_shader.c9
-rw-r--r--source/blender/draw/intern/draw_common.c32
-rw-r--r--source/blender/draw/intern/draw_common.h8
-rw-r--r--source/blender/draw/modes/object_mode.c20
-rw-r--r--source/blender/draw/modes/shaders/common_world_clip_lib.glsl2
5 files changed, 42 insertions, 29 deletions
diff --git a/source/blender/draw/intern/draw_builtin_shader.c b/source/blender/draw/intern/draw_builtin_shader.c
index 0b3fc45f5e7..2c3d656da2c 100644
--- a/source/blender/draw/intern/draw_builtin_shader.c
+++ b/source/blender/draw/intern/draw_builtin_shader.c
@@ -50,7 +50,11 @@ extern char datatoc_common_world_clip_lib_glsl[];
GPU_SHADER_3D_POINT_UNIFORM_SIZE_UNIFORM_COLOR_OUTLINE_AA, \
GPU_SHADER_3D_POINT_UNIFORM_SIZE_UNIFORM_COLOR_AA, \
GPU_SHADER_3D_SCREENSPACE_VARIYING_COLOR, \
- GPU_SHADER_3D_INSTANCE_SCREEN_ALIGNED)
+ GPU_SHADER_3D_INSTANCE_SCREEN_ALIGNED, \
+ GPU_SHADER_3D_GROUNDLINE, \
+ GPU_SHADER_3D_GROUNDPOINT, \
+ GPU_SHADER_DISTANCE_LINES, \
+ GPU_SHADER_INSTANCE_EDGES_VARIYING_COLOR)
/* cache of built-in shaders (each is created on first use) */
static struct {
@@ -70,9 +74,10 @@ static GPUShader *drw_shader_get_builtin_shader_clipped(eGPUBuiltinShader shader
&shader_code.geom,
&shader_code.defs);
+ /* In rare cases geometry shaders calculate clipping themselves. */
return DRW_shader_create_from_arrays({
.vert = (const char *[]){world_clip_lib, shader_code.vert, NULL},
- .geom = (const char *[]){shader_code.geom, NULL},
+ .geom = (const char *[]){shader_code.geom ? world_clip_lib : NULL, shader_code.geom, NULL},
.frag = (const char *[]){shader_code.frag, NULL},
.defs = (const char *[]){world_clip_def, shader_code.defs, NULL}});
}
diff --git a/source/blender/draw/intern/draw_common.c b/source/blender/draw/intern/draw_common.c
index 28bd39e9090..676c401cf44 100644
--- a/source/blender/draw/intern/draw_common.c
+++ b/source/blender/draw/intern/draw_common.c
@@ -358,24 +358,28 @@ DRWShadingGroup *shgroup_dynpoints_uniform_color(
return grp;
}
-DRWShadingGroup *shgroup_groundlines_uniform_color(DRWPass *pass, const float color[4])
+DRWShadingGroup *shgroup_groundlines_uniform_color(DRWPass *pass, const float color[4], eDRW_ShaderSlot shader_slot)
{
- GPUShader *sh = GPU_shader_get_builtin_shader(GPU_SHADER_3D_GROUNDLINE);
+ GPUShader *sh = DRW_shader_get_builtin_shader(GPU_SHADER_3D_GROUNDLINE, shader_slot);
DRWShadingGroup *grp = DRW_shgroup_point_batch_create(sh, pass);
DRW_shgroup_uniform_vec4(grp, "color", color, 1);
-
+ if (shader_slot == DRW_SHADER_SLOT_CLIPPED) {
+ DRW_shgroup_world_clip_planes_from_rv3d(grp, DRW_context_state_get()->rv3d);
+ }
return grp;
}
-DRWShadingGroup *shgroup_groundpoints_uniform_color(DRWPass *pass, const float color[4])
+DRWShadingGroup *shgroup_groundpoints_uniform_color(DRWPass *pass, const float color[4], eDRW_ShaderSlot shader_slot)
{
- GPUShader *sh = GPU_shader_get_builtin_shader(GPU_SHADER_3D_GROUNDPOINT);
+ GPUShader *sh = DRW_shader_get_builtin_shader(GPU_SHADER_3D_GROUNDPOINT, shader_slot);
DRWShadingGroup *grp = DRW_shgroup_point_batch_create(sh, pass);
DRW_shgroup_uniform_vec4(grp, "color", color, 1);
DRW_shgroup_state_enable(grp, DRW_STATE_POINT);
-
+ if (shader_slot == DRW_SHADER_SLOT_CLIPPED) {
+ DRW_shgroup_world_clip_planes_from_rv3d(grp, DRW_context_state_get()->rv3d);
+ }
return grp;
}
@@ -561,9 +565,9 @@ DRWShadingGroup *shgroup_camera_instance(DRWPass *pass, struct GPUBatch *geom, e
return grp;
}
-DRWShadingGroup *shgroup_distance_lines_instance(DRWPass *pass, struct GPUBatch *geom)
+DRWShadingGroup *shgroup_distance_lines_instance(DRWPass *pass, struct GPUBatch *geom, eDRW_ShaderSlot shader_slot)
{
- GPUShader *sh_inst = GPU_shader_get_builtin_shader(GPU_SHADER_DISTANCE_LINES);
+ GPUShader *sh_inst = DRW_shader_get_builtin_shader(GPU_SHADER_DISTANCE_LINES, shader_slot);
static float point_size = 4.0f;
DRW_shgroup_instance_format(g_formats.instance_distance_lines, {
@@ -575,13 +579,15 @@ DRWShadingGroup *shgroup_distance_lines_instance(DRWPass *pass, struct GPUBatch
DRWShadingGroup *grp = DRW_shgroup_instance_create(sh_inst, pass, geom, g_formats.instance_distance_lines);
DRW_shgroup_uniform_float(grp, "size", &point_size, 1);
-
+ if (shader_slot == DRW_SHADER_SLOT_CLIPPED) {
+ DRW_shgroup_world_clip_planes_from_rv3d(grp, DRW_context_state_get()->rv3d);
+ }
return grp;
}
-DRWShadingGroup *shgroup_spot_instance(DRWPass *pass, struct GPUBatch *geom)
+DRWShadingGroup *shgroup_spot_instance(DRWPass *pass, struct GPUBatch *geom, eDRW_ShaderSlot shader_slot)
{
- GPUShader *sh_inst = GPU_shader_get_builtin_shader(GPU_SHADER_INSTANCE_EDGES_VARIYING_COLOR);
+ GPUShader *sh_inst = DRW_shader_get_builtin_shader(GPU_SHADER_INSTANCE_EDGES_VARIYING_COLOR, shader_slot);
static const int True = true;
static const int False = false;
@@ -594,7 +600,9 @@ DRWShadingGroup *shgroup_spot_instance(DRWPass *pass, struct GPUBatch *geom)
DRW_shgroup_uniform_bool(grp, "drawFront", &False, 1);
DRW_shgroup_uniform_bool(grp, "drawBack", &False, 1);
DRW_shgroup_uniform_bool(grp, "drawSilhouette", &True, 1);
-
+ 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 39a895632bd..dffe4f2ebc9 100644
--- a/source/blender/draw/intern/draw_common.h
+++ b/source/blender/draw/intern/draw_common.h
@@ -143,8 +143,8 @@ void DRW_shgroup_world_clip_planes_from_rv3d(struct DRWShadingGroup *shgrp, cons
struct DRWShadingGroup *shgroup_dynlines_flat_color(struct DRWPass *pass);
struct DRWShadingGroup *shgroup_dynlines_dashed_uniform_color(struct DRWPass *pass, const float color[4]);
struct DRWShadingGroup *shgroup_dynpoints_uniform_color(struct DRWPass *pass, const float color[4], const float *size, eDRW_ShaderSlot shader_slot);
-struct DRWShadingGroup *shgroup_groundlines_uniform_color(struct DRWPass *pass, const float color[4]);
-struct DRWShadingGroup *shgroup_groundpoints_uniform_color(struct DRWPass *pass, const float color[4]);
+struct DRWShadingGroup *shgroup_groundlines_uniform_color(struct DRWPass *pass, const float color[4], eDRW_ShaderSlot shader_slot);
+struct DRWShadingGroup *shgroup_groundpoints_uniform_color(struct DRWPass *pass, const float color[4], eDRW_ShaderSlot shader_slot);
struct DRWShadingGroup *shgroup_instance_screenspace(struct DRWPass *pass, struct GPUBatch *geom, const float *size, eDRW_ShaderSlot shader_slot);
struct DRWShadingGroup *shgroup_instance_solid(struct DRWPass *pass, struct GPUBatch *geom);
struct DRWShadingGroup *shgroup_instance_wire(struct DRWPass *pass, struct GPUBatch *geom);
@@ -155,8 +155,8 @@ struct DRWShadingGroup *shgroup_instance(struct DRWPass *pass, struct GPUBatch *
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);
-struct DRWShadingGroup *shgroup_spot_instance(struct DRWPass *pass, struct GPUBatch *geom);
+struct DRWShadingGroup *shgroup_distance_lines_instance(struct DRWPass *pass, struct GPUBatch *geom, eDRW_ShaderSlot shader_slot);
+struct DRWShadingGroup *shgroup_spot_instance(struct DRWPass *pass, struct GPUBatch *geom, eDRW_ShaderSlot shader_slot);
struct DRWShadingGroup *shgroup_instance_mball_handles(struct DRWPass *pass);
struct DRWShadingGroup *shgroup_instance_bone_axes(struct DRWPass *pass);
struct DRWShadingGroup *shgroup_instance_bone_envelope_distance(struct DRWPass *pass);
diff --git a/source/blender/draw/modes/object_mode.c b/source/blender/draw/modes/object_mode.c
index ed047b93f9f..a64d7f288ca 100644
--- a/source/blender/draw/modes/object_mode.c
+++ b/source/blender/draw/modes/object_mode.c
@@ -1252,12 +1252,12 @@ static void OBJECT_cache_init(void *vedata)
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);
- sgl->camera_mist = shgroup_distance_lines_instance(sgl->non_meshes, geom);
+ sgl->camera_clip = shgroup_distance_lines_instance(sgl->non_meshes, geom, draw_ctx->shader_slot);
+ sgl->camera_mist = shgroup_distance_lines_instance(sgl->non_meshes, geom, draw_ctx->shader_slot);
geom = DRW_cache_single_line_endpoints_get();
- sgl->camera_clip_points = shgroup_distance_lines_instance(sgl->non_meshes, geom);
- sgl->camera_mist_points = shgroup_distance_lines_instance(sgl->non_meshes, geom);
+ sgl->camera_clip_points = shgroup_distance_lines_instance(sgl->non_meshes, geom, draw_ctx->shader_slot);
+ sgl->camera_mist_points = shgroup_distance_lines_instance(sgl->non_meshes, geom, draw_ctx->shader_slot);
geom = DRW_cache_quad_get();
sgl->camera_stereo_plane = shgroup_instance_alpha(sgl->non_meshes, geom, draw_ctx->shader_slot);
@@ -1310,7 +1310,7 @@ static void OBJECT_cache_init(void *vedata)
/* start with buflimit because we don't want stipples */
geom = DRW_cache_single_line_get();
- sgl->lamp_buflimit = shgroup_distance_lines_instance(sgl->non_meshes, geom);
+ sgl->lamp_buflimit = shgroup_distance_lines_instance(sgl->non_meshes, geom, draw_ctx->shader_slot);
sgl->lamp_center = shgroup_dynpoints_uniform_color(sgl->non_meshes, gb->colorLampNoAlpha, &gb->sizeLampCenter, draw_ctx->shader_slot);
@@ -1322,8 +1322,8 @@ static void OBJECT_cache_init(void *vedata)
geom = DRW_cache_lamp_sunrays_get();
sgl->lamp_sunrays = shgroup_instance_screenspace(sgl->non_meshes, geom, &gb->sizeLampCircle, draw_ctx->shader_slot);
- sgl->lamp_groundline = shgroup_groundlines_uniform_color(sgl->non_meshes, gb->colorLamp);
- sgl->lamp_groundpoint = shgroup_groundpoints_uniform_color(sgl->non_meshes, gb->colorLamp);
+ sgl->lamp_groundline = shgroup_groundlines_uniform_color(sgl->non_meshes, gb->colorLamp, draw_ctx->shader_slot);
+ sgl->lamp_groundpoint = shgroup_groundpoints_uniform_color(sgl->non_meshes, gb->colorLamp, draw_ctx->shader_slot);
geom = DRW_cache_screenspace_circle_get();
sgl->lamp_area_sphere = shgroup_instance_screen_aligned(sgl->non_meshes, geom, draw_ctx->shader_slot);
@@ -1338,13 +1338,13 @@ static void OBJECT_cache_init(void *vedata)
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);
+ sgl->lamp_distance = shgroup_distance_lines_instance(sgl->non_meshes, geom, draw_ctx->shader_slot);
geom = DRW_cache_single_line_endpoints_get();
- sgl->lamp_buflimit_points = shgroup_distance_lines_instance(sgl->non_meshes, geom);
+ sgl->lamp_buflimit_points = shgroup_distance_lines_instance(sgl->non_meshes, geom, draw_ctx->shader_slot);
geom = DRW_cache_lamp_spot_get();
- sgl->lamp_spot_cone = shgroup_spot_instance(sgl->non_meshes, geom);
+ sgl->lamp_spot_cone = shgroup_spot_instance(sgl->non_meshes, geom, draw_ctx->shader_slot);
geom = DRW_cache_circle_get();
sgl->lamp_spot_blend = shgroup_instance(sgl->non_meshes, geom, draw_ctx->shader_slot);
diff --git a/source/blender/draw/modes/shaders/common_world_clip_lib.glsl b/source/blender/draw/modes/shaders/common_world_clip_lib.glsl
index b889780751e..6964b2a0c39 100644
--- a/source/blender/draw/modes/shaders/common_world_clip_lib.glsl
+++ b/source/blender/draw/modes/shaders/common_world_clip_lib.glsl
@@ -1,5 +1,5 @@
#ifdef USE_WORLD_CLIP_PLANES
-#ifdef GPU_VERTEX_SHADER
+#if defined(GPU_VERTEX_SHADER) || defined(GPU_GEOMETRY_SHADER)
uniform vec4 WorldClipPlanes[6];
void world_clip_planes_calc_clip_distance(vec3 wpos)
{