diff options
author | Brecht Van Lommel <brechtvanlommel@pandora.be> | 2012-12-03 16:21:44 +0400 |
---|---|---|
committer | Brecht Van Lommel <brechtvanlommel@pandora.be> | 2012-12-03 16:21:44 +0400 |
commit | 41f98978e3430a7d38684d49891505bb954375aa (patch) | |
tree | a69caf8413332c0d359c7a873d86c77f16d3c4fc /intern/cycles | |
parent | f00a49baaaf4b2f8d8a6a6265255fa7085a79bf8 (diff) |
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.
Diffstat (limited to 'intern/cycles')
-rw-r--r-- | intern/cycles/kernel/osl/osl_shader.cpp | 30 | ||||
-rw-r--r-- | intern/cycles/kernel/shaders/node_rgb_ramp.osl | 3 | ||||
-rw-r--r-- | intern/cycles/kernel/svm/svm_ramp.h | 3 |
3 files changed, 24 insertions, 12 deletions
diff --git a/intern/cycles/kernel/osl/osl_shader.cpp b/intern/cycles/kernel/osl/osl_shader.cpp index 67a0e16419c..f72e4dd1384 100644 --- a/intern/cycles/kernel/osl/osl_shader.cpp +++ b/intern/cycles/kernel/osl/osl_shader.cpp @@ -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: diff --git a/intern/cycles/kernel/shaders/node_rgb_ramp.osl b/intern/cycles/kernel/shaders/node_rgb_ramp.osl index a128ebbd1cf..c7bb53bfefc 100644 --- a/intern/cycles/kernel/shaders/node_rgb_ramp.osl +++ b/intern/cycles/kernel/shaders/node_rgb_ramp.osl @@ -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]; diff --git a/intern/cycles/kernel/svm/svm_ramp.h b/intern/cycles/kernel/svm/svm_ramp.h index 55c2b3f6af4..c64413cbe84 100644 --- a/intern/cycles/kernel/svm/svm_ramp.h +++ b/intern/cycles/kernel/svm/svm_ramp.h @@ -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); |