[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [56490] trunk/blender/intern/cycles/kernel /closure/bsdf_microfacet.h: Fix for recent glossy BSDF fix, color ramp test file was rendering different.

Brecht Van Lommel brechtvanlommel at pandora.be
Fri May 3 15:17:29 CEST 2013


Revision: 56490
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=56490
Author:   blendix
Date:     2013-05-03 13:17:28 +0000 (Fri, 03 May 2013)
Log Message:
-----------
Fix for recent glossy BSDF fix, color ramp test file was rendering different.

Modified Paths:
--------------
    trunk/blender/intern/cycles/kernel/closure/bsdf_microfacet.h

Modified: trunk/blender/intern/cycles/kernel/closure/bsdf_microfacet.h
===================================================================
--- trunk/blender/intern/cycles/kernel/closure/bsdf_microfacet.h	2013-05-03 12:37:45 UTC (rev 56489)
+++ trunk/blender/intern/cycles/kernel/closure/bsdf_microfacet.h	2013-05-03 13:17:28 UTC (rev 56490)
@@ -78,7 +78,7 @@
 
 __device float3 bsdf_microfacet_ggx_eval_reflect(const ShaderClosure *sc, const float3 I, const float3 omega_in, float *pdf)
 {
-	float m_ag = sc->data0;
+	float m_ag = max(sc->data0, 1e-4f);
 	int m_refractive = sc->type == CLOSURE_BSDF_MICROFACET_GGX_REFRACTION_ID;
 	float3 N = sc->N;
 
@@ -115,7 +115,7 @@
 
 __device float3 bsdf_microfacet_ggx_eval_transmit(const ShaderClosure *sc, const float3 I, const float3 omega_in, float *pdf)
 {
-	float m_ag = sc->data0;
+	float m_ag = max(sc->data0, 1e-4f);
 	float m_eta = sc->data1;
 	int m_refractive = sc->type == CLOSURE_BSDF_MICROFACET_GGX_REFRACTION_ID;
 	float3 N = sc->N;
@@ -179,8 +179,9 @@
 				*omega_in = 2 * cosMO * m - I;
 				if(dot(Ng, *omega_in) > 0) {
 					if (m_ag <= 1e-4f) {
-						*pdf = 1;
-						*eval = make_float3(1, 1, 1);
+						// some high number for MIS
+						*pdf = 1e6f;
+						*eval = make_float3(1e6f, 1e6f, 1e6f);
 					}
 					else {
 						// microfacet normal is visible to this ray
@@ -235,8 +236,9 @@
 #endif
 
 				if (m_ag <= 1e-4f) {
-					*pdf = 1;
-					*eval = make_float3(1, 1, 1);
+					// some high number for MIS
+					*pdf = 1e6f;
+					*eval = make_float3(1e6f, 1e6f, 1e6f);
 				}
 				else {
 					// eq. 33
@@ -303,7 +305,7 @@
 
 __device float3 bsdf_microfacet_beckmann_eval_reflect(const ShaderClosure *sc, const float3 I, const float3 omega_in, float *pdf)
 {
-	float m_ab = sc->data0;
+	float m_ab = max(sc->data0, 1e-4f);
 	int m_refractive = sc->type == CLOSURE_BSDF_MICROFACET_BECKMANN_REFRACTION_ID;
 	float3 N = sc->N;
 
@@ -342,7 +344,7 @@
 
 __device float3 bsdf_microfacet_beckmann_eval_transmit(const ShaderClosure *sc, const float3 I, const float3 omega_in, float *pdf)
 {
-	float m_ab = sc->data0;
+	float m_ab = max(sc->data0, 1e-4f);
 	float m_eta = sc->data1;
 	int m_refractive = sc->type == CLOSURE_BSDF_MICROFACET_BECKMANN_REFRACTION_ID;
 	float3 N = sc->N;
@@ -394,8 +396,17 @@
 		// we take advantage of cos(atan(x)) == 1/sqrt(1+x^2)
 		//tttt  and sin(atan(x)) == x/sqrt(1+x^2)
 		float alpha2 = m_ab * m_ab;
-		float tanThetaM = safe_sqrtf(-alpha2 * logf(1 - randu));
-		float cosThetaM = 1 / safe_sqrtf(1 + tanThetaM * tanThetaM);
+		float tanThetaM, cosThetaM;
+
+		if(alpha2 == 0.0f) {
+			tanThetaM = 0.0f;
+			cosThetaM = 1.0f;
+		}
+		else {
+			tanThetaM = safe_sqrtf(-alpha2 * logf(1 - randu));
+			cosThetaM = 1 / safe_sqrtf(1 + tanThetaM * tanThetaM);
+		}
+
 		float sinThetaM = cosThetaM * tanThetaM;
 		float phiM = 2 * M_PI_F * randv;
 		float3 m = (cosf(phiM) * sinThetaM) * X +
@@ -409,8 +420,9 @@
 				*omega_in = 2 * cosMO * m - I;
 				if(dot(Ng, *omega_in) > 0) {
 					if (m_ab <= 1e-4f) {
-						*pdf = 1;
-						*eval = make_float3(1, 1, 1);
+						// some high number for MIS
+						*pdf = 1e6f;
+						*eval = make_float3(1e6f, 1e6f, 1e6f);
 					}
 					else {
 						// microfacet normal is visible to this ray
@@ -466,8 +478,9 @@
 				*domega_in_dy = dTdy;
 #endif
 				if (m_ab <= 1e-4f) {
-					*pdf = 1;
-					*eval = make_float3(1, 1, 1);
+					// some high number for MIS
+					*pdf = 1e6f;
+					*eval = make_float3(1e6f, 1e6f, 1e6f);
 				}
 				else {
 					// eq. 33




More information about the Bf-blender-cvs mailing list