[Bf-blender-cvs] [4b7cdfe6f98] tmp-overlay-engine: Cleanup: Code readability/simplicity
Clément Foucault
noreply at git.blender.org
Wed Nov 27 14:49:34 CET 2019
Commit: 4b7cdfe6f98f182c5b9facacc86ad6a65943ee95
Author: Clément Foucault
Date: Wed Nov 27 15:19:52 2019 +0100
Branches: tmp-overlay-engine
https://developer.blender.org/rB4b7cdfe6f98f182c5b9facacc86ad6a65943ee95
Cleanup: Code readability/simplicity
===================================================================
M source/blender/draw/engines/overlay/overlay_armature.c
M source/blender/draw/intern/shaders/common_view_lib.glsl
===================================================================
diff --git a/source/blender/draw/engines/overlay/overlay_armature.c b/source/blender/draw/engines/overlay/overlay_armature.c
index 0965f6d05c6..fc448a48735 100644
--- a/source/blender/draw/engines/overlay/overlay_armature.c
+++ b/source/blender/draw/engines/overlay/overlay_armature.c
@@ -295,18 +295,26 @@ static void bone_instance_data_set_angle_minmax(BoneInstanceData *data,
data->amax_b = amaxz;
}
+/* Encode 2 units float with byte precision into a float. */
+static float encode_2f_to_float(float a, float b)
+{
+ CLAMP(a, 0.0f, 1.0f);
+ CLAMP(b, 0.0f, 2.0f); /* Can go up to 2. Needed for wire size. */
+ return (float)((int)(a * 255) | ((int)(b * 255) << 8));
+}
+
void OVERLAY_bone_instance_data_set_color_hint(BoneInstanceData *data, const float hint_color[4])
{
/* Encoded color into 2 floats to be able to use the obmat to color the custom bones. */
- data->color_hint_a = (hint_color[0] * 254.0f / 255.0f) + floorf(hint_color[1] * 255.0f);
- data->color_hint_b = (hint_color[2] * 254.0f / 255.0f) + floorf(hint_color[3] * 255.0f);
+ data->color_hint_a = encode_2f_to_float(hint_color[0], hint_color[1]);
+ data->color_hint_b = encode_2f_to_float(hint_color[2], hint_color[3]);
}
void OVERLAY_bone_instance_data_set_color(BoneInstanceData *data, const float bone_color[4])
{
/* Encoded color into 2 floats to be able to use the obmat to color the custom bones. */
- data->color_a = (bone_color[0] * 254.0f / 255.0f) + floorf(bone_color[1] * 255.0f);
- data->color_b = (bone_color[2] * 254.0f / 255.0f) + floorf(bone_color[3] * 255.0f);
+ data->color_a = encode_2f_to_float(bone_color[0], bone_color[1]);
+ data->color_b = encode_2f_to_float(bone_color[2], bone_color[3]);
}
/* Octahedral */
diff --git a/source/blender/draw/intern/shaders/common_view_lib.glsl b/source/blender/draw/intern/shaders/common_view_lib.glsl
index 402183337a6..2f2125ad813 100644
--- a/source/blender/draw/intern/shaders/common_view_lib.glsl
+++ b/source/blender/draw/intern/shaders/common_view_lib.glsl
@@ -36,10 +36,13 @@ float mul_project_m4_v3_zfac(in vec3 co)
* TODO Split to an overlay lib. */
mat4 extract_matrix_packed_data(mat4 mat, out vec4 dataA, out vec4 dataB)
{
- const float div_a = 1.0;
- const float div_b = 1.0 / 255.0;
- dataA = vec4(fract(mat[0][3]), mat[0][3] * div_b, fract(mat[1][3]), mat[1][3] * div_b);
- dataB = vec4(fract(mat[2][3]), mat[2][3] * div_b, fract(mat[3][3]), mat[3][3] * div_b);
+ const float div = 1.0 / 255.0;
+ int a = int(mat[0][3]);
+ int b = int(mat[1][3]);
+ int c = int(mat[2][3]);
+ int d = int(mat[3][3]);
+ dataA = vec4(a & 0xFF, a >> 8, b & 0xFF, b >> 8) * div;
+ dataB = vec4(c & 0xFF, c >> 8, d & 0xFF, d >> 8) * div;
mat[0][3] = mat[1][3] = mat[2][3] = 0.0;
mat[3][3] = 1.0;
return mat;
More information about the Bf-blender-cvs
mailing list