Fix cycles issue when NaN is used for RGB ramp, can access array out of bounds then.

OSL noise() function is generating NaN's in certain cases, fix for that goes to our
OSL branch.

Also add missing minimum weight and max closure checks to OSL, forgot to add these
when fixing another bug.
This commit is contained in:
Brecht Van Lommel
2012-12-03 12:21:44 +00:00
parent f00a49baaa
commit 41f98978e3
3 changed files with 24 additions and 12 deletions

View File

@@ -150,13 +150,14 @@ static void flatten_surface_closure_tree(ShaderData *sd, bool no_glossy,
/* sample weight */
float sample_weight = fabsf(average(weight));
sd->flag |= bsdf->shaderdata_flag();
sc.sample_weight = sample_weight;
sc.type = bsdf->shaderclosure_type();
/* add */
sd->closure[sd->num_closure++] = sc;
if(sc.sample_weight > 1e-5f && sd->num_closure < MAX_CLOSURE) {
sd->closure[sd->num_closure++] = sc;
sd->flag |= bsdf->shaderdata_flag();
}
break;
}
case OSL::ClosurePrimitive::Emissive: {
@@ -170,9 +171,10 @@ static void flatten_surface_closure_tree(ShaderData *sd, bool no_glossy,
sc.type = CLOSURE_EMISSION_ID;
/* flag */
sd->flag |= SD_EMISSION;
sd->closure[sd->num_closure++] = sc;
if(sd->num_closure < MAX_CLOSURE) {
sd->closure[sd->num_closure++] = sc;
sd->flag |= SD_EMISSION;
}
break;
}
case AmbientOcclusion: {
@@ -185,8 +187,10 @@ static void flatten_surface_closure_tree(ShaderData *sd, bool no_glossy,
sc.sample_weight = sample_weight;
sc.type = CLOSURE_AMBIENT_OCCLUSION_ID;
sd->closure[sd->num_closure++] = sc;
sd->flag |= SD_AO;
if(sd->num_closure < MAX_CLOSURE) {
sd->closure[sd->num_closure++] = sc;
sd->flag |= SD_AO;
}
break;
}
case OSL::ClosurePrimitive::Holdout:
@@ -195,8 +199,11 @@ static void flatten_surface_closure_tree(ShaderData *sd, bool no_glossy,
sc.sample_weight = 0.0f;
sc.type = CLOSURE_HOLDOUT_ID;
sd->flag |= SD_HOLDOUT;
sd->closure[sd->num_closure++] = sc;
if(sd->num_closure < MAX_CLOSURE) {
sd->closure[sd->num_closure++] = sc;
sd->flag |= SD_HOLDOUT;
}
break;
case OSL::ClosurePrimitive::BSSRDF:
case OSL::ClosurePrimitive::Debug:
@@ -334,7 +341,8 @@ static void flatten_volume_closure_tree(ShaderData *sd,
sc.type = CLOSURE_VOLUME_ID;
/* add */
sd->closure[sd->num_closure++] = sc;
if(sc.sample_weight > 1e-5f && sd->num_closure < MAX_CLOSURE)
sd->closure[sd->num_closure++] = sc;
break;
}
case OSL::ClosurePrimitive::Holdout:

View File

@@ -29,7 +29,10 @@ shader node_rgb_ramp(
{
float f = clamp(Fac, 0.0, 1.0) * (RAMP_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;
float t = f - (float)i;
Color = ramp_color[i];

View File

@@ -25,7 +25,8 @@ __device float4 rgb_ramp_lookup(KernelGlobals *kg, int offset, float f)
{
f = clamp(f, 0.0f, 1.0f)*(RAMP_TABLE_SIZE-1);
int i = (int)f;
/* clamp int as well in case of NaN */
int i = clamp((int)f, 0, RAMP_TABLE_SIZE-1);
float t = f - (float)i;
float4 a = fetch_node_float(kg, offset+i);