Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'source/blender/draw/engines/workbench/shaders/workbench_common_lib.glsl')
-rw-r--r--source/blender/draw/engines/workbench/shaders/workbench_common_lib.glsl27
1 files changed, 27 insertions, 0 deletions
diff --git a/source/blender/draw/engines/workbench/shaders/workbench_common_lib.glsl b/source/blender/draw/engines/workbench/shaders/workbench_common_lib.glsl
index 451d509eeee..b8c90162c51 100644
--- a/source/blender/draw/engines/workbench/shaders/workbench_common_lib.glsl
+++ b/source/blender/draw/engines/workbench/shaders/workbench_common_lib.glsl
@@ -49,6 +49,33 @@ vec2 workbench_normal_encode(vec3 n)
# define workbench_normal_decode(a) (a)
#endif /* WORKBENCH_ENCODE_NORMALS */
+/* Encoding into the alpha of a RGBA8 UNORM texture. */
+#define TARGET_BITCOUNT 8
+#define METALLIC_BITS 3 /* Metallic channel is less important. */
+#define ROUGHNESS_BITS (TARGET_BITCOUNT - METALLIC_BITS)
+#define TOTAL_BITS (METALLIC_BITS + ROUGHNESS_BITS)
+
+/* Encode 2 float into 1 with the desired precision. */
+float workbench_float_pair_encode(float v1, float v2)
+{
+ const int total_mask = ~(0xFFFFFFFF << TOTAL_BITS);
+ const int v1_mask = ~(0xFFFFFFFF << ROUGHNESS_BITS);
+ const int v2_mask = ~(0xFFFFFFFF << METALLIC_BITS);
+ int iv1 = int(v1 * float(v1_mask));
+ int iv2 = int(v2 * float(v2_mask)) << ROUGHNESS_BITS;
+ return float(iv1 | iv2) * (1.0 / float(total_mask));
+}
+
+void workbench_float_pair_decode(float data, out float v1, out float v2)
+{
+ const int total_mask = ~(0xFFFFFFFF << TOTAL_BITS);
+ const int v1_mask = ~(0xFFFFFFFF << ROUGHNESS_BITS);
+ const int v2_mask = ~(0xFFFFFFFF << METALLIC_BITS);
+ int idata = int(data * float(total_mask));
+ v1 = float(idata & v1_mask) * (1.0 / float(v1_mask));
+ v2 = float(idata >> ROUGHNESS_BITS) * (1.0 / float(v2_mask));
+}
+
float calculate_transparent_weight(float z, float alpha)
{
#if 0