From da7ddb69e9f30d8bb480fb991a17b01113ad36ec Mon Sep 17 00:00:00 2001 From: Thomas Dinges Date: Fri, 5 Feb 2016 00:02:35 +0100 Subject: [PATCH] Cycles / OSL: Updare stdosl.h to 1.7.1. This updates our file to OSL 1.7.1, which comes with some new inbuilt features: - linearstep() - smooth_linearstep() - hash() - getchar() --- intern/cycles/kernel/shaders/stdosl.h | 32 ++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/intern/cycles/kernel/shaders/stdosl.h b/intern/cycles/kernel/shaders/stdosl.h index acf3ae8b1c7..8d5d3746caf 100644 --- a/intern/cycles/kernel/shaders/stdosl.h +++ b/intern/cycles/kernel/shaders/stdosl.h @@ -433,6 +433,35 @@ normal step (normal edge, normal x) BUILTIN; float step (float edge, float x) BUILTIN; float smoothstep (float edge0, float edge1, float x) BUILTIN; +float linearstep (float edge0, float edge1, float x) { + float result; + if (edge0 != edge1) { + float xclamped = clamp (x, edge0, edge1); + result = (xclamped - edge0) / (edge1 - edge0); + } else { // special case: edges coincide + result = step (edge0, x); + } + return result; +} + +float smooth_linearstep (float edge0, float edge1, float x_, float eps_) { + float result; + if (edge0 != edge1) { + float rampup (float x, float r) { return 0.5/r * x*x; } + float width_inv = 1.0 / (edge1 - edge0); + float eps = eps_ * width_inv; + float x = (x_ - edge0) * width_inv; + if (x <= -eps) result = 0; + else if (x >= eps && x <= 1.0-eps) result = x; + else if (x >= 1.0+eps) result = 1; + else if (x < eps) result = rampup (x+eps, 2.0*eps); + else /* if (x < 1.0+eps) */ result = 1.0 - rampup (1.0+eps - x, 2.0*eps); + } else { + result = step (edge0, x_); + } + return result; +} + float aastep (float edge, float s, float dedge, float ds) { // Box filtered AA step float width = fabs(dedge) + fabs(ds); @@ -455,8 +484,9 @@ float aastep (float edge, float s) { // String functions - int strlen (string s) BUILTIN; +int hash (string s) BUILTIN; +int getchar (string s, int index) BUILTIN; int startswith (string s, string prefix) BUILTIN; int endswith (string s, string suffix) BUILTIN; string substr (string s, int start, int len) BUILTIN;