Changeset View
Changeset View
Standalone View
Standalone View
source/blender/draw/intern/draw_common.c
| Show First 20 Lines • Show All 41 Lines • ▼ Show 20 Lines | |||||
| #endif | #endif | ||||
| #define UI_COLOR_RGBA_FROM_U8(r, g, b, a, v4) \ | #define UI_COLOR_RGBA_FROM_U8(r, g, b, a, v4) \ | ||||
| ARRAY_SET_ITEMS(v4, (float)r / 255.0f, (float)g / 255.0f, (float)b / 255.0f, (float)a / 255.0f) | ARRAY_SET_ITEMS(v4, (float)r / 255.0f, (float)g / 255.0f, (float)b / 255.0f, (float)a / 255.0f) | ||||
| /* Colors & Constant */ | /* Colors & Constant */ | ||||
| GlobalsUboStorage ts; | GlobalsUboStorage ts; | ||||
| struct GPUUniformBuffer *globals_ubo = NULL; | struct GPUUniformBuffer *globals_ubo = NULL; | ||||
| struct GPUTexture *globals_ramp = 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) | void DRW_globals_update(void) | ||||
| { | { | ||||
| UI_GetThemeColor4fv(TH_WIRE, ts.colorWire); | UI_GetThemeColor4fv(TH_WIRE, ts.colorWire); | ||||
| UI_GetThemeColor4fv(TH_WIRE_EDIT, ts.colorWireEdit); | UI_GetThemeColor4fv(TH_WIRE_EDIT, ts.colorWireEdit); | ||||
| UI_GetThemeColor4fv(TH_ACTIVE, ts.colorActive); | UI_GetThemeColor4fv(TH_ACTIVE, ts.colorActive); | ||||
| UI_GetThemeColor4fv(TH_SELECT, ts.colorSelect); | UI_GetThemeColor4fv(TH_SELECT, ts.colorSelect); | ||||
| UI_GetThemeColor4fv(TH_TRANSFORM, ts.colorTransform); | UI_GetThemeColor4fv(TH_TRANSFORM, ts.colorTransform); | ||||
| UI_COLOR_RGBA_FROM_U8(0x88, 0xFF, 0xFF, 155, ts.colorLibrarySelect); | UI_COLOR_RGBA_FROM_U8(0x88, 0xFF, 0xFF, 155, ts.colorLibrarySelect); | ||||
| UI_COLOR_RGBA_FROM_U8(0x55, 0xCC, 0xCC, 155, ts.colorLibrary); | UI_COLOR_RGBA_FROM_U8(0x55, 0xCC, 0xCC, 155, ts.colorLibrary); | ||||
| UI_GetThemeColor4fv(TH_LAMP, ts.colorLamp); | UI_GetThemeColor4fv(TH_LAMP, ts.colorLamp); | ||||
| UI_GetThemeColor4fv(TH_SPEAKER, ts.colorSpeaker); | UI_GetThemeColor4fv(TH_SPEAKER, ts.colorSpeaker); | ||||
| UI_GetThemeColor4fv(TH_CAMERA, ts.colorCamera); | UI_GetThemeColor4fv(TH_CAMERA, ts.colorCamera); | ||||
| UI_GetThemeColor4fv(TH_EMPTY, ts.colorEmpty); | UI_GetThemeColor4fv(TH_EMPTY, ts.colorEmpty); | ||||
| UI_GetThemeColor4fv(TH_VERTEX, ts.colorVertex); | UI_GetThemeColor4fv(TH_VERTEX, ts.colorVertex); | ||||
| UI_GetThemeColor4fv(TH_VERTEX_SELECT, ts.colorVertexSelect); | UI_GetThemeColor4fv(TH_VERTEX_SELECT, ts.colorVertexSelect); | ||||
| UI_GetThemeColor4fv(TH_VERTEX_UNREFERENCED, ts.colorVertexUnreferenced); | |||||
| UI_COLOR_RGBA_FROM_U8(0xA0, 0x00, 0xA0, 0xFF, ts.colorVertexMissingData); | |||||
| UI_GetThemeColor4fv(TH_EDITMESH_ACTIVE, ts.colorEditMeshActive); | UI_GetThemeColor4fv(TH_EDITMESH_ACTIVE, ts.colorEditMeshActive); | ||||
| UI_GetThemeColor4fv(TH_EDGE_SELECT, ts.colorEdgeSelect); | UI_GetThemeColor4fv(TH_EDGE_SELECT, ts.colorEdgeSelect); | ||||
| UI_GetThemeColor4fv(TH_EDGE_SEAM, ts.colorEdgeSeam); | UI_GetThemeColor4fv(TH_EDGE_SEAM, ts.colorEdgeSeam); | ||||
| UI_GetThemeColor4fv(TH_EDGE_SHARP, ts.colorEdgeSharp); | UI_GetThemeColor4fv(TH_EDGE_SHARP, ts.colorEdgeSharp); | ||||
| UI_GetThemeColor4fv(TH_EDGE_CREASE, ts.colorEdgeCrease); | UI_GetThemeColor4fv(TH_EDGE_CREASE, ts.colorEdgeCrease); | ||||
| UI_GetThemeColor4fv(TH_EDGE_BEVEL, ts.colorEdgeBWeight); | UI_GetThemeColor4fv(TH_EDGE_BEVEL, ts.colorEdgeBWeight); | ||||
| UI_GetThemeColor4fv(TH_EDGE_FACESEL, ts.colorEdgeFaceSelect); | UI_GetThemeColor4fv(TH_EDGE_FACESEL, ts.colorEdgeFaceSelect); | ||||
| ▲ Show 20 Lines • Show All 93 Lines • ▼ Show 20 Lines | #endif | ||||
| BKE_colorband_evaluate_table_rgba(&ramp, &colors, &col_size); | BKE_colorband_evaluate_table_rgba(&ramp, &colors, &col_size); | ||||
| if (globals_ramp) { | if (globals_ramp) { | ||||
| GPU_texture_free(globals_ramp); | GPU_texture_free(globals_ramp); | ||||
| } | } | ||||
| globals_ramp = GPU_texture_create_1D(col_size, GPU_RGBA8, colors, NULL); | globals_ramp = GPU_texture_create_1D(col_size, GPU_RGBA8, colors, NULL); | ||||
| MEM_freeN(colors); | 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 ************************************* */ | /* ********************************* SHGROUP ************************************* */ | ||||
| extern char datatoc_animviz_mpath_lines_vert_glsl[]; | extern char datatoc_animviz_mpath_lines_vert_glsl[]; | ||||
| extern char datatoc_animviz_mpath_lines_geom_glsl[]; | extern char datatoc_animviz_mpath_lines_geom_glsl[]; | ||||
| extern char datatoc_animviz_mpath_points_vert_glsl[]; | extern char datatoc_animviz_mpath_points_vert_glsl[]; | ||||
| ▲ Show 20 Lines • Show All 734 Lines • ▼ Show 20 Lines | bool DRW_object_axis_orthogonal_to_view(Object *ob, int axis) | ||||
| BKE_object_rot_to_mat3(ob, ob_rot, true); | BKE_object_rot_to_mat3(ob, ob_rot, true); | ||||
| float dot = dot_v3v3(ob_rot[axis], invviewmat[2]); | float dot = dot_v3v3(ob_rot[axis], invviewmat[2]); | ||||
| if (fabsf(dot) < 1e-3) { | if (fabsf(dot) < 1e-3) { | ||||
| return true; | return true; | ||||
| } | } | ||||
| return false; | 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); | |||||
| } | |||||
| } | |||||
| } | |||||
angavrilov: This color ramp matches the original code, but when it is being continuously interpolated… | |||||
| 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); | |||||
| } | |||||
This color ramp matches the original code, but when it is being continuously interpolated through like in this new drawing approach, it becomes obvious that the color progression is actually not very smooth. For instance the yellow band looks quite sharp and narrow, while green is wide and gradual. I wonder if it is possible to tweak it to achieve a more even flow of colors.