Overlay: port paint shaders to use 'GPUShaderCreateInfo'

Simple port.

Also a description of how each shader is used has been added.

NOTE: The shader created using `OVERLAY_shader_paint_vertcol` cannot be tested.
Apparently it is created but not used.

Reviewed By: fclem

Differential Revision: https://developer.blender.org/D14812
This commit is contained in:
Germano Cavalcante 2022-04-30 14:50:46 -03:00 committed by Germano Cavalcante
parent fc40356ed8
commit 57b4efc250
12 changed files with 227 additions and 161 deletions

View File

@ -89,15 +89,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_paint_face_vert_glsl[];
extern char datatoc_paint_point_vert_glsl[];
extern char datatoc_paint_texture_frag_glsl[];
extern char datatoc_paint_texture_vert_glsl[];
extern char datatoc_paint_vertcol_frag_glsl[];
extern char datatoc_paint_vertcol_vert_glsl[];
extern char datatoc_paint_weight_frag_glsl[];
extern char datatoc_paint_weight_vert_glsl[];
extern char datatoc_paint_wire_vert_glsl[];
extern char datatoc_particle_vert_glsl[];
extern char datatoc_particle_frag_glsl[];
extern char datatoc_sculpt_mask_vert_glsl[];
@ -958,17 +949,11 @@ GPUShader *OVERLAY_shader_outline_detect(void)
GPUShader *OVERLAY_shader_paint_face(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];
eGPUShaderConfig sh_cfg = draw_ctx->sh_cfg;
OVERLAY_Shaders *sh_data = &e_data.sh_data[sh_cfg];
if (!sh_data->paint_face) {
sh_data->paint_face = GPU_shader_create_from_arrays({
.vert = (const char *[]){sh_cfg->lib,
datatoc_common_view_lib_glsl,
datatoc_paint_face_vert_glsl,
NULL},
.frag = (const char *[]){datatoc_gpu_shader_uniform_color_frag_glsl, NULL},
.defs = (const char *[]){sh_cfg->def, NULL},
});
sh_data->paint_face = GPU_shader_create_from_info_name(
sh_cfg == GPU_SHADER_CFG_CLIPPED ? "overlay_paint_face_clipped" : "overlay_paint_face");
}
return sh_data->paint_face;
}
@ -976,18 +961,11 @@ GPUShader *OVERLAY_shader_paint_face(void)
GPUShader *OVERLAY_shader_paint_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];
eGPUShaderConfig sh_cfg = draw_ctx->sh_cfg;
OVERLAY_Shaders *sh_data = &e_data.sh_data[sh_cfg];
if (!sh_data->paint_point) {
sh_data->paint_point = GPU_shader_create_from_arrays({
.vert = (const char *[]){sh_cfg->lib,
datatoc_common_globals_lib_glsl,
datatoc_common_view_lib_glsl,
datatoc_paint_point_vert_glsl,
NULL},
.frag = (const char *[]){datatoc_gpu_shader_point_varying_color_frag_glsl, NULL},
.defs = (const char *[]){sh_cfg->def, NULL},
});
sh_data->paint_point = GPU_shader_create_from_info_name(
sh_cfg == GPU_SHADER_CFG_CLIPPED ? "overlay_paint_point_clipped" : "overlay_paint_point");
}
return sh_data->paint_point;
}
@ -995,19 +973,11 @@ GPUShader *OVERLAY_shader_paint_point(void)
GPUShader *OVERLAY_shader_paint_texture(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];
eGPUShaderConfig sh_cfg = draw_ctx->sh_cfg;
OVERLAY_Shaders *sh_data = &e_data.sh_data[sh_cfg];
if (!sh_data->paint_texture) {
sh_data->paint_texture = GPU_shader_create_from_arrays({
.vert = (const char *[]){sh_cfg->lib,
datatoc_common_view_lib_glsl,
datatoc_paint_texture_vert_glsl,
NULL},
.frag = (const char *[]){datatoc_common_colormanagement_lib_glsl,
datatoc_paint_texture_frag_glsl,
NULL},
.defs = (const char *[]){sh_cfg->def, NULL},
});
sh_data->paint_texture = GPU_shader_create_from_info_name(
sh_cfg ? "overlay_paint_texture_clipped" : "overlay_paint_texture");
}
return sh_data->paint_texture;
}
@ -1015,42 +985,27 @@ GPUShader *OVERLAY_shader_paint_texture(void)
GPUShader *OVERLAY_shader_paint_vertcol(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];
eGPUShaderConfig sh_cfg = draw_ctx->sh_cfg;
OVERLAY_Shaders *sh_data = &e_data.sh_data[sh_cfg];
if (!sh_data->paint_vertcol) {
sh_data->paint_vertcol = GPU_shader_create_from_arrays({
.vert = (const char *[]){sh_cfg->lib,
datatoc_common_globals_lib_glsl,
datatoc_common_view_lib_glsl,
datatoc_paint_vertcol_vert_glsl,
NULL},
.frag = (const char *[]){datatoc_common_globals_lib_glsl,
datatoc_paint_vertcol_frag_glsl,
NULL},
.defs = (const char *[]){sh_cfg->def, NULL},
});
sh_data->paint_vertcol = GPU_shader_create_from_info_name(
sh_cfg ? "overlay_paint_vertcol_clipped" : "overlay_paint_vertcol");
}
return sh_data->paint_vertcol;
}
GPUShader *OVERLAY_shader_paint_weight(const bool shading)
{
const char *info_name[2][2] = {
{"overlay_paint_weight", "overlay_paint_weight_fake_shading"},
{"overlay_paint_weight_clipped", "overlay_paint_weight_fake_shading_clipped"},
};
int index = shading ? 1 : 0;
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];
eGPUShaderConfig sh_cfg = draw_ctx->sh_cfg;
OVERLAY_Shaders *sh_data = &e_data.sh_data[sh_cfg];
if (!sh_data->paint_weight[index]) {
sh_data->paint_weight[index] = GPU_shader_create_from_arrays({
.vert = (const char *[]){sh_cfg->lib,
datatoc_common_globals_lib_glsl,
datatoc_common_view_lib_glsl,
datatoc_paint_weight_vert_glsl,
NULL},
.frag = (const char *[]){datatoc_common_globals_lib_glsl,
datatoc_paint_weight_frag_glsl,
NULL},
.defs = (const char *[]){sh_cfg->def, shading ? "#define FAKE_SHADING\n" : "", NULL},
});
sh_data->paint_weight[index] = GPU_shader_create_from_info_name(info_name[sh_cfg][index]);
}
return sh_data->paint_weight[index];
}
@ -1058,18 +1013,11 @@ GPUShader *OVERLAY_shader_paint_weight(const bool shading)
GPUShader *OVERLAY_shader_paint_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];
eGPUShaderConfig sh_cfg = draw_ctx->sh_cfg;
OVERLAY_Shaders *sh_data = &e_data.sh_data[sh_cfg];
if (!sh_data->paint_wire) {
sh_data->paint_wire = GPU_shader_create_from_arrays({
.vert = (const char *[]){sh_cfg->lib,
datatoc_common_globals_lib_glsl,
datatoc_common_view_lib_glsl,
datatoc_paint_wire_vert_glsl,
NULL},
.frag = (const char *[]){datatoc_gpu_shader_flat_color_frag_glsl, NULL},
.defs = (const char *[]){sh_cfg->def, NULL},
});
sh_data->paint_wire = GPU_shader_create_from_info_name(sh_cfg ? "overlay_paint_wire_clipped" :
"overlay_paint_wire");
}
return sh_data->paint_wire;
}

