DRW: support clipping for camera objects

This commit is contained in:
2019-01-25 07:13:02 +11:00
parent a4fe338dd8
commit 6d8394d38b
6 changed files with 38 additions and 17 deletions

View File

@@ -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;

View File

@@ -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) {

View File

@@ -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;
}

View File

@@ -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);

View File

@@ -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);

View File

@@ -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
}