Overlay Engine: LightProbe: Simplify drawing of irradiance grid data

This separates it from the outline pass and fix a visibility bug
when extras were off.
This commit is contained in:
2019-12-04 22:24:34 +01:00
parent a77fe7eb5c
commit 4705aa4fe5
10 changed files with 158 additions and 167 deletions

View File

@@ -345,6 +345,7 @@ data_to_c_simple(engines/overlay/shaders/edit_particle_point_vert.glsl SRC)
data_to_c_simple(engines/overlay/shaders/extra_frag.glsl SRC)
data_to_c_simple(engines/overlay/shaders/extra_vert.glsl SRC)
data_to_c_simple(engines/overlay/shaders/extra_groundline_vert.glsl SRC)
data_to_c_simple(engines/overlay/shaders/extra_lightprobe_grid_vert.glsl SRC)
data_to_c_simple(engines/overlay/shaders/extra_loose_point_frag.glsl SRC)
data_to_c_simple(engines/overlay/shaders/extra_loose_point_vert.glsl SRC)
data_to_c_simple(engines/overlay/shaders/extra_point_vert.glsl SRC)
@@ -363,7 +364,6 @@ data_to_c_simple(engines/overlay/shaders/outline_detect_frag.glsl SRC)
data_to_c_simple(engines/overlay/shaders/outline_prepass_frag.glsl SRC)
data_to_c_simple(engines/overlay/shaders/outline_prepass_geom.glsl SRC)
data_to_c_simple(engines/overlay/shaders/outline_prepass_vert.glsl SRC)
data_to_c_simple(engines/overlay/shaders/outline_lightprobe_grid_vert.glsl SRC)
data_to_c_simple(engines/overlay/shaders/paint_face_vert.glsl SRC)
data_to_c_simple(engines/overlay/shaders/paint_point_vert.glsl SRC)
data_to_c_simple(engines/overlay/shaders/paint_texture_frag.glsl SRC)

View File

