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
This commit is contained in:
2020-02-19 19:11:47 +01:00
parent 2df040ed58
commit 05fd2acf89
7 changed files with 67 additions and 14 deletions

View File

@@ -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;

View File

@@ -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,9 +49,22 @@ 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) */