commit c773354e904af2919f9077c712cdd12c1d8af395
parent cf7feb20bbfb4a197903a12f2db79dadad650d89
Author: Vincent Forest <vincent.forest@meso-star.com>
Date: Thu, 15 Sep 2016 15:40:35 +0200
Fix the ssf_bsdf_view_sample function
Ensure that the random numbers used to sample a component are in [0, 1[
Diffstat:
1 file changed, 7 insertions(+), 2 deletions(-)
diff --git a/src/ssf_bsdf_view.c b/src/ssf_bsdf_view.c
@@ -13,11 +13,16 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. */
+#define _POSIX_C_SOURCE 200112L /* nextafter */
+
#include "ssf.h"
#include "ssf_bsdf_view_c.h"
#include <rsys/mem_allocator.h>
+#include <float.h>
+#include <math.h>
+
/*******************************************************************************
* Helper functions
******************************************************************************/
@@ -145,8 +150,8 @@ ssf_bsdf_view_sample
}
/* Rescale the random number to reuse it (NOTE why?) */
- w = (u - view->cumulative[icomponent] )
- / (view->cumulative[icomponent+1] - view->cumulative[icomponent]);
+ w = (u - view->cumulative[icomponent] )/ nextafter
+ (view->cumulative[icomponent+1] - view->cumulative[icomponent], DBL_MAX);
/* Sample the component */
reflectivity = ssf_bxdf_sample(view->components[icomponent], w, v, wi, N, wo);