WIP: Onion Skinning Prototype #107641

Closed
Christoph Lendenfeld wants to merge 22 commits from ChrisLend/blender:onion_skin_test into main

When changing the target branch, be careful to rebase the branch in your fork to match. See documentation.
9 changed files with 94 additions and 1 deletions
Showing only changes of commit 9898a71d03 - Show all commits

View File

@ -6523,7 +6523,7 @@ class VIEW3D_PT_overlay_geometry(Panel):
col.prop(overlay, "show_face_orientation")
# sub.prop(overlay, "show_onion_skins")
sub.prop(overlay, "show_onion_skins")
class VIEW3D_PT_overlay_motion_tracking(Panel):

View File

@ -219,6 +219,7 @@ set(SRC
engines/overlay/overlay_viewer_attribute.cc
engines/overlay/overlay_volume.cc
engines/overlay/overlay_wireframe.cc
engines/overlay/overlay_onion_skin.cc
DRW_engine.h
DRW_pbvh.hh
@ -685,6 +686,8 @@ set(GLSL_SRC
engines/overlay/shaders/overlay_motion_path_line_vert.glsl
engines/overlay/shaders/overlay_motion_path_line_vert_no_geom.glsl
engines/overlay/shaders/overlay_motion_path_point_vert.glsl
engines/overlay/shaders/overlay_onion_skin_mesh_frag.glsl
engines/overlay/shaders/overlay_onion_skin_mesh_vert.glsl
engines/overlay/shaders/overlay_outline_detect_frag.glsl
engines/overlay/shaders/overlay_outline_prepass_curves_vert.glsl
engines/overlay/shaders/overlay_outline_prepass_frag.glsl

View File

@ -216,10 +216,12 @@ static void OVERLAY_cache_init(void *vedata)
OVERLAY_image_cache_init(data);
OVERLAY_metaball_cache_init(data);
OVERLAY_motion_path_cache_init(data);
OVERLAY_onion_skin_init(data);
OVERLAY_outline_cache_init(data);
OVERLAY_particle_cache_init(data);
OVERLAY_wireframe_cache_init(data);
OVERLAY_volume_cache_init(data);
OVERLAY_onion_skin_init(data);
}
BLI_INLINE OVERLAY_DupliData *OVERLAY_duplidata_get(Object *ob, void *vedata, bool *do_init)
@ -357,6 +359,8 @@ static void OVERLAY_cache_populate(void *vedata, Object *ob)
const bool draw_motion_paths = (pd->overlay.flag & V3D_OVERLAY_HIDE_MOTION_PATHS) == 0;
const bool draw_onion_skins = pd->overlay.flag & V3D_OVERLAY_ONION_SKINS;
bool do_init;
OVERLAY_DupliData *dupli = OVERLAY_duplidata_get(ob, vedata, &do_init);
@ -378,6 +382,9 @@ static void OVERLAY_cache_populate(void *vedata, Object *ob)
if (draw_bone_selection) {
OVERLAY_pose_cache_populate(data, ob);
}
if (draw_onion_skins) {
OVERLAY_onion_skin_populate(data, ob);
}
if (pd->overlay.flag & V3D_OVERLAY_VIEWER_ATTRIBUTE) {
if (is_preview) {
@ -678,6 +685,7 @@ static void OVERLAY_draw_scene(void *vedata)
OVERLAY_image_in_front_draw(data);
OVERLAY_motion_path_draw(data);
OVERLAY_onion_skin_draw(data);
OVERLAY_extra_centers_draw(data);
if (DRW_state_is_select() || DRW_state_is_depth()) {

View File

@ -0,0 +1,31 @@
#include "DRW_render.h"
#include "overlay_private.hh"
void OVERLAY_onion_skin_init(OVERLAY_Data *vedata)
{
OVERLAY_PassList *psl = vedata->psl;
OVERLAY_PrivateData *pd = vedata->stl->pd;
DRWState state = DRW_STATE_WRITE_COLOR | DRW_STATE_BLEND_ALPHA;
DRW_PASS_CREATE(psl->onion_skin_ps, state | pd->clipping_state);
GPUShader *shader = OVERLAY_shader_onion_skin_mesh();
DRWShadingGroup *grp;
pd->onion_skin_grp = grp = DRW_shgroup_create(shader, psl->onion_skin_ps);
DRW_shgroup_uniform_block(grp, "globalsBlock", G_draw.block_ubo);
}
void OVERLAY_onion_skin_populate(OVERLAY_Data *vedata, Object *ob)
{
OVERLAY_PrivateData *pd = vedata->stl->pd;
struct GPUBatch *geom = DRW_cache_object_surface_get(ob);
if (geom) {
DRW_shgroup_call(pd->onion_skin_grp, geom, ob);
}
}
void OVERLAY_onion_skin_draw(OVERLAY_Data *vedata)
{
OVERLAY_PassList *psl = vedata->psl;
DRW_draw_pass(psl->onion_skin_ps);
}

View File

@ -110,6 +110,7 @@ typedef struct OVERLAY_PassList {
DRWPass *image_foreground_scene_ps;
DRWPass *metaball_ps[2];
DRWPass *motion_paths_ps;
DRWPass *onion_skin_ps;
DRWPass *outlines_prepass_ps;
DRWPass *outlines_detect_ps;
DRWPass *outlines_resolve_ps;
@ -276,6 +277,7 @@ typedef struct OVERLAY_PrivateData {
DRWShadingGroup *flash_grp[2];
DRWShadingGroup *motion_path_lines_grp;
DRWShadingGroup *motion_path_points_grp;
DRWShadingGroup *onion_skin_grp;
DRWShadingGroup *outlines_grp;
DRWShadingGroup *outlines_curves_grp;
DRWShadingGroup *outlines_ptcloud_grp;
@ -649,6 +651,7 @@ void OVERLAY_image_empty_cache_populate(OVERLAY_Data *vedata, Object *ob);
void OVERLAY_image_cache_finish(OVERLAY_Data *vedata);
void OVERLAY_image_draw(OVERLAY_Data *vedata);
void OVERLAY_image_background_draw(OVERLAY_Data *vedata);
/**
* This function draws images that needs the view transform applied.
* It draws these images directly into the scene color buffer.
@ -666,6 +669,10 @@ void OVERLAY_motion_path_cache_init(OVERLAY_Data *vedata);
void OVERLAY_motion_path_cache_populate(OVERLAY_Data *vedata, Object *ob);
void OVERLAY_motion_path_draw(OVERLAY_Data *vedata);
void OVERLAY_onion_skin_init(OVERLAY_Data *vedata);
void OVERLAY_onion_skin_populate(OVERLAY_Data *vedata, Object *ob);
void OVERLAY_onion_skin_draw(OVERLAY_Data *vedata);
void OVERLAY_outline_init(OVERLAY_Data *vedata);
void OVERLAY_outline_cache_init(OVERLAY_Data *vedata);
void OVERLAY_outline_cache_populate(OVERLAY_Data *vedata,
@ -765,6 +772,7 @@ GPUShader *OVERLAY_shader_grid_image(void);
GPUShader *OVERLAY_shader_image(void);
GPUShader *OVERLAY_shader_motion_path_line(void);
GPUShader *OVERLAY_shader_motion_path_vert(void);
GPUShader *OVERLAY_shader_onion_skin_mesh(void);
GPUShader *OVERLAY_shader_uniform_color(void);
GPUShader *OVERLAY_shader_uniform_color_pointcloud(void);
GPUShader *OVERLAY_shader_outline_prepass(bool use_wire);

View File

@ -76,6 +76,7 @@ struct OVERLAY_Shaders {
GPUShader *image;
GPUShader *motion_path_line;
GPUShader *motion_path_vert;
GPUShader *onion_skin_mesh;
GPUShader *outline_prepass;
GPUShader *outline_prepass_curves;
GPUShader *outline_prepass_gpencil;
@ -683,6 +684,16 @@ GPUShader *OVERLAY_shader_motion_path_vert(void)
return sh_data->motion_path_vert;
}
GPUShader *OVERLAY_shader_onion_skin_mesh(void)
{
const DRWContextState *draw_ctx = DRW_context_state_get();
OVERLAY_Shaders *sh_data = &e_data.sh_data[draw_ctx->sh_cfg];
if (!sh_data->onion_skin_mesh) {
sh_data->onion_skin_mesh = GPU_shader_create_from_info_name("overlay_onion_skin_mesh");
}
return sh_data->onion_skin_mesh;
}
GPUShader *OVERLAY_shader_outline_prepass(bool use_wire)
{
const DRWContextState *draw_ctx = DRW_context_state_get();

View File

@ -247,6 +247,23 @@ GPU_SHADER_CREATE_INFO(overlay_motion_path_point_clipped)
/** \} */
/* -------------------------------------------------------------------- */
/** \name Onion Skin
* \{ */
GPU_SHADER_INTERFACE_INFO(onion_skin_iface, "interp").smooth(Type::VEC4, "color");
GPU_SHADER_CREATE_INFO(overlay_onion_skin_mesh)
.do_static_compilation(true)
.vertex_in(0, Type::VEC3, "pos")
.vertex_out(onion_skin_iface)
.fragment_out(0, Type::VEC4, "fragColor")
.fragment_source("overlay_onion_skin_mesh_frag.glsl")
.vertex_source("overlay_onion_skin_mesh_vert.glsl")
.additional_info("draw_mesh", "draw_globals");
/** \} */
/* -------------------------------------------------------------------- */
/** \name Image Empty
* \{ */

View File

@ -0,0 +1,4 @@
void main()
{
fragColor = interp.color;
}

View File

@ -0,0 +1,11 @@
#pragma BLENDER_REQUIRE(common_view_clipping_lib.glsl)
#pragma BLENDER_REQUIRE(common_view_lib.glsl)
void main()
{
interp.color.rgb = vec3(1, 0, 1);
interp.color.a = 0.5f;
vec3 world_pos = point_object_to_world(pos);
gl_Position = point_world_to_ndc(world_pos);
/* view_clipping_distances(world_pos); */
}