Code refactor: use dynamic shader node array lengths now that OSL supports them.

This commit is contained in:
Brecht Van Lommel
2016-05-08 01:54:35 +02:00
parent 93e4ae84ad
commit 08670d3b81
13 changed files with 106 additions and 166 deletions

View File

@@ -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,