[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [60538] branches/soc-2013-dingto/intern/ cycles/kernel/kernel_volume.h: Volume:

Thomas Dinges blender at dingto.org
Fri Oct 4 00:04:05 CEST 2013


Revision: 60538
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=60538
Author:   dingto
Date:     2013-10-03 22:04:05 +0000 (Thu, 03 Oct 2013)
Log Message:
-----------
Volume:
* More style and code cleanup. 

Modified Paths:
--------------
    branches/soc-2013-dingto/intern/cycles/kernel/kernel_volume.h

Modified: branches/soc-2013-dingto/intern/cycles/kernel/kernel_volume.h
===================================================================
--- branches/soc-2013-dingto/intern/cycles/kernel/kernel_volume.h	2013-10-03 21:27:26 UTC (rev 60537)
+++ branches/soc-2013-dingto/intern/cycles/kernel/kernel_volume.h	2013-10-03 22:04:05 UTC (rev 60538)
@@ -39,12 +39,13 @@
 	/* return "sigma" that required to get "value" attenuation at "geom_factor" distance of media.
 	to make input value resemble "alpha color" in 2d grapics , "value"=0 mean ransparent, 1 = opaque, so there is another a=1-v step.*/
 #if 0
-//	const float att_magic_eps = 1e-7f;
-	const float att_magic_eps = 1e-15f;
+	const float att_magic_eps = 1e-15f; // 1e-7f?
 	float attenuation = 1-value;
 	// protect infinity nan from too big density materials
-	if( attenuation < att_magic_eps) attenuation = att_magic_eps;
-	return (-logf( attenuation )/geom_factor);
+	if(attenuation < att_magic_eps) 
+		attenuation = att_magic_eps;
+
+	return (-logf(attenuation) / geom_factor);
 #else
 	return value * geom_factor;
 #endif
@@ -70,7 +71,6 @@
        return sigma_from_value(v, kernel_data.integrator.volume_density_factor);
 }
 
-
 __device  float3 kernel_volume_get_final_homogeneous_extinction_tsd(KernelGlobals *kg, ShaderData *sd, float trandp, Ray ray, int path_flag)
 {
 	// return 3 transition extinction coefficients based on particle BRDF, base density and color
@@ -126,12 +126,11 @@
 		res_sigma.z = base_sigma * (1.0f + logf(1.0f + (1.0f / M_E - 1.0f) * transition_pdf * color.z));
 //		printf("pdf=%g\n", transition_pdf);
 #else
-		res_sigma = ( make_float3(transition_pdf, transition_pdf, transition_pdf) * color);
-		if( res_sigma.x > 1.0f) res_sigma.x = 1.0f;
-		if( res_sigma.y > 1.0f) res_sigma.y = 1.0f;
-		if( res_sigma.z > 1.0f) res_sigma.z = 1.0f;
+		res_sigma = (make_float3(transition_pdf, transition_pdf, transition_pdf) * color);		
+		res_sigma = min(res_sigma, 1.0f);
 #endif
 	}
+
 	return res_sigma;
 }
 
@@ -181,8 +180,9 @@
 		shader_eval_volume(kg, &tsd, trandp, path_flag, SHADER_CONTEXT_MAIN);
 		float3 color = tsd.closure.weight;
 #endif
-		res_sigma = make_float3(base_sigma, base_sigma, base_sigma) / ( make_float3(transition_pdf, transition_pdf, transition_pdf) * color);
+		res_sigma = make_float3(base_sigma, base_sigma, base_sigma) / (make_float3(transition_pdf, transition_pdf, transition_pdf) * color);
 	}
+
 	return res_sigma;
 }
 