@@ -67,6 +67,9 @@ void OVERLAY_antialiasing_init(OVERLAY_Data *vedata)
OVERLAY_PrivateData *pd = vedata->stl->pd;
DefaultTextureList *dtxl = DRW_viewport_texture_list_get();
/* Small texture which will have very small impact on rendertime. */
DRW_texture_ensure_2d(&txl->dummy_depth_tx, 1, 1, GPU_DEPTH_COMPONENT24, 0);
if (!DRW_state_is_fbo()) {
/* Use default view */
pd->view_default = (DRWView *)DRW_view_default_get();

View File

@@ -39,17 +39,11 @@
void OVERLAY_edit_mesh_init(OVERLAY_Data *vedata)
{
OVERLAY_TextureList *txl = vedata->txl;
OVERLAY_PrivateData *pd = vedata->stl->pd;
const DRWContextState *draw_ctx = DRW_context_state_get();
pd->edit_mesh.do_zbufclip = XRAY_FLAG_ENABLED(draw_ctx->v3d);
if (!pd->edit_mesh.do_zbufclip) {
/* Small texture which will have very small impact on rendertime. */
DRW_texture_ensure_2d(&txl->dummy_depth_tx, 1, 1, GPU_DEPTH_COMPONENT24, 0);
}
/* Create view with depth offset */
DRWView *default_view = (DRWView *)DRW_view_default_get();
/* Don't use AA view (pd->view_default) because edit mode already has anti-aliasing. */

View File

@@ -196,10 +196,9 @@ static void OVERLAY_cache_populate(void *vedata, Object *ob)
const bool draw_bones = (pd->overlay.flag & V3D_OVERLAY_HIDE_BONES) == 0;
const bool draw_wires = draw_surface && has_surface &&
(pd->wireframe_mode || !pd->hide_overlays);
const bool draw_outlines = !in_edit_mode && !in_paint_mode && renderable &&
const bool draw_outlines = !in_edit_mode && !in_paint_mode && renderable && has_surface &&
(pd->v3d_flag & V3D_SELECT_OUTLINE) &&
((ob->base_flag & BASE_SELECTED) ||
(is_select && ob->type == OB_LIGHTPROBE));
(ob->base_flag & BASE_SELECTED);
const bool draw_bone_selection = (ob->type == OB_MESH) && pd->armature.do_pose_fade_geom &&
!is_select;
const bool draw_extras =

View File

@@ -28,6 +28,7 @@
#include "BKE_camera.h"
#include "BKE_constraint.h"
#include "BKE_curve.h"
#include "BKE_global.h"
#include "BKE_mball.h"
#include "BKE_mesh.h"
#include "BKE_movieclip.h"
@@ -60,10 +61,27 @@
void OVERLAY_extra_cache_init(OVERLAY_Data *vedata)
{
OVERLAY_PassList *psl = vedata->psl;
OVERLAY_TextureList *txl = vedata->txl;
OVERLAY_PrivateData *pd = vedata->stl->pd;
DRW_PASS_CREATE(psl->extra_blend_ps, DRW_STATE_WRITE_COLOR | DRW_STATE_BLEND_ALPHA);
DRW_PASS_CREATE(psl->extra_centers_ps, DRW_STATE_WRITE_COLOR | DRW_STATE_BLEND_ALPHA);
DRWState state_blend = DRW_STATE_WRITE_COLOR | DRW_STATE_BLEND_ALPHA;
DRW_PASS_CREATE(psl->extra_blend_ps, state_blend | pd->clipping_state);
DRW_PASS_CREATE(psl->extra_centers_ps, state_blend | pd->clipping_state);
{
DRWState state = DRW_STATE_WRITE_COLOR;
DRW_PASS_CREATE(psl->extra_grid_ps, state | pd->clipping_state);
DefaultTextureList *dtxl = DRW_viewport_texture_list_get();
DRWShadingGroup *grp;
struct GPUShader *sh = OVERLAY_shader_extra_grid();
struct GPUTexture *tex = DRW_state_is_fbo() ? dtxl->depth : txl->dummy_depth_tx;
pd->extra_grid_grp = grp = DRW_shgroup_create(sh, psl->extra_grid_ps);
DRW_shgroup_uniform_texture_persistent(grp, "depthBuffer", tex);
DRW_shgroup_uniform_block_persistent(grp, "globalsBlock", G_draw.block_ubo);
DRW_shgroup_uniform_bool_copy(grp, "isTransform", (G.moving & G_TRANSFORM_OBJ) != 0);
}
for (int i = 0; i < 2; i++) {
/* Non Meshes Pass (Camera, empties, lights ...) */
@@ -662,11 +680,12 @@ void OVERLAY_lightprobe_cache_populate(OVERLAY_Data *vedata, Object *ob)
const DRWContextState *draw_ctx = DRW_context_state_get();
ViewLayer *view_layer = draw_ctx->view_layer;
float *color_p;
DRW_object_wire_theme_get(ob, view_layer, &color_p);
int theme_id = DRW_object_wire_theme_get(ob, view_layer, &color_p);
const LightProbe *prb = (LightProbe *)ob->data;
const bool show_clipping = (prb->flag & LIGHTPROBE_FLAG_SHOW_CLIP_DIST) != 0;
const bool show_parallax = (prb->flag & LIGHTPROBE_FLAG_SHOW_PARALLAX) != 0;
const bool show_influence = (prb->flag & LIGHTPROBE_FLAG_SHOW_INFLUENCE) != 0;
const bool show_data = (ob->base_flag & BASE_SELECTED) || DRW_state_is_select();
union {
float mat[4][4];
@@ -711,6 +730,31 @@ void OVERLAY_lightprobe_cache_populate(OVERLAY_Data *vedata, Object *ob)
OVERLAY_empty_shape(cb, ob->obmat, 1.0 + prb->distinf, OB_CUBE, color_p);
OVERLAY_empty_shape(cb, ob->obmat, 1.0 + prb->distinf * f, OB_CUBE, color_p);
}
/* Data dots */
if (show_data) {
instdata.mat[0][3] = prb->grid_resolution_x;
instdata.mat[1][3] = prb->grid_resolution_y;
instdata.mat[2][3] = prb->grid_resolution_z;
/* Put theme id in matrix. */
if (UNLIKELY(ob->base_flag & BASE_FROM_DUPLI)) {
instdata.mat[3][3] = 0.0;
}
else if (theme_id == TH_ACTIVE) {
instdata.mat[3][3] = 1.0;
}
else /* TH_SELECT */ {
instdata.mat[3][3] = 2.0;
}
uint cell_count = prb->grid_resolution_x * prb->grid_resolution_y * prb->grid_resolution_z;
DRWShadingGroup *grp = DRW_shgroup_create_sub(vedata->stl->pd->extra_grid_grp);
DRW_shgroup_uniform_vec4_copy(grp, "gridModelMatrix[0]", instdata.mat[0]);
DRW_shgroup_uniform_vec4_copy(grp, "gridModelMatrix[1]", instdata.mat[1]);
DRW_shgroup_uniform_vec4_copy(grp, "gridModelMatrix[2]", instdata.mat[2]);
DRW_shgroup_uniform_vec4_copy(grp, "gridModelMatrix[3]", instdata.mat[3]);
DRW_shgroup_call_procedural_points(grp, NULL, cell_count);
}
break;
case LIGHTPROBE_TYPE_PLANAR:
DRW_buffer_add_entry(cb->probe_planar, color_p, &instdata);
@@ -1581,7 +1625,17 @@ void OVERLAY_extra_in_front_draw(OVERLAY_Data *vedata)
void OVERLAY_extra_centers_draw(OVERLAY_Data *vedata)
{
OVERLAY_FramebufferList *fbl = vedata->fbl;
OVERLAY_PassList *psl = vedata->psl;
if (DRW_state_is_fbo()) {
GPU_framebuffer_bind(fbl->overlay_color_only_fb);
}
DRW_draw_pass(psl->extra_grid_ps);
DRW_draw_pass(psl->extra_centers_ps);
if (DRW_state_is_fbo()) {
GPU_framebuffer_bind(fbl->overlay_default_fb);
}
}

View File

@@ -75,15 +75,10 @@ void OVERLAY_outline_cache_init(OVERLAY_Data *vedata)
DRWState state = DRW_STATE_WRITE_COLOR | DRW_STATE_WRITE_DEPTH | DRW_STATE_DEPTH_LESS_EQUAL;
DRW_PASS_CREATE(psl->outlines_prepass_ps, state | pd->clipping_state);
GPUShader *sh_grid = OVERLAY_shader_outline_prepass_grid();
GPUShader *sh_geom = OVERLAY_shader_outline_prepass(pd->xray_enabled_and_not_wire);
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_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. */
@@ -111,51 +106,6 @@ void OVERLAY_outline_cache_init(OVERLAY_Data *vedata)
}
}
static void outline_lightprobe(OVERLAY_PrivateData *pd, Object *ob, ViewLayer *view_layer)
{
DRWShadingGroup *grp;
LightProbe *prb = (LightProbe *)ob->data;
int theme_id = DRW_object_wire_theme_get(ob, view_layer, NULL);
if (prb->type == LIGHTPROBE_TYPE_GRID) {
float corner[3];
float increment[3][3];
/* Update transforms */
float cell_dim[3], half_cell_dim[3];
cell_dim[0] = 2.0f / (float)(prb->grid_resolution_x);
cell_dim[1] = 2.0f / (float)(prb->grid_resolution_y);
cell_dim[2] = 2.0f / (float)(prb->grid_resolution_z);
mul_v3_v3fl(half_cell_dim, cell_dim, 0.5f);
/* First cell. */
copy_v3_fl(corner, -1.0f);
add_v3_v3(corner, half_cell_dim);
mul_m4_v3(ob->obmat, corner);
/* Opposite neighbor cell. */
copy_v3_fl3(increment[0], cell_dim[0], 0.0f, 0.0f);
copy_v3_fl3(increment[1], 0.0f, cell_dim[1], 0.0f);
copy_v3_fl3(increment[2], 0.0f, 0.0f, cell_dim[2]);
for (int i = 0; i < 3; i++) {
add_v3_v3(increment[i], half_cell_dim);
add_v3_fl(increment[i], -1.0f);
mul_m4_v3(ob->obmat, increment[i]);
sub_v3_v3(increment[i], corner);
}
uint cell_count = prb->grid_resolution_x * prb->grid_resolution_y * prb->grid_resolution_z;
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]);
DRW_shgroup_uniform_vec3_copy(grp, "increment_z", increment[2]);
DRW_shgroup_uniform_ivec3_copy(grp, "grid_resolution", &prb->grid_resolution_x);
DRW_shgroup_call_procedural_points(grp, NULL, cell_count);
}
}
void OVERLAY_outline_cache_populate(OVERLAY_Data *vedata,
Object *ob,
OVERLAY_DupliData *dupli,
@@ -172,11 +122,6 @@ void OVERLAY_outline_cache_populate(OVERLAY_Data *vedata,
return;
}
if (ob->type == OB_LIGHTPROBE) {
outline_lightprobe(pd, ob, draw_ctx->view_layer);
return;
}
if (dupli && !init_dupli) {
geom = dupli->outline_geom;
shgroup = dupli->outline_shgrp;
@@ -233,8 +178,4 @@ void OVERLAY_outline_draw(OVERLAY_Data *vedata)
DRW_stats_group_end();
}
else if (DRW_state_is_select()) {
/* Render probes spheres/planes so we can select them. */
DRW_draw_pass(psl->outlines_prepass_ps);
}
}

