diff options
author | Clément Foucault <foucault.clem@gmail.com> | 2022-04-30 22:08:07 +0300 |
---|---|---|
committer | Clément Foucault <foucault.clem@gmail.com> | 2022-04-30 22:11:55 +0300 |
commit | 69a43069e857582e82e812e05f74493066f8b0a7 (patch) | |
tree | db94942e56d9894ee27371b3ef75bc6e451db52f /source/blender/draw | |
parent | 57b4efc250a76ef7172cf5700e84138c4f22e62c (diff) |
Overlay: Port edit gpencil shaders to use shaderCreateInfo
This should have (mostly) no functional changes.
Support for clipping was added to the shaders but it is not enabled for now
as we wait for the Gpencil engine to support clipping.
Diffstat (limited to 'source/blender/draw')
5 files changed, 98 insertions, 63 deletions
diff --git a/source/blender/draw/engines/overlay/overlay_shader.c b/source/blender/draw/engines/overlay/overlay_shader.c index bd00d4d47f0..0288dc12be8 100644 --- a/source/blender/draw/engines/overlay/overlay_shader.c +++ b/source/blender/draw/engines/overlay/overlay_shader.c @@ -446,14 +446,12 @@ GPUShader *OVERLAY_shader_edit_curve_wire(void) GPUShader *OVERLAY_shader_edit_gpencil_guide_point(void) { - OVERLAY_Shaders *sh_data = &e_data.sh_data[0]; + const DRWContextState *draw_ctx = DRW_context_state_get(); + OVERLAY_Shaders *sh_data = &e_data.sh_data[draw_ctx->sh_cfg]; if (!sh_data->edit_gpencil_guide_point) { - sh_data->edit_gpencil_guide_point = GPU_shader_create_from_arrays({ - .vert = (const char *[]){datatoc_common_view_lib_glsl, - datatoc_edit_gpencil_guide_vert_glsl, - NULL}, - .frag = (const char *[]){datatoc_gpu_shader_point_varying_color_frag_glsl, NULL}, - }); + sh_data->edit_gpencil_guide_point = GPU_shader_create_from_info_name( + draw_ctx->sh_cfg ? "overlay_edit_gpencil_guide_point_clipped" : + "overlay_edit_gpencil_guide_point"); } return sh_data->edit_gpencil_guide_point; } @@ -461,18 +459,10 @@ GPUShader *OVERLAY_shader_edit_gpencil_guide_point(void) GPUShader *OVERLAY_shader_edit_gpencil_point(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->edit_gpencil_point) { - sh_data->edit_gpencil_point = GPU_shader_create_from_arrays({ - .vert = (const char *[]){sh_cfg->lib, - datatoc_common_globals_lib_glsl, - datatoc_common_view_lib_glsl, - datatoc_edit_gpencil_vert_glsl, - NULL}, - .frag = (const char *[]){datatoc_gpu_shader_point_varying_color_frag_glsl, NULL}, - .defs = (const char *[]){sh_cfg->def, "#define USE_POINTS\n", NULL}, - }); + sh_data->edit_gpencil_point = GPU_shader_create_from_info_name( + draw_ctx->sh_cfg ? "overlay_edit_gpencil_point_clipped" : "overlay_edit_gpencil_point"); } return sh_data->edit_gpencil_point; } @@ -480,18 +470,10 @@ GPUShader *OVERLAY_shader_edit_gpencil_point(void) GPUShader *OVERLAY_shader_edit_gpencil_wire(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->edit_gpencil_wire) { - sh_data->edit_gpencil_wire = GPU_shader_create_from_arrays({ - .vert = (const char *[]){sh_cfg->lib, - datatoc_common_globals_lib_glsl, - datatoc_common_view_lib_glsl, - datatoc_edit_gpencil_vert_glsl, - NULL}, - .frag = (const char *[]){datatoc_gpu_shader_3D_smooth_color_frag_glsl, NULL}, - .defs = (const char *[]){sh_cfg->def, NULL}, - }); + sh_data->edit_gpencil_wire = GPU_shader_create_from_info_name( + draw_ctx->sh_cfg ? "overlay_edit_gpencil_wire_clipped" : "overlay_edit_gpencil_wire"); } return sh_data->edit_gpencil_wire; } diff --git a/source/blender/draw/engines/overlay/overlay_shader_shared.h b/source/blender/draw/engines/overlay/overlay_shader_shared.h index 860560e1026..20b6adf09bb 100644 --- a/source/blender/draw/engines/overlay/overlay_shader_shared.h +++ b/source/blender/draw/engines/overlay/overlay_shader_shared.h @@ -50,6 +50,14 @@ BLI_STATIC_ASSERT_ALIGN(OVERLAY_GridData, 16) /* Keep the same value in `handle_display` in `DNA_view3d_types.h` */ # define CURVE_HANDLE_SELECTED 0 # define CURVE_HANDLE_ALL 1 + +# define GP_EDIT_POINT_SELECTED 1u /* 1 << 0 */ +# define GP_EDIT_STROKE_SELECTED 2u /* 1 << 1 */ +# define GP_EDIT_MULTIFRAME 4u /* 1 << 2 */ +# define GP_EDIT_STROKE_START 8u /* 1 << 3 */ +# define GP_EDIT_STROKE_END 16u /* 1 << 4 */ +# define GP_EDIT_POINT_DIMMED 32u /* 1 << 5 */ + #else /* TODO(fclem): Find a better way to share enums/defines from DNA files with GLSL. */ BLI_STATIC_ASSERT(CURVE_HANDLE_SELECTED == 0, "Ensure value is sync"); diff --git a/source/blender/draw/engines/overlay/shaders/edit_gpencil_guide_vert.glsl b/source/blender/draw/engines/overlay/shaders/edit_gpencil_guide_vert.glsl index ef68b0f4e6f..a5091345539 100644 --- a/source/blender/draw/engines/overlay/shaders/edit_gpencil_guide_vert.glsl +++ b/source/blender/draw/engines/overlay/shaders/edit_gpencil_guide_vert.glsl @@ -1,8 +1,6 @@ -uniform vec4 pColor; -uniform float pSize; -uniform vec3 pPosition; -out vec4 finalColor; +#pragma BLENDER_REQUIRE(common_view_clipping_lib.glsl) +#pragma BLENDER_REQUIRE(common_view_lib.glsl) void main() { @@ -11,4 +9,6 @@ void main() gl_Position = point_world_to_ndc(pPosition); finalColor = pColor; gl_PointSize = pSize; + + view_clipping_distances(pPosition); } diff --git a/source/blender/draw/engines/overlay/shaders/edit_gpencil_vert.glsl b/source/blender/draw/engines/overlay/shaders/edit_gpencil_vert.glsl index a6161d36a07..f5d6e89d016 100644 --- a/source/blender/draw/engines/overlay/shaders/edit_gpencil_vert.glsl +++ b/source/blender/draw/engines/overlay/shaders/edit_gpencil_vert.glsl @@ -1,19 +1,6 @@ -uniform float normalSize; -uniform bool doMultiframe; -uniform bool doStrokeEndpoints; -uniform bool hideSelect; -uniform bool doWeightColor; -uniform float gpEditOpacity; -uniform vec4 gpEditColor; -uniform sampler1D weightTex; - -in vec3 pos; -in int ma; -in uint vflag; -in float weight; - -out vec4 finalColor; +#pragma BLENDER_REQUIRE(common_view_clipping_lib.glsl) +#pragma BLENDER_REQUIRE(common_view_lib.glsl) void discard_vert() { @@ -21,26 +8,19 @@ void discard_vert() gl_Position = vec4(0.0, 0.0, -3e36, 0.0); } -#define GP_EDIT_POINT_SELECTED 1u /* 1 << 0 */ -#define GP_EDIT_STROKE_SELECTED 2u /* 1 << 1 */ -#define GP_EDIT_MULTIFRAME 4u /* 1 << 2 */ -#define GP_EDIT_STROKE_START 8u /* 1 << 3 */ -#define GP_EDIT_STROKE_END 16u /* 1 << 4 */ -#define GP_EDIT_POINT_DIMMED 32u /* 1 << 5 */ - #ifdef USE_POINTS -# define colorUnselect colorGpencilVertex -# define colorSelect colorGpencilVertexSelect +# define gp_colorUnselect colorGpencilVertex +# define gp_colorSelect colorGpencilVertexSelect #else -# define colorUnselect gpEditColor -# define colorSelect (hideSelect ? colorUnselect : colorGpencilVertexSelect) +# define gp_colorUnselect gpEditColor +# define gp_colorSelect (hideSelect ? gp_colorUnselect : colorGpencilVertexSelect) #endif vec3 weight_to_rgb(float t) { if (t < 0.0) { /* No weight */ - return colorUnselect.rgb; + return gp_colorUnselect.rgb; } else if (t > 1.0) { /* Error color */ @@ -68,7 +48,7 @@ void main() finalColor.a = gpEditOpacity; } else { - finalColor = (is_point_sel) ? colorSelect : colorUnselect; + finalColor = (is_point_sel) ? gp_colorSelect : gp_colorUnselect; finalColor.a *= gpEditOpacity; } @@ -76,7 +56,7 @@ void main() gl_PointSize = sizeVertexGpencil * 2.0; if (is_point_dimmed) { - finalColor.rgb = clamp(colorUnselect.rgb + vec3(0.3), 0.0, 1.0); + finalColor.rgb = clamp(gp_colorUnselect.rgb + vec3(0.3), 0.0, 1.0); } if (doStrokeEndpoints && !doWeightColor) { @@ -103,7 +83,5 @@ void main() discard_vert(); } -#ifdef USE_WORLD_CLIP_PLANES - world_clip_planes_calc_clip_distance(world_pos); -#endif + view_clipping_distances(world_pos); } diff --git a/source/blender/draw/engines/overlay/shaders/infos/edit_mode_info.hh b/source/blender/draw/engines/overlay/shaders/infos/edit_mode_info.hh index a4a4753df38..16d5e03b59a 100644 --- a/source/blender/draw/engines/overlay/shaders/infos/edit_mode_info.hh +++ b/source/blender/draw/engines/overlay/shaders/infos/edit_mode_info.hh @@ -399,3 +399,70 @@ GPU_SHADER_CREATE_INFO(overlay_edit_lattice_wire_clipped) .additional_info("overlay_edit_lattice_wire", "drw_clipped"); /** \} */ + +/* -------------------------------------------------------------------- */ +/** \name Edit GPencil + * \{ */ + +GPU_SHADER_CREATE_INFO(overlay_edit_gpencil) + .typedef_source("overlay_shader_shared.h") + /* NOTE: Color already in Linear space. Which is what we want. */ + .define("srgbTarget", "false") + .vertex_in(0, Type::VEC3, "pos") + .vertex_in(1, Type::INT, "ma") + .vertex_in(2, Type::UINT, "vflag") + .vertex_in(3, Type::FLOAT, "weight") + .push_constant(Type::FLOAT, "normalSize") + .push_constant(Type::BOOL, "doMultiframe") + .push_constant(Type::BOOL, "doStrokeEndpoints") + .push_constant(Type::BOOL, "hideSelect") + .push_constant(Type::BOOL, "doWeightColor") + .push_constant(Type::FLOAT, "gpEditOpacity") + .push_constant(Type::VEC4, "gpEditColor") + .sampler(0, ImageType::FLOAT_1D, "weightTex") + .fragment_out(0, Type::VEC4, "fragColor") + .vertex_source("edit_gpencil_vert.glsl") + .additional_info("draw_mesh", "draw_globals"); + +GPU_SHADER_CREATE_INFO(overlay_edit_gpencil_wire) + .do_static_compilation(true) + .vertex_out(overlay_edit_smooth_color_iface) + .fragment_source("gpu_shader_3D_smooth_color_frag.glsl") + .additional_info("overlay_edit_gpencil"); + +GPU_SHADER_CREATE_INFO(overlay_edit_gpencil_wire_clipped) + .do_static_compilation(true) + .additional_info("overlay_edit_gpencil_wire", "drw_clipped"); + +GPU_SHADER_CREATE_INFO(overlay_edit_gpencil_point) + .do_static_compilation(true) + .define("USE_POINTS") + .vertex_out(overlay_edit_flat_color_iface) + .fragment_source("gpu_shader_point_varying_color_frag.glsl") + .additional_info("overlay_edit_gpencil"); + +GPU_SHADER_CREATE_INFO(overlay_edit_gpencil_point_clipped) + .do_static_compilation(true) + .additional_info("overlay_edit_gpencil_point", "drw_clipped"); + +/* TODO(fclem): Refactor this to take list of point instead of drawing 1 point per drawcall. */ +GPU_SHADER_CREATE_INFO(overlay_edit_gpencil_guide_point) + .do_static_compilation(true) + /* NOTE: Color already in Linear space. Which is what we want. */ + .define("srgbTarget", "false") + .vertex_in(0, Type::VEC3, "pos") + .vertex_in(1, Type::INT, "data") + .vertex_out(overlay_edit_flat_color_iface) + .push_constant(Type::VEC3, "pPosition") + .push_constant(Type::FLOAT, "pSize") + .push_constant(Type::VEC4, "pColor") + .fragment_out(0, Type::VEC4, "fragColor") + .vertex_source("edit_gpencil_guide_vert.glsl") + .fragment_source("gpu_shader_point_varying_color_frag.glsl") + .additional_info("draw_mesh", "draw_globals"); + +GPU_SHADER_CREATE_INFO(overlay_edit_gpencil_guide_point_clipped) + .do_static_compilation(true) + .additional_info("overlay_edit_gpencil_guide_point", "drw_clipped"); + +/** \} */ |