@@ -190,7 +190,7 @@
 {
 	/* check all objects that intersect random ray from given point, assume we have perfect geometry (all meshes closed, correct faces direct
 	 we can calculate current volume material, assuming background as start, and reassign when we cross face */
-	if (!kernel_data.integrator.use_volumetric)
+	if(!kernel_data.integrator.use_volumetric)
 		return kernel_data.background.shader;
 
 	Ray ray;
@@ -204,18 +204,18 @@
 	int stack = 0;
 //	while (scene_intersect(kg, &ray, PATH_RAY_SHADOW, &isect))
 #ifdef __HAIR__ 
-	while (scene_intersect(kg, &ray, 0, &isect, NULL, 0.0f, 0.0f))
+	while(scene_intersect(kg, &ray, 0, &isect, NULL, 0.0f, 0.0f))
 #else
-	while (scene_intersect(kg, &ray, 0, &isect))
+	while(scene_intersect(kg, &ray, 0, &isect))
 #endif
 	{
 		ShaderData sd;
         shader_setup_from_ray(kg, &sd, &isect, &ray, bounce);
         shader_eval_surface(kg, &sd, 0.0f, 0, SHADER_CONTEXT_MAIN); // not needed ?
 
-		if (sd.flag & SD_BACKFACING) {
+		if(sd.flag & SD_BACKFACING) {
 			stack--;
-			if (stack <= 0 && (sd.flag & SD_HAS_VOLUME))
+			if(stack <= 0 && (sd.flag & SD_HAS_VOLUME))
 				return sd.shader; // we are inside of object, as first triangle hit is from inside
 		}
 		else
@@ -229,13 +229,15 @@
 	return kernel_data.background.shader;
 }
 
-/*used */
+/* used */
 
 /* Volumetric sampling */
 __device int kernel_volumetric_woodcock_sampler(KernelGlobals *kg, RNG *rng_congruential, ShaderData *sd,
 	Ray ray, int path_flag, float end, float *new_t, float *pdf)
 {
-	/* google "woodcock delta tracker" algorithm, must be preprocessed to guess max density in volume, better keep it as close to density as possible or we got lot of tiny steps and spend milenniums marching single volume ray segment. 0.95 is good default. */
+	/* Google "woodcock delta tracker" algorithm, must be preprocessed to guess max density in volume,
+	 * better keep it as close to density as possible or we got lot of tiny steps and spend millenniums
+	 * marching single volume ray segment. 0.95 is good default. */
 	float magic_eps = 1e-4f;
 
 	int max_iter = kernel_data.integrator.volume_max_iterations;
@@ -245,27 +247,27 @@
 	
 	float step = end / 10.0f; // uses 10 segments for maximum - needs parameter
 	for(float s = 0.0f ; s < end ; s+= step)
-		max_sigma_t = max( max_sigma_t , get_sigma_sample(kg, sd, rand_congruential(), path_flag, ray.P + ray.D * s));
+		max_sigma_t = max(max_sigma_t , get_sigma_sample(kg, sd, rand_congruential(), path_flag, ray.P + ray.D * s));
 	
 	int i = 0;
 	float t = 0;
 	float sigma_factor = 1.0f;
 	*pdf = 1.0f;
 
-	if((end < magic_eps) || (max_sigma_t == 0))
+	if((end < magic_eps) || (max_sigma_t == 0.0f))
 		return 0;
 
 	do {
 		float r = rand_congruential();
-		t += -logf( r) / max_sigma_t;
+		t += -logf(r) / max_sigma_t;
 		// *pdf *= sigma_factor; // pdf that previous position was transparent pseudo-particle, obviously 1.0 for first loop step
 		// *pdf *= max_sigma_t * r; // pdf of particle collision, based on conventional freefly homogeneous distance equation
 	}
-	while( ( sigma_factor = (get_sigma_sample(kg, sd, rand_congruential(), path_flag, ray.P + ray.D * t)/ max_sigma_t)) < rand_congruential() && 
+	while((sigma_factor = (get_sigma_sample(kg, sd, rand_congruential(), path_flag, ray.P + ray.D * t) / max_sigma_t)) < rand_congruential() && 
 		t < (end - magic_eps) &&
 		i++ < max_iter);
 
-	if (t < (end - magic_eps) && i <= max_iter) {
+	if(t < (end - magic_eps) && i <= max_iter) {
 		*new_t = t;
 	    sd->P = ray.P + ray.D * t;
 		// *pdf *= sigma_factor; // fixme: is it necessary ?
@@ -273,15 +275,15 @@
 	}
 
 	// Assume rest of media up to end is homogeneous, it helps when using woodcock in outdoor scenes that tend to have continuous density.
-	if ((i > max_iter) && (t < (end - magic_eps))) {
+	if((i > max_iter) && (t < (end - magic_eps))) {
 		float sigma = get_sigma_sample(kg, sd, rand_congruential(), path_flag, ray.P + ray.D * t);
-		if( sigma < magic_eps)
+		if(sigma < magic_eps)
 			return 0;
 
 		float r = rand_congruential();
-		t += -logf( r) / sigma;
+		t += -logf(r) / sigma;
 		*pdf *= sigma * r;
-		if (t < (end - magic_eps)) {
+		if(t < (end - magic_eps)) {
 			// double check current sigma, just to be sure we do not register event for null media.
 			if(get_sigma_sample(kg, sd, rand_congruential(), path_flag, ray.P + ray.D * t) > magic_eps) {
 				*new_t = t;
@@ -296,7 +298,9 @@
 __device int kernel_volumetric_woodcock_sampler2(KernelGlobals *kg, RNG *rng_congruential, ShaderData *sd,
 	Ray ray, int path_flag, float end, float *new_t, float *pdf)
 {
-	/* google "woodcock delta tracker" algorithm, must be preprocessed to guess max density in volume, better keep it as close to density as possible or we got lot of tiny steps and spend milenniums marching single volume ray segment. 0.95 is good default. */
+	/* Google "woodcock delta tracker" algorithm, must be preprocessed to guess max density in volume,
+	 * better keep it as close to density as possible or we got lot of tiny steps and spend millenniums
+	 * marching single volume ray segment. 0.95 is good default. */
 	float magic_eps = 1e-4f;
 
 	int max_iter = kernel_data.integrator.volume_max_iterations;
@@ -312,22 +316,22 @@
 	if((end - start) < magic_eps)
 		return 0;
 	
-	if(max_sigma_t == 0)
+	if(max_sigma_t == 0.0f)
 		return 0;
 
 	do {
 		float r = rand_congruential();
-		t += -logf( r) / max_sigma_t;
+		t += -logf(r) / max_sigma_t;
 		// *pdf *= sigma_factor; // pdf that previous position was transparent pseudo-particle, obviously 1.0 for first loop step
 		// *pdf *= max_sigma_t * r; // pdf of particle collision, based on conventional freefly homogeneous distance equation
 	}
-	while( ( sigma_factor = (get_sigma_sample(kg, sd, rand_congruential(), path_flag, ray.P + ray.D * (t + start))/ max_sigma_t)) < rand_congruential() && 
-		(t +start )< (end - magic_eps) &&
+	while((sigma_factor = (get_sigma_sample(kg, sd, rand_congruential(), path_flag, ray.P + ray.D * (t + start)) / max_sigma_t)) < rand_congruential() && 
+		(t + start ) < (end - magic_eps) &&
 		i++ < max_iter);
 
 	if ((t + start) < (end - magic_eps) && i <= max_iter) {
 		*new_t = t + start;
-	        sd->P = ray.P + ray.D * (t + start);
+		sd->P = ray.P + ray.D * (t + start);
 		// *pdf *= sigma_factor; // fixme: is it necessary ?
 		return 1;
 	}
@@ -337,16 +341,16 @@
 	// last chance trick, we cannot iterate infinity, but we can force to homogeneous last step after max_iter,
 	// assume rest of media up to end is homogeneous, it help to use woodcock even in outdoor scenes that tend to have continuous density
 	// even if vary a bit in close distance. of course it make sampling biased (not respect actual density).
-	if ((i > max_iter) && ((t +start ) < (end - magic_eps))) {
+	if((i > max_iter) && ((t +start ) < (end - magic_eps))) {
 		float sigma = get_sigma_sample(kg, sd, rand_congruential(), path_flag, ray.P + ray.D * (t + start));
 		if( sigma < magic_eps) return 0;
 		// t += -logf( rand_congruential()) / sigma;
 		float r = rand_congruential();
-		t += -logf( r) / sigma;
+		t += -logf(r) / sigma;
 		*pdf *= sigma * r;
-		if ((t + start) < (end - magic_eps)) {
+		if((t + start) < (end - magic_eps)) {
 			// double check current sigma, just to be sure we do not register event for null media.
-			if( get_sigma_sample(kg, sd, rand_congruential(), path_flag, ray.P + ray.D * (t + start)) > magic_eps) {
+			if(get_sigma_sample(kg, sd, rand_congruential(), path_flag, ray.P + ray.D * (t + start)) > magic_eps) {
 				*new_t = t + start;
 				sd->P = ray.P + ray.D * (t + start);
 				return 1;
@@ -387,9 +391,9 @@
 		integral += intstep;
 		cell_count++;
 	}
-	while( (integral < root) && (cell_count < max_steps) && (t < end));
+	while((integral < root) && (cell_count < max_steps) && (t < end));
 
-	if ((cell_count >= max_steps) || (t > end)) {
+	if((cell_count >= max_steps) || (t > end)) {
 		return 0;
 	}
 
@@ -404,7 +408,7 @@
 	Ray ray, int path_flag, float end, float *new_t, float *pdf)
 {	

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list