View File

@@ -72,6 +72,7 @@ typedef struct OVERLAY_PassList {
DRWPass *extra_ps[2];
DRWPass *extra_blend_ps;
DRWPass *extra_centers_ps;
DRWPass *extra_grid_ps;
DRWPass *facing_ps;
DRWPass *grid_ps;
DRWPass *image_background_under_ps;
@@ -220,11 +221,11 @@ typedef struct OVERLAY_PrivateData {
DRWShadingGroup *edit_particle_point_grp;
DRWShadingGroup *edit_text_overlay_grp;
DRWShadingGroup *edit_text_wire_grp[2];
DRWShadingGroup *extra_grid_grp;
DRWShadingGroup *facing_grp;
DRWShadingGroup *motion_path_lines_grp;
DRWShadingGroup *motion_path_points_grp;
DRWShadingGroup *outlines_grp;
DRWShadingGroup *outlines_grid_grp;
DRWShadingGroup *paint_surf_grp;
DRWShadingGroup *paint_wire_grp;
DRWShadingGroup *paint_wire_selected_grp;
@@ -546,7 +547,7 @@ GPUShader *OVERLAY_shader_motion_path_line(void);
GPUShader *OVERLAY_shader_motion_path_vert(void);
GPUShader *OVERLAY_shader_uniform_color(void);
GPUShader *OVERLAY_shader_outline_prepass(bool use_wire);
GPUShader *OVERLAY_shader_outline_prepass_grid(void);
GPUShader *OVERLAY_shader_extra_grid(void);
GPUShader *OVERLAY_shader_outline_detect(void);
GPUShader *OVERLAY_shader_paint_face(void);
GPUShader *OVERLAY_shader_paint_point(void);

View File

@@ -65,6 +65,7 @@ extern char datatoc_edit_particle_point_vert_glsl[];
extern char datatoc_extra_frag_glsl[];
extern char datatoc_extra_vert_glsl[];
extern char datatoc_extra_groundline_vert_glsl[];
extern char datatoc_extra_lightprobe_grid_vert_glsl[];
extern char datatoc_extra_loose_point_vert_glsl[];
extern char datatoc_extra_loose_point_frag_glsl[];
extern char datatoc_extra_point_vert_glsl[];
@@ -83,7 +84,6 @@ extern char datatoc_outline_detect_frag_glsl[];
extern char datatoc_outline_prepass_frag_glsl[];
extern char datatoc_outline_prepass_geom_glsl[];
extern char datatoc_outline_prepass_vert_glsl[];
extern char datatoc_outline_lightprobe_grid_vert_glsl[];
extern char datatoc_paint_face_vert_glsl[];
extern char datatoc_paint_point_vert_glsl[];
extern char datatoc_paint_texture_frag_glsl[];
@@ -148,6 +148,7 @@ typedef struct OVERLAY_Shaders {
GPUShader *extra_groundline;
GPUShader *extra_wire[2];
GPUShader *extra_point;
GPUShader *extra_lightprobe_grid;
GPUShader *extra_loose_point;
GPUShader *facing;
GPUShader *grid;
@@ -156,7 +157,6 @@ typedef struct OVERLAY_Shaders {
GPUShader *motion_path_vert;
GPUShader *outline_prepass;
GPUShader *outline_prepass_wire;
GPUShader *outline_prepass_lightprobe_grid;
GPUShader *outline_detect;
GPUShader *paint_face;
GPUShader *paint_point;
@@ -688,6 +688,26 @@ GPUShader *OVERLAY_shader_extra(void)
return sh_data->extra;
}
GPUShader *OVERLAY_shader_extra_grid(void)
{
const DRWContextState *draw_ctx = DRW_context_state_get();
const GPUShaderConfigData *sh_cfg = &GPU_shader_cfg_data[draw_ctx->sh_cfg];
OVERLAY_Shaders *sh_data = &e_data.sh_data[draw_ctx->sh_cfg];
if (!sh_data->extra_lightprobe_grid) {
sh_data->extra_lightprobe_grid = GPU_shader_create_from_arrays({
.vert = (const char *[]){sh_cfg->lib,
datatoc_common_view_lib_glsl,
datatoc_common_globals_lib_glsl,
datatoc_gpu_shader_common_obinfos_lib_glsl,
datatoc_extra_lightprobe_grid_vert_glsl,
NULL},
.frag = (const char *[]){datatoc_gpu_shader_point_varying_color_frag_glsl, NULL},
.defs = (const char *[]){sh_cfg->def, NULL},
});
}
return sh_data->extra_lightprobe_grid;
}
GPUShader *OVERLAY_shader_extra_groundline(void)
{
const DRWContextState *draw_ctx = DRW_context_state_get();
@@ -918,26 +938,6 @@ GPUShader *OVERLAY_shader_outline_prepass(bool use_wire)
return use_wire ? sh_data->outline_prepass_wire : sh_data->outline_prepass;
}
GPUShader *OVERLAY_shader_outline_prepass_grid(void)
{
const DRWContextState *draw_ctx = DRW_context_state_get();
const GPUShaderConfigData *sh_cfg = &GPU_shader_cfg_data[draw_ctx->sh_cfg];
OVERLAY_Shaders *sh_data = &e_data.sh_data[draw_ctx->sh_cfg];
if (!sh_data->outline_prepass_lightprobe_grid) {
sh_data->outline_prepass_lightprobe_grid = GPU_shader_create_from_arrays({
.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},
.defs = (const char *[]){sh_cfg->def, NULL},
});
}
return sh_data->outline_prepass_lightprobe_grid;
}
GPUShader *OVERLAY_shader_outline_detect(void)
{
OVERLAY_Shaders *sh_data = &e_data.sh_data[0];

View File

@@ -0,0 +1,70 @@
uniform sampler2D depthBuffer;
uniform vec4 gridModelMatrix[4];
uniform bool isTransform;
out vec4 finalColor;
vec4 color_from_id(float color_id)
{
if (isTransform) {
return colorTransform;
}
else if (color_id == 0.0) {
return colorDupliSelect;
}
else if (color_id == 1.0) {
return colorActive;
}
else /* 2.0 */ {
return colorSelect;
}
return colorTransform;
}
/* 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()
{
mat4 model_mat = mat4(
gridModelMatrix[0], gridModelMatrix[1], gridModelMatrix[2], gridModelMatrix[3]);
model_mat[0][3] = model_mat[1][3] = model_mat[2][3] = 0.0;
model_mat[3][3] = 1.0;
float color_id = gridModelMatrix[3].w;
ivec3 grid_resolution = ivec3(gridModelMatrix[0].w, gridModelMatrix[1].w, gridModelMatrix[2].w);
vec3 ls_cell_location;
/* Keep in sync with update_irradiance_probe */
ls_cell_location.z = float(gl_VertexID % grid_resolution.z);
ls_cell_location.y = float((gl_VertexID / grid_resolution.z) % grid_resolution.y);
ls_cell_location.x = float(gl_VertexID / (grid_resolution.z * grid_resolution.y));
ls_cell_location += 0.5;
ls_cell_location /= vec3(grid_resolution);
ls_cell_location = ls_cell_location * 2.0 - 1.0;
vec3 ws_cell_location = (model_mat * vec4(ls_cell_location, 1.0)).xyz;
gl_Position = point_world_to_ndc(ws_cell_location);
gl_PointSize = sizeVertex * 2.0;
finalColor = color_from_id(color_id);
/* Shade occluded points differently. */
vec4 p = gl_Position / gl_Position.w;
float z_depth = texture(depthBuffer, p.xy * 0.5 + 0.5).r * 2.0 - 1.0;
float z_delta = p.z - z_depth;
if (z_delta > 0.0) {
float fac = 1.0 - z_delta * 10000.0;
/* Smooth blend to avoid flickering. */
finalColor = mix(colorBackground, finalColor, clamp(fac, 0.5, 1.0));
}
#ifdef USE_WORLD_CLIP_PLANES
world_clip_planes_calc_clip_distance(ws_cell_location);
#endif
}

View File

@@ -1,71 +0,0 @@
uniform ivec3 grid_resolution;
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;
/* Keep in sync with update_irradiance_probe */
ls_cell_location.z = float(gl_VertexID % grid_resolution.z);
ls_cell_location.y = float((gl_VertexID / grid_resolution.z) % grid_resolution.y);
ls_cell_location.x = float(gl_VertexID / (grid_resolution.z * grid_resolution.y));
vec3 ws_cell_location = corner +
(increment_x * ls_cell_location.x + increment_y * ls_cell_location.y +
increment_z * ls_cell_location.z);
gl_Position = ViewProjectionMatrix * vec4(ws_cell_location, 1.0);
gl_PointSize = 2.0f;
/* 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
}