diff options
author | Jeroen Bakker <j.bakker@atmind.nl> | 2018-09-25 19:19:59 +0300 |
---|---|---|
committer | Alexander Gavrilov <angavrilov@gmail.com> | 2018-09-27 17:33:33 +0300 |
commit | 3da46a8d8df26d6fe5b9289ae7ebfe01f1deeda8 (patch) | |
tree | e752806eb0db2c61f4592435a1173439ef534cbb /source/blender/draw/intern/draw_common.c | |
parent | 6791d95b1db8a2419b9534e95ea7c73c1cb4ff62 (diff) |
Implement a new dedicated weight painting shader.
Move the weight paint drawing to the fragment shader. The shader
uses a texture that uses the U.coba_weight custom color band, or
an internal color band.
In addition to actual weights, the shader has to display two
alert colors: missing vertex group, and zero weight. The zero
weight alert has to be blended with regular weight colors,
so that a single alert vertex surrounded by weighted ones is
still visible.
Reviewers: campbellbarton, fclem
Differential Revision: https://developer.blender.org/D3675
Diffstat (limited to 'source/blender/draw/intern/draw_common.c')
-rw-r--r-- | source/blender/draw/intern/draw_common.c | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/source/blender/draw/intern/draw_common.c b/source/blender/draw/intern/draw_common.c index eeaa204a252..faa4d980cd1 100644 --- a/source/blender/draw/intern/draw_common.c +++ b/source/blender/draw/intern/draw_common.c @@ -47,6 +47,12 @@ GlobalsUboStorage ts; struct GPUUniformBuffer *globals_ubo = NULL; struct GPUTexture *globals_ramp = NULL; +struct GPUTexture *globals_weight_ramp = NULL; + +static bool weight_ramp_custom = false; +static ColorBand weight_ramp_copy; + +static struct GPUTexture* DRW_create_weight_colorramp_texture(void); void DRW_globals_update(void) { @@ -63,6 +69,8 @@ void DRW_globals_update(void) UI_GetThemeColor4fv(TH_EMPTY, ts.colorEmpty); UI_GetThemeColor4fv(TH_VERTEX, ts.colorVertex); UI_GetThemeColor4fv(TH_VERTEX_SELECT, ts.colorVertexSelect); + UI_GetThemeColor4fv(TH_VERTEX_UNREFERENCED, ts.colorVertexUnreferenced); + UI_COLOR_RGBA_FROM_U8(0xB0, 0x00, 0xB0, 0xFF, ts.colorVertexMissingData); UI_GetThemeColor4fv(TH_EDITMESH_ACTIVE, ts.colorEditMeshActive); UI_GetThemeColor4fv(TH_EDGE_SELECT, ts.colorEdgeSelect); @@ -174,6 +182,21 @@ void DRW_globals_update(void) globals_ramp = GPU_texture_create_1D(col_size, GPU_RGBA8, colors, NULL); MEM_freeN(colors); + + /* Weight Painting color ramp texture */ + bool user_weight_ramp = (U.flag & USER_CUSTOM_RANGE) != 0; + + if (weight_ramp_custom != user_weight_ramp || + (user_weight_ramp && memcmp(&weight_ramp_copy, &U.coba_weight, sizeof(ColorBand)) != 0)) { + DRW_TEXTURE_FREE_SAFE(globals_weight_ramp); + } + + if (globals_weight_ramp == NULL) { + weight_ramp_custom = user_weight_ramp; + memcpy(&weight_ramp_copy, &U.coba_weight, sizeof(ColorBand)); + + globals_weight_ramp = DRW_create_weight_colorramp_texture(); + } } /* ********************************* SHGROUP ************************************* */ @@ -924,3 +947,36 @@ bool DRW_object_axis_orthogonal_to_view(Object *ob, int axis) return false; } + +static void DRW_evaluate_weight_to_color(float *result, float weight) +{ + if (U.flag & USER_CUSTOM_RANGE) + { + BKE_colorband_evaluate(&U.coba_weight, weight, result); + } + else { + /* Use gamma correction to even out the color bands: + * increasing widens yellow/cyan vs red/green/blue. + * Gamma 1.0 produces the original 2.79 color ramp. */ + const float gamma = 1.5f; + float hsv[3] = { (2.0f / 3.0f) * (1.0f - weight), 1.0f, pow(0.5f + 0.5f * weight, gamma) }; + + hsv_to_rgb_v(hsv, result); + + for (int i = 0; i < 3; i++) { + result[i] = pow(result[i], 1.0f/gamma); + } + } +} + +static GPUTexture* DRW_create_weight_colorramp_texture(void) +{ + char error[256]; + float pixels[256 * 4]; + for (int i = 0 ; i < 256 ; i ++) { + DRW_evaluate_weight_to_color(&pixels[i*4], i / 255.0f); + pixels[i*4 + 3] = 1.0f; + } + + return GPU_texture_create_1D(256, GPU_RGBA8, pixels, error); +} |