View File

@ -0,0 +1,180 @@
/* SPDX-License-Identifier: GPL-2.0-or-later */
#include "gpu_shader_create_info.hh"
/* -------------------------------------------------------------------- */
/** \name OVERLAY_shader_paint_face.
*
* Used for face selection mode in Weight, Vertex and Texture Paint.
* \{ */
GPU_SHADER_CREATE_INFO(overlay_paint_face)
.do_static_compilation(true)
.define("srgbTarget", "false") /* NOTE: Color already in Linear space. */
.vertex_in(0, Type::VEC3, "pos")
.vertex_in(1, Type::VEC4, "nor") /* Select flag on the 4th component. */
.push_constant(Type::VEC4, "color")
.fragment_out(0, Type::VEC4, "fragColor")
.vertex_source("paint_face_vert.glsl")
.fragment_source("gpu_shader_uniform_color_frag.glsl")
.additional_info("draw_modelmat");
GPU_SHADER_CREATE_INFO(overlay_paint_face_clipped)
.additional_info("overlay_paint_face")
.additional_info("drw_clipped")
.do_static_compilation(true);
/** \} */
/* -------------------------------------------------------------------- */
/** \name OVERLAY_shader_paint_point.
*
* Used for vertex selection mode in Weight and Vertex Paint.
* \{ */
GPU_SHADER_INTERFACE_INFO(overlay_overlay_paint_point_iface, "").smooth(Type::VEC4, "finalColor");
GPU_SHADER_CREATE_INFO(overlay_paint_point)
.do_static_compilation(true)
.vertex_in(0, Type::VEC3, "pos")
.vertex_in(1, Type::VEC4, "nor") /* Select flag on the 4th component. */
.vertex_out(overlay_overlay_paint_point_iface)
.fragment_out(0, Type::VEC4, "fragColor")
.vertex_source("paint_point_vert.glsl")
.fragment_source("gpu_shader_point_varying_color_frag.glsl")
.additional_info("draw_modelmat", "draw_globals");
GPU_SHADER_CREATE_INFO(overlay_paint_point_clipped)
.additional_info("overlay_paint_point")
.additional_info("drw_clipped")
.do_static_compilation(true);
/** \} */
/* -------------------------------------------------------------------- */
/** \name OVERLAY_shader_paint_texture.
*
* Used in Texture Paint mode for the Stencil Image Masking.
* \{ */
GPU_SHADER_INTERFACE_INFO(overlay_paint_texture_iface, "").smooth(Type::VEC2, "uv_interp");
GPU_SHADER_CREATE_INFO(overlay_paint_texture)
.do_static_compilation(true)
.vertex_in(0, Type::VEC3, "pos")
.vertex_in(1, Type::VEC2, "mu") /* Masking uv map. */
.vertex_out(overlay_paint_texture_iface)
.sampler(0, ImageType::FLOAT_2D, "maskImage")
.push_constant(Type::VEC3, "maskColor")
.push_constant(Type::FLOAT, "opacity") /* `1.0` by default. */
.push_constant(Type::BOOL, "maskInvertStencil")
.push_constant(Type::BOOL, "maskImagePremultiplied")
.fragment_out(0, Type::VEC4, "fragColor")
.vertex_source("paint_texture_vert.glsl")
.fragment_source("paint_texture_frag.glsl")
.additional_info("draw_modelmat");
GPU_SHADER_CREATE_INFO(overlay_paint_texture_clipped)
.additional_info("overlay_paint_texture")
.additional_info("drw_clipped")
.do_static_compilation(true);
/** \} */
/* -------------------------------------------------------------------- */
/** \name OVERLAY_shader_paint_vertcol.
*
* It should be used to draw a Vertex Paint overlay. But it is currently unreachable.
* \{ */
GPU_SHADER_INTERFACE_INFO(overlay_paint_vertcol_iface, "").smooth(Type::VEC3, "finalColor");
GPU_SHADER_CREATE_INFO(overlay_paint_vertcol)
.do_static_compilation(true)
.vertex_in(0, Type::VEC3, "pos")
.vertex_in(1, Type::VEC3, "ac") /* Active color. */
.vertex_out(overlay_paint_vertcol_iface)
.push_constant(Type::FLOAT, "opacity") /* `1.0` by default. */
.push_constant(Type::BOOL, "useAlphaBlend") /* `false` by default. */
.fragment_out(0, Type::VEC4, "fragColor")
.vertex_source("paint_vertcol_vert.glsl")
.fragment_source("paint_vertcol_frag.glsl")
.additional_info("draw_modelmat");
GPU_SHADER_CREATE_INFO(overlay_paint_vertcol_clipped)
.additional_info("overlay_paint_vertcol")
.additional_info("drw_clipped")
.do_static_compilation(true);
/** \} */
/* -------------------------------------------------------------------- */
/** \name OVERLAY_shader_paint_weight.
*
* Used to display Vertex Weights.
* `overlay paint weight` is for wireframe display mode.
* \{ */
GPU_SHADER_INTERFACE_INFO(overlay_paint_weight_iface, "")
.smooth(Type::VEC2, "weight_interp") /* (weight, alert) */
.smooth(Type::FLOAT, "color_fac");
GPU_SHADER_CREATE_INFO(overlay_paint_weight)
.do_static_compilation(true)
.vertex_in(0, Type::FLOAT, "weight")
.vertex_in(1, Type::VEC3, "pos")
.vertex_in(2, Type::VEC3, "nor")
.vertex_out(overlay_paint_weight_iface)
.sampler(0, ImageType::FLOAT_1D, "colorramp")
.push_constant(Type::FLOAT, "opacity") /* `1.0` by default. */
.push_constant(Type::BOOL, "drawContours") /* `false` by default. */
.fragment_out(0, Type::VEC4, "fragColor")
.vertex_source("paint_weight_vert.glsl")
.fragment_source("paint_weight_frag.glsl")
.additional_info("draw_modelmat", "draw_globals");
GPU_SHADER_CREATE_INFO(overlay_paint_weight_fake_shading)
.additional_info("overlay_paint_weight")
.define("FAKE_SHADING")
.push_constant(Type::VEC3, "light_dir")
.do_static_compilation(true);
GPU_SHADER_CREATE_INFO(overlay_paint_weight_clipped)
.additional_info("overlay_paint_weight")
.additional_info("drw_clipped")
.do_static_compilation(true);
GPU_SHADER_CREATE_INFO(overlay_paint_weight_fake_shading_clipped)
.additional_info("overlay_paint_weight_fake_shading")
.additional_info("drw_clipped")
.do_static_compilation(true);
/** \} */
/* -------------------------------------------------------------------- */
/** \name OVERLAY_shader_paint_wire.
*
* Used in face selection mode to display edges of selected faces in Weight, Vertex and Texture
* paint modes.
* \{ */
GPU_SHADER_INTERFACE_INFO(overlay_paint_wire_iface, "").flat(Type::VEC4, "finalColor");
GPU_SHADER_CREATE_INFO(overlay_paint_wire)
.do_static_compilation(true)
.define("srgbTarget", "false") /* NOTE: Color already in Linear space. */
.vertex_in(0, Type::VEC3, "pos")
.vertex_in(1, Type::VEC4, "nor") /* flag stored in w */
.vertex_out(overlay_paint_wire_iface)
.push_constant(Type::BOOL, "useSelect")
.fragment_out(0, Type::VEC4, "fragColor")
.vertex_source("paint_wire_vert.glsl")
.fragment_source("gpu_shader_flat_color_frag.glsl")
.additional_info("draw_modelmat", "draw_globals");
GPU_SHADER_CREATE_INFO(overlay_paint_wire_clipped)
.additional_info("overlay_paint_vertcol")
.additional_info("drw_clipped")
.do_static_compilation(true);
/** \} */

