diff options
Diffstat (limited to 'math.cginc')
| -rwxr-xr-x | math.cginc | 9 |
1 files changed, 9 insertions, 0 deletions
@@ -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 |
