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:
		@@ -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;
 | 
			
		||||
 
 | 
			
		||||
@@ -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) */
 | 
			
		||||
 
 | 
			
		||||
@@ -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,
 | 
			
		||||
 
 | 
			
		||||
@@ -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) {
 | 
			
		||||
 
 | 
			
		||||
@@ -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];
 | 
			
		||||
 
 | 
			
		||||
@@ -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)
 | 
			
		||||
 
 | 
			
		||||
@@ -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);
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user