diff options
author | Thomas Dinges <blender@dingto.org> | 2016-02-05 02:02:35 +0300 |
---|---|---|
committer | Thomas Dinges <blender@dingto.org> | 2016-02-05 02:05:26 +0300 |
commit | da7ddb69e9f30d8bb480fb991a17b01113ad36ec (patch) | |
tree | 58f96155d0323450320a51155b21691d38b9b9f9 /intern/cycles/kernel/shaders | |
parent | 208a49b1c35b024b2a99ae2d26494c7391808727 (diff) |
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()
Diffstat (limited to 'intern/cycles/kernel/shaders')
-rw-r--r-- | intern/cycles/kernel/shaders/stdosl.h | 32 |
1 files changed, 31 insertions, 1 deletions
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; |