[Bf-blender-cvs] [890623f8865] blender2.8: Object Mode: Add back spot cone display
Clément Foucault
noreply at git.blender.org
Wed Aug 22 19:49:40 CEST 2018
Commit: 890623f8865a87a9c1a1c78561acfea2a5e43eb1
Author: Clément Foucault
Date: Wed Aug 22 18:44:24 2018 +0200
Branches: blender2.8
https://developer.blender.org/rB890623f8865a87a9c1a1c78561acfea2a5e43eb1
Object Mode: Add back spot cone display
===================================================================
M source/blender/draw/intern/draw_cache.c
M source/blender/draw/intern/draw_cache.h
M source/blender/draw/intern/draw_common.c
M source/blender/draw/intern/draw_common.h
M source/blender/draw/intern/draw_debug.c
M source/blender/draw/modes/object_mode.c
M source/blender/gpu/shaders/gpu_shader_instance_variying_size_variying_color_vert.glsl
===================================================================
diff --git a/source/blender/draw/intern/draw_cache.c b/source/blender/draw/intern/draw_cache.c
index 831c9ea33b9..412ad72207e 100644
--- a/source/blender/draw/intern/draw_cache.c
+++ b/source/blender/draw/intern/draw_cache.c
@@ -84,7 +84,9 @@ static struct DRWShapeCache {
GPUBatch *drw_lamp_area_disk;
GPUBatch *drw_lamp_hemi;
GPUBatch *drw_lamp_spot;
+ GPUBatch *drw_lamp_spot_volume;
GPUBatch *drw_lamp_spot_square;
+ GPUBatch *drw_lamp_spot_square_volume;
GPUBatch *drw_speaker;
GPUBatch *drw_lightprobe_cube;
GPUBatch *drw_lightprobe_planar;
@@ -1491,7 +1493,6 @@ GPUBatch *DRW_cache_lamp_spot_get(void)
negate_v3_v3(neg[i], n[i]);
}
- /* Position Only 3D format */
static GPUVertFormat format = { 0 };
static struct { uint pos, n1, n2; } attr_id;
if (format.attr_len == 0) {
@@ -1539,6 +1540,51 @@ GPUBatch *DRW_cache_lamp_spot_get(void)
#undef NSEGMENTS
}
+GPUBatch *DRW_cache_lamp_spot_volume_get(void)
+{
+#define NSEGMENTS 32
+ if (!SHC.drw_lamp_spot_volume) {
+ /* a single ring of vertices */
+ float p[NSEGMENTS][2];
+ for (int i = 0; i < NSEGMENTS; ++i) {
+ float angle = 2 * M_PI * ((float)i / (float)NSEGMENTS);
+ p[i][0] = cosf(angle);
+ p[i][1] = sinf(angle);
+ }
+
+ static GPUVertFormat format = { 0 };
+ static struct { uint pos; } attr_id;
+ if (format.attr_len == 0) {
+ attr_id.pos = GPU_vertformat_attr_add(&format, "pos", GPU_COMP_F32, 3, GPU_FETCH_FLOAT);
+ }
+
+ GPUVertBuf *vbo = GPU_vertbuf_create_with_format(&format);
+ GPU_vertbuf_data_alloc(vbo, NSEGMENTS * 3);
+
+ uint v_idx = 0;
+ for (int i = 0; i < NSEGMENTS; ++i) {
+ float cv[2], v[3];
+
+ ARRAY_SET_ITEMS(v, 0.0f, 0.0f, 0.0f);
+ GPU_vertbuf_attr_set(vbo, attr_id.pos, v_idx++, v);
+
+ cv[0] = p[i % NSEGMENTS][0];
+ cv[1] = p[i % NSEGMENTS][1];
+ ARRAY_SET_ITEMS(v, cv[0], cv[1], -1.0f);
+ GPU_vertbuf_attr_set(vbo, attr_id.pos, v_idx++, v);
+
+ cv[0] = p[(i + 1) % NSEGMENTS][0];
+ cv[1] = p[(i + 1) % NSEGMENTS][1];
+ ARRAY_SET_ITEMS(v, cv[0], cv[1], -1.0f);
+ GPU_vertbuf_attr_set(vbo, attr_id.pos, v_idx++, v);
+ }
+
+ SHC.drw_lamp_spot_volume = GPU_batch_create_ex(GPU_PRIM_TRIS, vbo, NULL, GPU_BATCH_OWNS_VBO);
+ }
+ return SHC.drw_lamp_spot_volume;
+#undef NSEGMENTS
+}
+
GPUBatch *DRW_cache_lamp_spot_square_get(void)
{
if (!SHC.drw_lamp_spot_square) {
@@ -1574,6 +1620,39 @@ GPUBatch *DRW_cache_lamp_spot_square_get(void)
return SHC.drw_lamp_spot_square;
}
+GPUBatch *DRW_cache_lamp_spot_square_volume_get(void)
+{
+ if (!SHC.drw_lamp_spot_square_volume) {
+ float p[5][3] = {{ 0.0f, 0.0f, 0.0f},
+ { 1.0f, 1.0f, -1.0f},
+ { 1.0f, -1.0f, -1.0f},
+ {-1.0f, -1.0f, -1.0f},
+ {-1.0f, 1.0f, -1.0f}};
+
+ uint v_idx = 0;
+
+ /* Position Only 3D format */
+ static GPUVertFormat format = { 0 };
+ static struct { uint pos; } attr_id;
+ if (format.attr_len == 0) {
+ attr_id.pos = GPU_vertformat_attr_add(&format, "pos", GPU_COMP_F32, 3, GPU_FETCH_FLOAT);
+ }
+
+ GPUVertBuf *vbo = GPU_vertbuf_create_with_format(&format);
+ GPU_vertbuf_data_alloc(vbo, 12);
+
+ /* piramid sides */
+ for (int i = 1; i <= 4; ++i) {
+ GPU_vertbuf_attr_set(vbo, attr_id.pos, v_idx++, p[0]);
+ GPU_vertbuf_attr_set(vbo, attr_id.pos, v_idx++, p[((i + 1) % 4) + 1]);
+ GPU_vertbuf_attr_set(vbo, attr_id.pos, v_idx++, p[(i % 4) + 1]);
+ }
+
+ SHC.drw_lamp_spot_square_volume = GPU_batch_create_ex(GPU_PRIM_TRIS, vbo, NULL, GPU_BATCH_OWNS_VBO);
+ }
+ return SHC.drw_lamp_spot_square_volume;
+}
+
/** \} */
/* -------------------------------------------------------------------- */
diff --git a/source/blender/draw/intern/draw_cache.h b/source/blender/draw/intern/draw_cache.h
index f5f4527ca13..eb75c685ec0 100644
--- a/source/blender/draw/intern/draw_cache.h
+++ b/source/blender/draw/intern/draw_cache.h
@@ -91,7 +91,9 @@ struct GPUBatch *DRW_cache_lamp_area_square_get(void);
struct GPUBatch *DRW_cache_lamp_area_disk_get(void);
struct GPUBatch *DRW_cache_lamp_hemi_get(void);
struct GPUBatch *DRW_cache_lamp_spot_get(void);
+struct GPUBatch *DRW_cache_lamp_spot_volume_get(void);
struct GPUBatch *DRW_cache_lamp_spot_square_get(void);
+struct GPUBatch *DRW_cache_lamp_spot_square_volume_get(void);
/* Camera */
struct GPUBatch *DRW_cache_camera_get(void);
diff --git a/source/blender/draw/intern/draw_common.c b/source/blender/draw/intern/draw_common.c
index bfcf5f2511d..30b1ebe07cd 100644
--- a/source/blender/draw/intern/draw_common.c
+++ b/source/blender/draw/intern/draw_common.c
@@ -396,6 +396,23 @@ DRWShadingGroup *shgroup_instance(DRWPass *pass, struct GPUBatch *geom)
});
DRWShadingGroup *grp = DRW_shgroup_instance_create(sh_inst, pass, geom, g_formats.instance_sized);
+ DRW_shgroup_uniform_float_copy(grp, "alpha", 1.0f);
+
+ return grp;
+}
+
+DRWShadingGroup *shgroup_instance_alpha(DRWPass *pass, struct GPUBatch *geom, float alpha)
+{
+ GPUShader *sh_inst = GPU_shader_get_builtin_shader(GPU_SHADER_INSTANCE_VARIYING_COLOR_VARIYING_SIZE);
+
+ DRW_shgroup_instance_format(g_formats.instance_sized, {
+ {"color", DRW_ATTRIB_FLOAT, 4},
+ {"size", DRW_ATTRIB_FLOAT, 1},
+ {"InstanceModelMatrix", DRW_ATTRIB_FLOAT, 16}
+ });
+
+ DRWShadingGroup *grp = DRW_shgroup_instance_create(sh_inst, pass, geom, g_formats.instance_sized);
+ DRW_shgroup_uniform_float_copy(grp, "alpha", alpha);
return grp;
}
diff --git a/source/blender/draw/intern/draw_common.h b/source/blender/draw/intern/draw_common.h
index 05c3da9f96c..bab6c67a081 100644
--- a/source/blender/draw/intern/draw_common.h
+++ b/source/blender/draw/intern/draw_common.h
@@ -120,6 +120,7 @@ struct DRWShadingGroup *shgroup_instance_empty_axes(struct DRWPass *pass, struct
struct DRWShadingGroup *shgroup_instance_image_plane(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, float alpha);
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_distance_lines_instance(struct DRWPass *pass, struct GPUBatch *geom);
diff --git a/source/blender/draw/intern/draw_debug.c b/source/blender/draw/intern/draw_debug.c
index 8af13d66c28..c748b8fb0d8 100644
--- a/source/blender/draw/intern/draw_debug.c
+++ b/source/blender/draw/intern/draw_debug.c
@@ -208,6 +208,7 @@ static void drw_debug_draw_spheres(void)
GPUBatch *draw_batch = GPU_batch_create(GPU_PRIM_LINES, empty_sphere->verts[0], NULL);
GPU_batch_instbuf_set(draw_batch, inst_vbo, true);
GPU_batch_program_set_builtin(draw_batch, GPU_SHADER_INSTANCE_VARIYING_COLOR_VARIYING_SIZE);
+ GPU_batch_uniform_1f(draw_batch, "alpha", 1.0f);
GPU_batch_draw(draw_batch);
GPU_batch_discard(draw_batch);
diff --git a/source/blender/draw/modes/object_mode.c b/source/blender/draw/modes/object_mode.c
index af85cc7bb00..934b9ada99f 100644
--- a/source/blender/draw/modes/object_mode.c
+++ b/source/blender/draw/modes/object_mode.c
@@ -106,6 +106,7 @@ extern char datatoc_gpu_shader_uniform_color_frag_glsl[];
/* *********** LISTS *********** */
typedef struct OBJECT_PassList {
struct DRWPass *non_meshes[2];
+ struct DRWPass *spot_shapes[2];
struct DRWPass *ob_center;
struct DRWPass *outlines;
struct DRWPass *outlines_search;
@@ -146,6 +147,7 @@ typedef struct OBJECT_Data {
typedef struct OBJECT_ShadingGroupList {
/* Reference only */
struct DRWPass *non_meshes;
+ struct DRWPass *spot_shapes;
struct DRWPass *bone_solid;
struct DRWPass *bone_outline;
struct DRWPass *bone_wire;
@@ -209,6 +211,10 @@ typedef struct OBJECT_ShadingGroupList {
DRWShadingGroup *lamp_spot_blend;
DRWShadingGroup *lamp_spot_pyramid;
DRWShadingGroup *lamp_spot_blend_rect;
+ DRWShadingGroup *lamp_spot_volume;
+ DRWShadingGroup *lamp_spot_volume_rect;
+ DRWShadingGroup *lamp_spot_volume_outside;
+ DRWShadingGroup *lamp_spot_volume_rect_outside;
/* Helpers */
DRWShadingGroup *relationship_lines;
@@ -1100,8 +1106,7 @@ static void OBJECT_cache_init(void *vedata)
DRWState state =
DRW_STATE_WRITE_COLOR | DRW_STATE_WRITE_DEPTH |
- DRW_STATE_DEPTH_LESS_EQUAL | DRW_STATE_BLEND | DRW_STATE_POINT;
- state |= DRW_STATE_WIRE;
+ DRW_STATE_DEPTH_LESS_EQUAL | DRW_STATE_BLEND | DRW_STATE_POINT | DRW_STATE_WIRE;
sgl->non_meshes = psl->non_meshes[i] = DRW_pass_create("Non Meshes Pass", state);
/* Empties */
@@ -1292,6 +1297,28 @@ static void OBJECT_cache_init(void *vedata)
/* TODO port to shader stipple */
geom = DRW_cache_field_cone_limit_get();
sgl->field_cone_limit = shgroup_instance_scaled(sgl->non_meshes, geom);
+
+ /* 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);
+ float cone_spot_alpha = 0.5f;
+
+ geom = DRW_cache_lamp_spot_volume_get();
+ sgl->lamp_spot_volume = shgroup_instance_alpha(sgl->spot_shapes, geom, cone_spot_alpha);
+
+ geom = DRW_cache_lamp_spot_square_volume_get();
+ sgl->lamp_spot_volume_rect = shgroup_instance_alpha(sgl->spot_shapes, geom, cone_spot_alpha);
+
+ cone_spot_alpha = 0.3f;
+ geom = DRW_cache_lamp_spot_volume_get();
+ sgl->lamp_spot_volume_outside = shgroup_instance_alpha(sgl->spot_shapes, geom, cone_spot_alpha);
+ 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, cone_spot_alpha);
+ 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);
}
{
@@ -1429,8 +1456,9 @@ static void DRW_shgroup_lamp(OBJECT_Sh
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list