From c15b13f78f359728a2b458126a907ff1a1b80365 Mon Sep 17 00:00:00 2001 From: Thomas Dinges Date: Thu, 27 Jun 2013 16:08:06 +0000 Subject: Cycles / Ramp closures: * Fix crash with negative values in Phong Ramp, and add some checks to survive INF and NAN values. Patch by Brecht and myself. --- intern/cycles/kernel/closure/bsdf_diffuse_ramp.h | 2 ++ intern/cycles/kernel/closure/bsdf_phong_ramp.h | 4 ++++ 2 files changed, 6 insertions(+) (limited to 'intern') diff --git a/intern/cycles/kernel/closure/bsdf_diffuse_ramp.h b/intern/cycles/kernel/closure/bsdf_diffuse_ramp.h index 579145bdd80..2e43e16693f 100644 --- a/intern/cycles/kernel/closure/bsdf_diffuse_ramp.h +++ b/intern/cycles/kernel/closure/bsdf_diffuse_ramp.h @@ -41,6 +41,8 @@ __device float3 bsdf_diffuse_ramp_get_color(const ShaderClosure *sc, const float float npos = pos * (float)(MAXCOLORS - 1); int ipos = float_to_int(npos); + if (ipos < 0) + return colors[0]; if (ipos >= (MAXCOLORS - 1)) return colors[MAXCOLORS - 1]; float offset = npos - (float)ipos; diff --git a/intern/cycles/kernel/closure/bsdf_phong_ramp.h b/intern/cycles/kernel/closure/bsdf_phong_ramp.h index b51d41486c7..1e332933287 100644 --- a/intern/cycles/kernel/closure/bsdf_phong_ramp.h +++ b/intern/cycles/kernel/closure/bsdf_phong_ramp.h @@ -41,6 +41,8 @@ __device float3 bsdf_phong_ramp_get_color(const ShaderClosure *sc, const float3 float npos = pos * (float)(MAXCOLORS - 1); int ipos = float_to_int(npos); + if (ipos < 0) + return colors[0]; if (ipos >= (MAXCOLORS - 1)) return colors[MAXCOLORS - 1]; float offset = npos - (float)ipos; @@ -49,6 +51,8 @@ __device float3 bsdf_phong_ramp_get_color(const ShaderClosure *sc, const float3 __device int bsdf_phong_ramp_setup(ShaderClosure *sc) { + sc->data0 = max(sc->data0, 0.0f); + sc->type = CLOSURE_BSDF_PHONG_RAMP_ID; return SD_BSDF | SD_BSDF_HAS_EVAL | SD_BSDF_GLOSSY; } -- cgit v1.2.3