Changeset View
Changeset View
Standalone View
Standalone View
source/blender/draw/intern/draw_common.c
| Show First 20 Lines • Show All 916 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 = 2.0f; | |||||
| 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… | |||||
| GPUTexture* DRW_create_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; | |||||
| } | |||||
| GPUTexture *result = GPU_texture_create_1D(256, GPU_RGBA8, pixels, error); | |||||
| return result; | |||||
| } | |||||
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.