diff options
author | Clément Foucault <foucault.clem@gmail.com> | 2022-05-01 00:54:52 +0300 |
---|---|---|
committer | Clément Foucault <foucault.clem@gmail.com> | 2022-05-01 00:54:52 +0300 |
commit | 86b37748a7e9d685c56fc47c7aa96fdf7947d75e (patch) | |
tree | 2371a41d3b7a3b9069cbebd694a3c2ae19bff5e3 /source/blender/draw | |
parent | 6e5877c189df5d6c2dfcaa44ba4c3c9a8b387998 (diff) |
Overlay: Port background shaders to use shaderCreateInfo
This should have no functional changes.
Diffstat (limited to 'source/blender/draw')
6 files changed, 39 insertions, 36 deletions
diff --git a/source/blender/draw/engines/overlay/overlay_background.c b/source/blender/draw/engines/overlay/overlay_background.c index 6a87658b57c..32bcd04e05b 100644 --- a/source/blender/draw/engines/overlay/overlay_background.c +++ b/source/blender/draw/engines/overlay/overlay_background.c @@ -12,13 +12,6 @@ #include "draw_manager_text.h" #include "overlay_private.h" -#define BG_SOLID 0 -#define BG_GRADIENT 1 -#define BG_CHECKER 2 -#define BG_RADIAL 3 -#define BG_SOLID_CHECKER 4 -#define BG_MASK 5 - void OVERLAY_background_cache_init(OVERLAY_Data *vedata) { OVERLAY_PassList *psl = vedata->psl; diff --git a/source/blender/draw/engines/overlay/overlay_shader.c b/source/blender/draw/engines/overlay/overlay_shader.c index c04a3218461..d01a2c2fa7f 100644 --- a/source/blender/draw/engines/overlay/overlay_shader.c +++ b/source/blender/draw/engines/overlay/overlay_shader.c @@ -238,11 +238,7 @@ GPUShader *OVERLAY_shader_background(void) { OVERLAY_Shaders *sh_data = &e_data.sh_data[0]; if (!sh_data->background) { - sh_data->background = GPU_shader_create_from_arrays({ - .vert = (const char *[]){datatoc_common_fullscreen_vert_glsl, NULL}, - .frag = - (const char *[]){datatoc_common_globals_lib_glsl, datatoc_background_frag_glsl, NULL}, - }); + sh_data->background = GPU_shader_create_from_info_name("overlay_background"); } return sh_data->background; } @@ -250,13 +246,8 @@ GPUShader *OVERLAY_shader_background(void) GPUShader *OVERLAY_shader_clipbound(void) { OVERLAY_Shaders *sh_data = &e_data.sh_data[0]; - const GPUShaderConfigData *sh_cfg = &GPU_shader_cfg_data[0]; if (!sh_data->clipbound) { - sh_data->clipbound = GPU_shader_create_from_arrays({ - .vert = (const char *[]){datatoc_common_view_lib_glsl, datatoc_clipbound_vert_glsl, NULL}, - .frag = (const char *[]){datatoc_gpu_shader_uniform_color_frag_glsl, NULL}, - .defs = (const char *[]){sh_cfg->def, NULL}, - }); + sh_data->clipbound = GPU_shader_create_from_info_name("overlay_clipbound"); } return sh_data->clipbound; } diff --git a/source/blender/draw/engines/overlay/overlay_shader_shared.h b/source/blender/draw/engines/overlay/overlay_shader_shared.h index 20b6adf09bb..268346d8355 100644 --- a/source/blender/draw/engines/overlay/overlay_shader_shared.h +++ b/source/blender/draw/engines/overlay/overlay_shader_shared.h @@ -11,6 +11,15 @@ typedef enum OVERLAY_GridBits OVERLAY_GridBits; typedef struct OVERLAY_GridData OVERLAY_GridData; #endif +/* TODO(fclem): Should eventually become OVERLAY_BackgroundType. + * But there is no uint push constant functions at the moment. */ +#define BG_SOLID 0 +#define BG_GRADIENT 1 +#define BG_CHECKER 2 +#define BG_RADIAL 3 +#define BG_SOLID_CHECKER 4 +#define BG_MASK 5 + enum OVERLAY_GridBits { SHOW_AXIS_X = (1 << 0), SHOW_AXIS_Y = (1 << 1), diff --git a/source/blender/draw/engines/overlay/shaders/background_frag.glsl b/source/blender/draw/engines/overlay/shaders/background_frag.glsl index 6b45b341ca4..b25dcae9fca 100644 --- a/source/blender/draw/engines/overlay/shaders/background_frag.glsl +++ b/source/blender/draw/engines/overlay/shaders/background_frag.glsl @@ -1,21 +1,6 @@ -uniform sampler2D colorBuffer; -uniform sampler2D depthBuffer; -uniform int bgType; -uniform vec4 colorOverride; - -in vec4 uvcoordsvar; - -out vec4 fragColor; - -#define BG_SOLID 0 -#define BG_GRADIENT 1 -#define BG_CHECKER 2 -#define BG_RADIAL 3 -#define BG_SOLID_CHECKER 4 -#define BG_MASK 5 -#define SQRT2 1.4142135623730950488 +#pragma BLENDER_REQUIRE(common_math_lib.glsl) /* 4x4 bayer matrix prepared for 8bit UNORM precision error. */ #define P(x) (((x + 0.5) * (1.0 / 16.0) - 0.5) * (1.0 / 255.0)) @@ -69,7 +54,7 @@ void main() col_low = pow(colorBackgroundGradient.rgb, vec3(1.0 / 2.2)); vec2 uv_n = uvcoordsvar.xy - 0.5; - bg_col = mix(col_high, col_low, length(uv_n) * SQRT2); + bg_col = mix(col_high, col_low, length(uv_n) * M_SQRT2); /* Convert back to linear. */ bg_col = pow(bg_col, vec3(2.2)); diff --git a/source/blender/draw/engines/overlay/shaders/clipbound_vert.glsl b/source/blender/draw/engines/overlay/shaders/clipbound_vert.glsl index 1bfa5dadc32..c065a66414f 100644 --- a/source/blender/draw/engines/overlay/shaders/clipbound_vert.glsl +++ b/source/blender/draw/engines/overlay/shaders/clipbound_vert.glsl @@ -1,5 +1,5 @@ -uniform vec3 boundbox[8]; +#pragma BLENDER_REQUIRE(common_view_lib.glsl) void main() { diff --git a/source/blender/draw/engines/overlay/shaders/infos/background_info.hh b/source/blender/draw/engines/overlay/shaders/infos/background_info.hh new file mode 100644 index 00000000000..c96d302d861 --- /dev/null +++ b/source/blender/draw/engines/overlay/shaders/infos/background_info.hh @@ -0,0 +1,25 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ + +#include "gpu_shader_create_info.hh" + +GPU_SHADER_CREATE_INFO(overlay_background) + .do_static_compilation(true) + .typedef_source("overlay_shader_shared.h") + .sampler(0, ImageType::FLOAT_2D, "colorBuffer") + .sampler(1, ImageType::DEPTH_2D, "depthBuffer") + .push_constant(Type::INT, "bgType") + .push_constant(Type::VEC4, "colorOverride") + .fragment_source("background_frag.glsl") + .fragment_out(0, Type::VEC4, "fragColor") + .additional_info("draw_fullscreen", "draw_globals"); + +GPU_SHADER_CREATE_INFO(overlay_clipbound) + .do_static_compilation(true) + /* NOTE: Color already in Linear space. Which is what we want. */ + .define("srgbTarget", "false") + .push_constant(Type::VEC4, "color") + .push_constant(Type::VEC3, "boundbox", 8) + .vertex_source("clipbound_vert.glsl") + .fragment_out(0, Type::VEC4, "fragColor") + .fragment_source("gpu_shader_uniform_color_frag.glsl") + .additional_info("draw_view"); |