summaryrefslogtreecommitdiffstats
path: root/math.cginc
diff options
context:
space:
mode:
Diffstat (limited to 'math.cginc')
-rwxr-xr-xmath.cginc9
1 files changed, 9 insertions, 0 deletions
diff --git a/math.cginc b/math.cginc
index fa38553..c2ae26e 100755
--- a/math.cginc
+++ b/math.cginc
@@ -240,4 +240,13 @@ float voronoi_edge_distance(float3 x) {
return (d2 - d1) / (2.0 * max(1e-4, length(p2 - p1)));
}
+float median(float3 x) {
+ // Get the min and max.
+ float x_min= min(min(x.r, x.g), x.b);
+ float x_max = max(max(x.r, x.g), x.b);
+
+ // Compute (x.r + x.g + x.b) - (x_min + x_max). This gives us the median.
+ return (x.r + x.g + x.b) - (x_min + x_max);
+}
+
#endif // __MATH_INC