Overlay Engine: Outline: Simplify drawing code
Use obinfo ubo to compute outline color id. Note this commit removes the planar probe outline on purpose.
This commit is contained in:
parent
6d3eb85f66
commit
a77fe7eb5c
|
@ -22,6 +22,8 @@
|
|||
|
||||
#include "DRW_render.h"
|
||||
|
||||
#include "BKE_global.h"
|
||||
|
||||
#include "DNA_lightprobe_types.h"
|
||||
|
||||
#include "UI_resources.h"
|
||||
|
@ -58,77 +60,6 @@ void OVERLAY_outline_init(OVERLAY_Data *vedata)
|
|||
}
|
||||
}
|
||||
|
||||
static int shgroup_theme_id_to_outline_id(int theme_id, const int base_flag)
|
||||
{
|
||||
if (UNLIKELY(base_flag & BASE_FROM_DUPLI)) {
|
||||
switch (theme_id) {
|
||||
case TH_ACTIVE:
|
||||
case TH_SELECT:
|
||||
return 2;
|
||||
case TH_TRANSFORM:
|
||||
return 0;
|
||||
default:
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
switch (theme_id) {
|
||||
case TH_ACTIVE:
|
||||
return 3;
|
||||
case TH_SELECT:
|
||||
return 1;
|
||||
case TH_TRANSFORM:
|
||||
return 0;
|
||||
default:
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
static DRWShadingGroup *shgroup_theme_id_to_outline_or_null(OVERLAY_PrivateData *pd,
|
||||
int theme_id,
|
||||
const int base_flag)
|
||||
{
|
||||
int outline_id = shgroup_theme_id_to_outline_id(theme_id, base_flag);
|
||||
switch (outline_id) {
|
||||
case 3: /* TH_ACTIVE */
|
||||
return pd->outlines_active_grp;
|
||||
case 2: /* Duplis */
|
||||
return pd->outlines_select_dupli_grp;
|
||||
case 1: /* TH_SELECT */
|
||||
return pd->outlines_select_grp;
|
||||
case 0: /* TH_TRANSFORM */
|
||||
return pd->outlines_transform_grp;
|
||||
default:
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
static DRWShadingGroup *shgroup_theme_id_to_probe_outline_or_null(OVERLAY_PrivateData *pd,
|
||||
int theme_id,
|
||||
const int base_flag)
|
||||
{
|
||||
int outline_id = shgroup_theme_id_to_outline_id(theme_id, base_flag);
|
||||
switch (outline_id) {
|
||||
case 3: /* TH_ACTIVE */
|
||||
return pd->outlines_probe_active_grp;
|
||||
case 2: /* Duplis */
|
||||
return pd->outlines_probe_select_dupli_grp;
|
||||
case 1: /* TH_SELECT */
|
||||
return pd->outlines_probe_select_grp;
|
||||
case 0: /* TH_TRANSFORM */
|
||||
return pd->outlines_probe_transform_grp;
|
||||
default:
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
static DRWShadingGroup *outline_shgroup(DRWPass *pass, int outline_id, GPUShader *sh)
|
||||
{
|
||||
DRWShadingGroup *grp = DRW_shgroup_create(sh, pass);
|
||||
DRW_shgroup_uniform_int_copy(grp, "outlineId", outline_id);
|
||||
return grp;
|
||||
}
|
||||
|
||||
void OVERLAY_outline_cache_init(OVERLAY_Data *vedata)
|
||||
{
|
||||
OVERLAY_PassList *psl = vedata->psl;
|
||||
|
@ -146,20 +77,13 @@ void OVERLAY_outline_cache_init(OVERLAY_Data *vedata)
|
|||
|
||||
GPUShader *sh_grid = OVERLAY_shader_outline_prepass_grid();
|
||||
GPUShader *sh_geom = OVERLAY_shader_outline_prepass(pd->xray_enabled_and_not_wire);
|
||||
GPUShader *sh = OVERLAY_shader_outline_prepass(false);
|
||||
|
||||
pd->outlines_transform_grp = outline_shgroup(psl->outlines_prepass_ps, 0, sh_geom);
|
||||
pd->outlines_select_grp = outline_shgroup(psl->outlines_prepass_ps, 1, sh_geom);
|
||||
pd->outlines_select_dupli_grp = outline_shgroup(psl->outlines_prepass_ps, 2, sh_geom);
|
||||
pd->outlines_active_grp = outline_shgroup(psl->outlines_prepass_ps, 3, sh_geom);
|
||||
pd->outlines_grp = grp = DRW_shgroup_create(sh_geom, psl->outlines_prepass_ps);
|
||||
DRW_shgroup_uniform_bool_copy(grp, "isTransform", (G.moving & G_TRANSFORM_OBJ) != 0);
|
||||
|
||||
pd->outlines_probe_transform_grp = outline_shgroup(psl->outlines_prepass_ps, 0, sh);
|
||||
pd->outlines_probe_select_grp = outline_shgroup(psl->outlines_prepass_ps, 1, sh);
|
||||
pd->outlines_probe_select_dupli_grp = outline_shgroup(psl->outlines_prepass_ps, 2, sh);
|
||||
pd->outlines_probe_active_grp = outline_shgroup(psl->outlines_prepass_ps, 3, sh);
|
||||
|
||||
pd->outlines_probe_grid_grp = grp = DRW_shgroup_create(sh_grid, psl->outlines_prepass_ps);
|
||||
pd->outlines_grid_grp = grp = DRW_shgroup_create(sh_grid, psl->outlines_prepass_ps);
|
||||
DRW_shgroup_uniform_block_persistent(grp, "globalsBlock", G_draw.block_ubo);
|
||||
DRW_shgroup_uniform_bool_copy(grp, "isTransform", (G.moving & G_TRANSFORM_OBJ) != 0);
|
||||
}
|
||||
|
||||
/* outlines_prepass_ps is still needed for selection of probes. */
|
||||
|
@ -221,10 +145,8 @@ static void outline_lightprobe(OVERLAY_PrivateData *pd, Object *ob, ViewLayer *v
|
|||
sub_v3_v3(increment[i], corner);
|
||||
}
|
||||
|
||||
int outline_id = shgroup_theme_id_to_outline_id(theme_id, ob->base_flag);
|
||||
uint cell_count = prb->grid_resolution_x * prb->grid_resolution_y * prb->grid_resolution_z;
|
||||
grp = DRW_shgroup_create_sub(pd->outlines_probe_grid_grp);
|
||||
DRW_shgroup_uniform_int_copy(grp, "outlineId", outline_id);
|
||||
grp = DRW_shgroup_create_sub(pd->outlines_grid_grp);
|
||||
DRW_shgroup_uniform_vec3_copy(grp, "corner", corner);
|
||||
DRW_shgroup_uniform_vec3_copy(grp, "increment_x", increment[0]);
|
||||
DRW_shgroup_uniform_vec3_copy(grp, "increment_y", increment[1]);
|
||||
|
@ -232,10 +154,6 @@ static void outline_lightprobe(OVERLAY_PrivateData *pd, Object *ob, ViewLayer *v
|
|||
DRW_shgroup_uniform_ivec3_copy(grp, "grid_resolution", &prb->grid_resolution_x);
|
||||
DRW_shgroup_call_procedural_points(grp, NULL, cell_count);
|
||||
}
|
||||
else if (prb->type == LIGHTPROBE_TYPE_PLANAR && (prb->flag & LIGHTPROBE_FLAG_SHOW_DATA)) {
|
||||
grp = shgroup_theme_id_to_probe_outline_or_null(pd, theme_id, ob->base_flag);
|
||||
DRW_shgroup_call_no_cull(grp, DRW_cache_quad_get(), ob);
|
||||
}
|
||||
}
|
||||
|
||||
void OVERLAY_outline_cache_populate(OVERLAY_Data *vedata,
|
||||
|
@ -278,8 +196,7 @@ void OVERLAY_outline_cache_populate(OVERLAY_Data *vedata,
|
|||
}
|
||||
|
||||
if (geom) {
|
||||
int theme_id = DRW_object_wire_theme_get(ob, draw_ctx->view_layer, NULL);
|
||||
shgroup = shgroup_theme_id_to_outline_or_null(pd, theme_id, ob->base_flag);
|
||||
shgroup = pd->outlines_grp;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -223,15 +223,8 @@ typedef struct OVERLAY_PrivateData {
|
|||
DRWShadingGroup *facing_grp;
|
||||
DRWShadingGroup *motion_path_lines_grp;
|
||||
DRWShadingGroup *motion_path_points_grp;
|
||||
DRWShadingGroup *outlines_active_grp;
|
||||
DRWShadingGroup *outlines_select_grp;
|
||||
DRWShadingGroup *outlines_select_dupli_grp;
|
||||
DRWShadingGroup *outlines_transform_grp;
|
||||
DRWShadingGroup *outlines_probe_transform_grp;
|
||||
DRWShadingGroup *outlines_probe_select_grp;
|
||||
DRWShadingGroup *outlines_probe_select_dupli_grp;
|
||||
DRWShadingGroup *outlines_probe_active_grp;
|
||||
DRWShadingGroup *outlines_probe_grid_grp;
|
||||
DRWShadingGroup *outlines_grp;
|
||||
DRWShadingGroup *outlines_grid_grp;
|
||||
DRWShadingGroup *paint_surf_grp;
|
||||
DRWShadingGroup *paint_wire_grp;
|
||||
DRWShadingGroup *paint_wire_selected_grp;
|
||||
|
|
|
@ -893,6 +893,7 @@ GPUShader *OVERLAY_shader_outline_prepass(bool use_wire)
|
|||
sh_data->outline_prepass_wire = GPU_shader_create_from_arrays({
|
||||
.vert = (const char *[]){sh_cfg->lib,
|
||||
datatoc_common_view_lib_glsl,
|
||||
datatoc_gpu_shader_common_obinfos_lib_glsl,
|
||||
datatoc_outline_prepass_vert_glsl,
|
||||
NULL},
|
||||
.geom = (const char *[]){sh_cfg->lib,
|
||||
|
@ -907,6 +908,7 @@ GPUShader *OVERLAY_shader_outline_prepass(bool use_wire)
|
|||
sh_data->outline_prepass = GPU_shader_create_from_arrays({
|
||||
.vert = (const char *[]){sh_cfg->lib,
|
||||
datatoc_common_view_lib_glsl,
|
||||
datatoc_gpu_shader_common_obinfos_lib_glsl,
|
||||
datatoc_outline_prepass_vert_glsl,
|
||||
NULL},
|
||||
.frag = (const char *[]){datatoc_outline_prepass_frag_glsl, NULL},
|
||||
|
@ -926,6 +928,7 @@ GPUShader *OVERLAY_shader_outline_prepass_grid(void)
|
|||
.vert = (const char *[]){sh_cfg->lib,
|
||||
datatoc_common_view_lib_glsl,
|
||||
datatoc_common_globals_lib_glsl,
|
||||
datatoc_gpu_shader_common_obinfos_lib_glsl,
|
||||
datatoc_outline_lightprobe_grid_vert_glsl,
|
||||
NULL},
|
||||
.frag = (const char *[]){datatoc_outline_prepass_frag_glsl, NULL},
|
||||
|
|
|
@ -4,9 +4,43 @@ uniform vec3 corner;
|
|||
uniform vec3 increment_x;
|
||||
uniform vec3 increment_y;
|
||||
uniform vec3 increment_z;
|
||||
uniform bool isTransform;
|
||||
|
||||
flat out int objectId;
|
||||
|
||||
int outline_colorid_get(void)
|
||||
{
|
||||
int flag = int(abs(ObjectInfo.w));
|
||||
bool is_from_dupli = (flag & DRW_BASE_FROM_DUPLI) != 0;
|
||||
bool is_active = (flag & DRW_BASE_ACTIVE) != 0;
|
||||
|
||||
if (is_from_dupli) {
|
||||
if (isTransform) {
|
||||
return 0; /* colorTransform */
|
||||
}
|
||||
else {
|
||||
return 2; /* colorDupliSelect */
|
||||
}
|
||||
}
|
||||
|
||||
if (isTransform) {
|
||||
return 0; /* colorTransform */
|
||||
}
|
||||
else if (is_active) {
|
||||
return 3; /* colorActive */
|
||||
}
|
||||
else {
|
||||
return 1; /* colorSelect */
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Replace top 2 bits (of the 16bit output) by outlineId.
|
||||
* This leaves 16K different IDs to create outlines between objects.
|
||||
* SHIFT = (32 - (16 - 2)) */
|
||||
#define SHIFT 18u
|
||||
|
||||
void main()
|
||||
{
|
||||
vec3 ls_cell_location;
|
||||
|
@ -25,6 +59,12 @@ void main()
|
|||
/* ID 0 is nothing (background) */
|
||||
objectId = resource_handle + 1;
|
||||
|
||||
/* Should be 2 bits only [0..3]. */
|
||||
int outline_id = outline_colorid_get();
|
||||
|
||||
/* Combine for 16bit uint target. */
|
||||
objectId = (outline_id << 14) | ((objectId << SHIFT) >> SHIFT);
|
||||
|
||||
#ifdef USE_WORLD_CLIP_PLANES
|
||||
world_clip_planes_calc_clip_distance(ws_cell_location);
|
||||
#endif
|
||||
|
|
|
@ -1,18 +1,10 @@
|
|||
|
||||
/* Should be 2 bits only [0..3]. */
|
||||
uniform int outlineId;
|
||||
|
||||
flat in int objectId;
|
||||
|
||||
/* using uint because 16bit uint can contain more ids than int. */
|
||||
out uint outId;
|
||||
|
||||
/* Replace top 2 bits (of the 16bit output) by outlineId.
|
||||
* This leaves 16K different IDs to create outlines between objects.
|
||||
* SHIFT = (32 - (16 - 2)) */
|
||||
#define SHIFT 18u
|
||||
|
||||
void main()
|
||||
{
|
||||
outId = (uint(outlineId) << 14u) | ((uint(objectId) << SHIFT) >> SHIFT);
|
||||
outId = uint(objectId);
|
||||
}
|
||||
|
|
|
@ -1,4 +1,6 @@
|
|||
|
||||
uniform bool isTransform;
|
||||
|
||||
in vec3 pos;
|
||||
|
||||
#ifdef USE_GEOM
|
||||
|
@ -10,6 +12,39 @@ out int objectId_g;
|
|||
flat out int objectId;
|
||||
#endif
|
||||
|
||||
int outline_colorid_get(void)
|
||||
{
|
||||
int flag = int(abs(ObjectInfo.w));
|
||||
bool is_from_dupli = (flag & DRW_BASE_FROM_DUPLI) != 0;
|
||||
bool is_active = (flag & DRW_BASE_ACTIVE) != 0;
|
||||
|
||||
if (is_from_dupli) {
|
||||
if (isTransform) {
|
||||
return 0; /* colorTransform */
|
||||
}
|
||||
else {
|
||||
return 2; /* colorDupliSelect */
|
||||
}
|
||||
}
|
||||
|
||||
if (isTransform) {
|
||||
return 0; /* colorTransform */
|
||||
}
|
||||
else if (is_active) {
|
||||
return 3; /* colorActive */
|
||||
}
|
||||
else {
|
||||
return 1; /* colorSelect */
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Replace top 2 bits (of the 16bit output) by outlineId.
|
||||
* This leaves 16K different IDs to create outlines between objects.
|
||||
* SHIFT = (32 - (16 - 2)) */
|
||||
#define SHIFT 18u
|
||||
|
||||
void main()
|
||||
{
|
||||
vec3 world_pos = point_object_to_world(pos);
|
||||
|
@ -23,6 +58,12 @@ void main()
|
|||
/* ID 0 is nothing (background) */
|
||||
objectId = resource_handle + 1;
|
||||
|
||||
/* Should be 2 bits only [0..3]. */
|
||||
int outline_id = outline_colorid_get();
|
||||
|
||||
/* Combine for 16bit uint target. */
|
||||
objectId = (outline_id << 14) | ((objectId << SHIFT) >> SHIFT);
|
||||
|
||||
#ifdef USE_WORLD_CLIP_PLANES
|
||||
world_clip_planes_calc_clip_distance(world_pos);
|
||||
#endif
|
||||
|
|
Loading…
Reference in New Issue