Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPablo Dobarro <pablodp606@gmail.com>2020-02-19 21:11:47 +0300
committerPablo Dobarro <pablodp606@gmail.com>2020-02-19 21:12:46 +0300
commit05fd2acf895847c51d8c02166a87d9fa50def39c (patch)
tree0b0eb65f52501288f897ca1ef4eab7f29d412389
parent2df040ed58fb9e80ae69f50262bb702f50f0d71f (diff)
Theme: Radial gradient background and enum for gradient type
This commit replaces the "Use Gradient" checkbox theme option with an enum and implements a radial background. Whith this change, it should be easier to implemet other types of more complex background types, like a world space oriented gradient. Reviewed By: billreynish, fclem, brecht Differential Revision: https://developer.blender.org/D6825
-rw-r--r--source/blender/draw/engines/overlay/overlay_background.c16
-rw-r--r--source/blender/draw/engines/overlay/shaders/background_frag.glsl21
-rw-r--r--source/blender/editors/include/UI_resources.h2
-rw-r--r--source/blender/editors/interface/resources.c4
-rw-r--r--source/blender/makesdna/DNA_userdef_types.h10
-rw-r--r--source/blender/makesdna/intern/dna_rename_defs.h1
-rw-r--r--source/blender/makesrna/intern/rna_userdef.c27
7 files changed, 67 insertions, 14 deletions
diff --git a/source/blender/draw/engines/overlay/overlay_background.c b/source/blender/draw/engines/overlay/overlay_background.c
index d98a9066a8e..880f5c49b3e 100644
--- a/source/blender/draw/engines/overlay/overlay_background.c
+++ b/source/blender/draw/engines/overlay/overlay_background.c
@@ -30,6 +30,7 @@
#define BG_SOLID 0
#define BG_GRADIENT 1
#define BG_CHECKER 2
+#define BG_RADIAL 3
void OVERLAY_background_cache_init(OVERLAY_Data *vedata)
{
@@ -67,11 +68,18 @@ void OVERLAY_background_cache_init(OVERLAY_Data *vedata)
copy_v3_v3(color_override, v3d->shading.background_color);
color_override[3] = 1.0f;
}
- else if (UI_GetThemeValue(TH_SHOW_BACK_GRAD)) {
- background_type = BG_GRADIENT;
- }
else {
- background_type = BG_SOLID;
+ switch (UI_GetThemeValue(TH_BACKGROUND_TYPE)) {
+ case TH_BACKGROUND_SINGLE_COLOR:
+ background_type = BG_SOLID;
+ break;
+ case TH_BACKGROUND_GRADIENT_LINEAR:
+ background_type = BG_GRADIENT;
+ break;
+ case TH_BACKGROUND_GRADIENT_RADIAL:
+ background_type = BG_RADIAL;
+ break;
+ }
}
DRWState state = DRW_STATE_WRITE_COLOR | DRW_STATE_BLEND_BACKGROUND;
diff --git a/source/blender/draw/engines/overlay/shaders/background_frag.glsl b/source/blender/draw/engines/overlay/shaders/background_frag.glsl
index 737c3acb438..60fa83e1695 100644
--- a/source/blender/draw/engines/overlay/shaders/background_frag.glsl
+++ b/source/blender/draw/engines/overlay/shaders/background_frag.glsl
@@ -12,6 +12,8 @@ out vec4 fragColor;
#define BG_SOLID 0
#define BG_GRADIENT 1
#define BG_CHECKER 2
+#define BG_RADIAL 3
+#define SQRT2 1.4142135623730950488
/* 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))
@@ -38,6 +40,8 @@ void main()
float depth = texture(depthBuffer, uvcoordsvar.st).r;
vec3 bg_col;
+ vec3 col_high;
+ vec3 col_low;
switch (bgType) {
case BG_SOLID:
@@ -45,14 +49,27 @@ void main()
break;
case BG_GRADIENT:
/* XXX do interpolation in a non-linear space to have a better visual result. */
- vec3 col_high = pow(colorBackground.rgb, vec3(1.0 / 2.2));
- vec3 col_low = pow(colorBackgroundGradient.rgb, vec3(1.0 / 2.2));
+ col_high = pow(colorBackground.rgb, vec3(1.0 / 2.2));
+ col_low = pow(colorBackgroundGradient.rgb, vec3(1.0 / 2.2));
bg_col = mix(col_low, col_high, uvcoordsvar.t);
/* Convert back to linear. */
bg_col = pow(bg_col, vec3(2.2));
/* Dither to hide low precision buffer. (Could be improved) */
bg_col += dither();
break;
+ case BG_RADIAL:
+ /* Do interpolation in a non-linear space to have a better visual result. */
+ col_high = pow(colorBackground.rgb, vec3(1.0 / 2.2));
+ 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);
+
+ /* Convert back to linear. */
+ bg_col = pow(bg_col, vec3(2.2));
+ /* Dither to hide low precision buffer. (Could be improved) */
+ bg_col += dither();
+ break;
case BG_CHECKER:
float size = 8.0 * sizePixel;
ivec2 p = ivec2(floor(gl_FragCoord.xy / size));
diff --git a/source/blender/editors/include/UI_resources.h b/source/blender/editors/include/UI_resources.h
index 1e6e46cbe71..e4b11977214 100644
--- a/source/blender/editors/include/UI_resources.h
+++ b/source/blender/editors/include/UI_resources.h
@@ -309,7 +309,7 @@ typedef enum ThemeColorID {
TH_GIZMO_A,
TH_GIZMO_B,
- TH_SHOW_BACK_GRAD,
+ TH_BACKGROUND_TYPE,
TH_INFO_SELECTED,
TH_INFO_SELECTED_TEXT,
diff --git a/source/blender/editors/interface/resources.c b/source/blender/editors/interface/resources.c
index 3aede744115..4a6ce59de9b 100644
--- a/source/blender/editors/interface/resources.c
+++ b/source/blender/editors/interface/resources.c
@@ -196,9 +196,9 @@ const uchar *UI_ThemeGetColorPtr(bTheme *btheme, int spacetype, int colorid)
cp = ts->back_grad;
break;
- case TH_SHOW_BACK_GRAD:
+ case TH_BACKGROUND_TYPE:
cp = &setting;
- setting = ts->show_back_grad;
+ setting = ts->background_type;
break;
case TH_TEXT:
if (theme_regionid == RGN_TYPE_WINDOW) {
diff --git a/source/blender/makesdna/DNA_userdef_types.h b/source/blender/makesdna/DNA_userdef_types.h
index cd67bb3d25b..87018c8284d 100644
--- a/source/blender/makesdna/DNA_userdef_types.h
+++ b/source/blender/makesdna/DNA_userdef_types.h
@@ -214,7 +214,7 @@ typedef struct ThemeSpace {
unsigned char back[4];
unsigned char back_grad[4];
- char show_back_grad;
+ char background_type;
char _pad0[3];
/** Panel title. */
@@ -424,6 +424,14 @@ typedef struct ThemeSpace {
} ThemeSpace;
+/* Viewport Background Gradient Types. */
+
+typedef enum eBackgroundGradientTypes {
+ TH_BACKGROUND_SINGLE_COLOR = 0,
+ TH_BACKGROUND_GRADIENT_LINEAR = 1,
+ TH_BACKGROUND_GRADIENT_RADIAL = 2,
+} eBackgroundGradientTypes;
+
/* set of colors for use as a custom color set for Objects/Bones wire drawing */
typedef struct ThemeWireColor {
unsigned char solid[4];
diff --git a/source/blender/makesdna/intern/dna_rename_defs.h b/source/blender/makesdna/intern/dna_rename_defs.h
index 404f483fde2..1ae7ad6bc70 100644
--- a/source/blender/makesdna/intern/dna_rename_defs.h
+++ b/source/blender/makesdna/intern/dna_rename_defs.h
@@ -109,3 +109,4 @@ DNA_STRUCT_RENAME_ELEM(bTheme, tstatusbar, space_statusbar)
DNA_STRUCT_RENAME_ELEM(bTheme, ttopbar, space_topbar)
DNA_STRUCT_RENAME_ELEM(bTheme, tuserpref, space_preferences)
DNA_STRUCT_RENAME_ELEM(bTheme, tv3d, space_view3d)
+DNA_STRUCT_RENAME_ELEM(ThemeSpace, show_back_grad, background_type)
diff --git a/source/blender/makesrna/intern/rna_userdef.c b/source/blender/makesrna/intern/rna_userdef.c
index 7d782efb7cf..571643a91f5 100644
--- a/source/blender/makesrna/intern/rna_userdef.c
+++ b/source/blender/makesrna/intern/rna_userdef.c
@@ -1306,6 +1306,25 @@ static void rna_def_userdef_theme_ui_panel(BlenderRNA *brna)
RNA_def_property_update(prop, 0, "rna_userdef_theme_update");
}
+const EnumPropertyItem rna_enum_userdef_theme_background_types_items[] = {
+ {TH_BACKGROUND_SINGLE_COLOR,
+ "Single Color",
+ 0,
+ "Single Color",
+ "Use a solid color as viewport background"},
+ {TH_BACKGROUND_GRADIENT_LINEAR,
+ "LINEAR",
+ 0,
+ "Linear Gradient",
+ "Use a screen space vertical linear gradient as viewport background"},
+ {TH_BACKGROUND_GRADIENT_RADIAL,
+ "RADIAL",
+ 0,
+ "Vignette",
+ "Use a radial gradient as viewport background"},
+ {0, NULL, 0, NULL, NULL},
+};
+
static void rna_def_userdef_theme_ui_gradient(BlenderRNA *brna)
{
/* Fake struct, keep this for compatible theme presets. */
@@ -1318,10 +1337,10 @@ static void rna_def_userdef_theme_ui_gradient(BlenderRNA *brna)
RNA_def_struct_ui_text(
srna, "Theme Background Color", "Theme settings for background colors and gradient");
- prop = RNA_def_property(srna, "show_grad", PROP_BOOLEAN, PROP_NONE);
- RNA_def_property_boolean_sdna(prop, NULL, "show_back_grad", 1);
- RNA_def_property_ui_text(
- prop, "Use Gradient", "Do a gradient for the background of the viewport working area");
+ prop = RNA_def_property(srna, "background_type", PROP_ENUM, PROP_NONE);
+ RNA_def_property_enum_sdna(prop, NULL, "background_type");
+ RNA_def_property_enum_items(prop, rna_enum_userdef_theme_background_types_items);
+ RNA_def_property_ui_text(prop, "Background Type", "Type of background in the 3D viewport");
RNA_def_property_update(prop, 0, "rna_userdef_theme_update");
prop = RNA_def_property(srna, "high_gradient", PROP_FLOAT, PROP_COLOR_GAMMA);