View File

@ -1,6 +1,5 @@
in vec3 pos;
in vec4 nor; /* select flag on the 4th component */
#pragma BLENDER_REQUIRE(common_view_clipping_lib.glsl)
#pragma BLENDER_REQUIRE(common_view_lib.glsl)
void main()
{
@ -17,8 +16,6 @@ void main()
gl_Position = vec4(-2.0, -2.0, -2.0, 1.0);
}
else {
#ifdef USE_WORLD_CLIP_PLANES
world_clip_planes_calc_clip_distance(world_pos);
#endif
view_clipping_distances(world_pos);
}
}

View File

@ -1,8 +1,5 @@
in vec3 pos;
in vec4 nor; /* select flag on the 4th component */
out vec4 finalColor;
#pragma BLENDER_REQUIRE(common_view_clipping_lib.glsl)
#pragma BLENDER_REQUIRE(common_view_lib.glsl)
void main()
{
@ -26,7 +23,5 @@ void main()
gl_PointSize = sizeVertex * 2.0;
#ifdef USE_WORLD_CLIP_PLANES
world_clip_planes_calc_clip_distance(world_pos);
#endif
view_clipping_distances(world_pos);
}

View File

@ -1,13 +1,4 @@
in vec2 uv_interp;
out vec4 fragColor;
uniform float opacity = 1.0;
uniform sampler2D maskImage;
uniform bool maskImagePremultiplied;
uniform vec3 maskColor;
uniform bool maskInvertStencil;
#pragma BLENDER_REQUIRE(common_colormanagement_lib.glsl)
void main()
{

View File

@ -1,8 +1,5 @@
in vec3 pos;
in vec2 mu; /* masking uv map */
out vec2 uv_interp;
#pragma BLENDER_REQUIRE(common_view_clipping_lib.glsl)
#pragma BLENDER_REQUIRE(common_view_lib.glsl)
void main()
{
@ -13,7 +10,5 @@ void main()
uv_interp = mu;
#ifdef USE_WORLD_CLIP_PLANES
world_clip_planes_calc_clip_distance(world_pos);
#endif
view_clipping_distances(world_pos);
}

View File

@ -1,11 +1,3 @@
in vec3 finalColor;
out vec4 fragColor;
uniform float opacity = 1.0;
uniform bool useAlphaBlend = false;
vec3 linear_to_srgb_attr(vec3 c)
{
c = max(c, vec3(0.0));

View File

@ -1,8 +1,5 @@
in vec3 pos;
in vec3 ac; /* active color */
out vec3 finalColor;
#pragma BLENDER_REQUIRE(common_view_clipping_lib.glsl)
#pragma BLENDER_REQUIRE(common_view_lib.glsl)
vec3 srgb_to_linear_attr(vec3 c)
{
@ -21,7 +18,5 @@ void main()
finalColor = srgb_to_linear_attr(ac);
#ifdef USE_WORLD_CLIP_PLANES
world_clip_planes_calc_clip_distance(world_pos);
#endif
view_clipping_distances(world_pos);
}

View File

@ -1,14 +1,3 @@
in vec2 weight_interp; /* (weight, alert) */
in float color_fac;
out vec4 fragColor;
uniform float opacity = 1.0;
uniform sampler1D colorramp;
uniform bool drawContours = false;
float contours(float value, float steps, float width_px, float max_rel_width, float gradient)
{
/* Minimum visible and minimum full strength line width in screen space for fade out. */

View File

@ -1,13 +1,5 @@
#ifdef FAKE_SHADING
uniform vec3 light_dir;
#endif
in float weight;
in vec3 pos;
in vec3 nor;
out vec2 weight_interp; /* (weight, alert) */
out float color_fac;
#pragma BLENDER_REQUIRE(common_view_clipping_lib.glsl)
#pragma BLENDER_REQUIRE(common_view_lib.glsl)
void main()
{
@ -29,7 +21,5 @@ void main()
color_fac = 1.0;
#endif
#ifdef USE_WORLD_CLIP_PLANES
world_clip_planes_calc_clip_distance(world_pos);
#endif
view_clipping_distances(world_pos);
}

View File

@ -1,10 +1,5 @@
uniform bool useSelect;
in vec3 pos;
in vec4 nor; /* flag stored in w */
flat out vec4 finalColor;
#pragma BLENDER_REQUIRE(common_view_clipping_lib.glsl)
#pragma BLENDER_REQUIRE(common_view_lib.glsl)
void main()
{
@ -32,7 +27,5 @@ void main()
finalColor = vec4(1.0, 1.0, 1.0, 0.3);
}
#ifdef USE_WORLD_CLIP_PLANES
world_clip_planes_calc_clip_distance(world_pos);
#endif
view_clipping_distances(world_pos);
}

View File

@ -448,6 +448,7 @@ set(SRC_SHADER_CREATE_INFOS
../draw/engines/overlay/shaders/infos/extra_info.hh
../draw/engines/overlay/shaders/infos/grid_info.hh
../draw/engines/overlay/shaders/infos/edit_mode_info.hh
../draw/engines/overlay/shaders/infos/paint_info.hh
../draw/engines/overlay/shaders/infos/volume_info.hh
../draw/engines/select/shaders/infos/select_id_info.hh
../draw/engines/workbench/shaders/infos/workbench_composite_info.hh