diff options
author | Brecht Van Lommel <brechtvanlommel@gmail.com> | 2016-05-08 02:54:35 +0300 |
---|---|---|
committer | Brecht Van Lommel <brechtvanlommel@gmail.com> | 2016-05-17 22:39:16 +0300 |
commit | 08670d3b8117cda608c178688f261e1204794a0d (patch) | |
tree | 4a82f0e7d2212bfc956619880d6b7cc168a2e7df /intern/cycles/kernel/shaders | |
parent | 93e4ae84ad31dc6a56fd249592b24007ea286ddc (diff) |
Code refactor: use dynamic shader node array lengths now that OSL supports them.
Diffstat (limited to 'intern/cycles/kernel/shaders')
-rw-r--r-- | intern/cycles/kernel/shaders/node_rgb_curves.osl | 16 | ||||
-rw-r--r-- | intern/cycles/kernel/shaders/node_rgb_ramp.osl | 9 | ||||
-rw-r--r-- | intern/cycles/kernel/shaders/node_vector_curves.osl | 16 | ||||
-rw-r--r-- | intern/cycles/kernel/shaders/oslutil.h | 3 |
4 files changed, 23 insertions, 21 deletions
diff --git a/intern/cycles/kernel/shaders/node_rgb_curves.osl b/intern/cycles/kernel/shaders/node_rgb_curves.osl index fc93dbd044b..8e208e8a8f7 100644 --- a/intern/cycles/kernel/shaders/node_rgb_curves.osl +++ b/intern/cycles/kernel/shaders/node_rgb_curves.osl @@ -17,8 +17,10 @@ #include "stdosl.h" #include "oslutil.h" -float ramp_lookup(color ramp[RAMP_TABLE_SIZE], float at, int component) +float ramp_lookup(color ramp[], float at, int component) { + int table_size = arraylength(ramp); + if (at < 0.0 || at > 1.0) { float t0, dy; if (at < 0.0) { @@ -27,19 +29,19 @@ float ramp_lookup(color ramp[RAMP_TABLE_SIZE], float at, int component) at = -at; } else { - t0 = ramp[RAMP_TABLE_SIZE - 1][component]; - dy = t0 - ramp[RAMP_TABLE_SIZE - 2][component]; + t0 = ramp[table_size - 1][component]; + dy = t0 - ramp[table_size - 2][component]; at = at - 1.0; } - return t0 + dy * at * (RAMP_TABLE_SIZE - 1); + return t0 + dy * at * (table_size - 1); } - float f = clamp(at, 0.0, 1.0) * (RAMP_TABLE_SIZE - 1); + float f = clamp(at, 0.0, 1.0) * (table_size - 1); /* clamp int as well in case of NaN */ int i = (int)f; if (i < 0) i = 0; - if (i >= RAMP_TABLE_SIZE) i = RAMP_TABLE_SIZE - 1; + if (i >= table_size) i = table_size - 1; float t = f - (float)i; float result = ramp[i][component]; @@ -51,7 +53,7 @@ float ramp_lookup(color ramp[RAMP_TABLE_SIZE], float at, int component) } shader node_rgb_curves( - color ramp[RAMP_TABLE_SIZE] = {0.0}, + color ramp[] = {0.0}, float min_x = 0.0, float max_x = 1.0, diff --git a/intern/cycles/kernel/shaders/node_rgb_ramp.osl b/intern/cycles/kernel/shaders/node_rgb_ramp.osl index 0202ba0bf79..2ab6b6778b7 100644 --- a/intern/cycles/kernel/shaders/node_rgb_ramp.osl +++ b/intern/cycles/kernel/shaders/node_rgb_ramp.osl @@ -18,20 +18,21 @@ #include "oslutil.h" shader node_rgb_ramp( - color ramp_color[RAMP_TABLE_SIZE] = {0.0}, - float ramp_alpha[RAMP_TABLE_SIZE] = {0.0}, + color ramp_color[] = {0.0}, + float ramp_alpha[] = {0.0}, int ramp_interpolate = 1, float Fac = 0.0, output color Color = 0.0, output float Alpha = 1.0) { - float f = clamp(Fac, 0.0, 1.0) * (RAMP_TABLE_SIZE - 1); + int table_size = arraylength(ramp_color); + float f = clamp(Fac, 0.0, 1.0) * (table_size - 1); /* clamp int as well in case of NaN */ int i = (int)f; if (i < 0) i = 0; - if (i >= RAMP_TABLE_SIZE) i = RAMP_TABLE_SIZE - 1; + if (i >= table_size) i = table_size - 1; float t = f - (float)i; Color = ramp_color[i]; diff --git a/intern/cycles/kernel/shaders/node_vector_curves.osl b/intern/cycles/kernel/shaders/node_vector_curves.osl index 4d4c28b57a2..cff4efe1d98 100644 --- a/intern/cycles/kernel/shaders/node_vector_curves.osl +++ b/intern/cycles/kernel/shaders/node_vector_curves.osl @@ -17,8 +17,10 @@ #include "stdosl.h" #include "oslutil.h" -float ramp_lookup(color ramp[RAMP_TABLE_SIZE], float at, int component) +float ramp_lookup(color ramp[], float at, int component) { + int table_size = arraylength(ramp); + if (at < 0.0 || at > 1.0) { float t0, dy; if (at < 0.0) { @@ -27,19 +29,19 @@ float ramp_lookup(color ramp[RAMP_TABLE_SIZE], float at, int component) at = -at; } else { - t0 = ramp[RAMP_TABLE_SIZE - 1][component]; - dy = t0 - ramp[RAMP_TABLE_SIZE - 2][component]; + t0 = ramp[table_size - 1][component]; + dy = t0 - ramp[table_size - 2][component]; at = at - 1.0; } - return t0 + dy * at * (RAMP_TABLE_SIZE - 1); + return t0 + dy * at * (table_size - 1); } - float f = clamp(at, 0.0, 1.0) * (RAMP_TABLE_SIZE - 1); + float f = clamp(at, 0.0, 1.0) * (table_size - 1); /* clamp int as well in case of NaN */ int i = (int)f; if (i < 0) i = 0; - if (i >= RAMP_TABLE_SIZE) i = RAMP_TABLE_SIZE - 1; + if (i >= table_size) i = table_size - 1; float t = f - (float)i; float result = ramp[i][component]; @@ -51,7 +53,7 @@ float ramp_lookup(color ramp[RAMP_TABLE_SIZE], float at, int component) } shader node_vector_curves( - color ramp[RAMP_TABLE_SIZE] = {0.0}, + color ramp[] = {0.0}, float min_x = 0.0, float max_x = 1.0, diff --git a/intern/cycles/kernel/shaders/oslutil.h b/intern/cycles/kernel/shaders/oslutil.h index d90900bc474..141e5d27e3a 100644 --- a/intern/cycles/kernel/shaders/oslutil.h +++ b/intern/cycles/kernel/shaders/oslutil.h @@ -33,9 +33,6 @@ #ifndef CCL_OSLUTIL_H #define CCL_OSLUTIL_H -/* NB: must match the value in kernel_types.h */ -#define RAMP_TABLE_SIZE 256 - // Return wireframe opacity factor [0, 1] given a geometry type in // ("triangles", "polygons" or "patches"), and a line_width in raster // or world space depending on the last (raster) boolean argument. |