[Bf-blender-cvs] [daf0112] soc-2013-dingto: Cycles Volume: add appropriate shader contexts for OSL.

Brecht Van Lommel noreply at git.blender.org
Thu Dec 26 15:58:00 CET 2013


Commit: daf01126e6658c89f1dab6e7dfc7d98d61f8861d
Author: Brecht Van Lommel
Date:   Thu Dec 26 15:54:44 2013 +0100
https://developer.blender.org/rBdaf01126e6658c89f1dab6e7dfc7d98d61f8861d

Cycles Volume: add appropriate shader contexts for OSL.

This is needed to avoid using same memory block twice when the closures from
a shader evaluation are in use at the same time as the closures from another
evaluation.

===================================================================

M	intern/cycles/kernel/kernel_types.h
M	intern/cycles/kernel/kernel_volume.h

===================================================================

diff --git a/intern/cycles/kernel/kernel_types.h b/intern/cycles/kernel/kernel_types.h
index 02a1197..ed55254 100644
--- a/intern/cycles/kernel/kernel_types.h
+++ b/intern/cycles/kernel/kernel_types.h
@@ -487,7 +487,8 @@ typedef enum ShaderContext {
 	SHADER_CONTEXT_EMISSION = 2,
 	SHADER_CONTEXT_SHADOW = 3,
 	SHADER_CONTEXT_SSS = 4,
-	SHADER_CONTEXT_NUM = 5
+	SHADER_CONTEXT_VOLUME = 5,
+	SHADER_CONTEXT_NUM = 6
 } ShaderContext;
 
 /* Shader Data
diff --git a/intern/cycles/kernel/kernel_volume.h b/intern/cycles/kernel/kernel_volume.h
index aca3e60..495642a 100644
--- a/intern/cycles/kernel/kernel_volume.h
+++ b/intern/cycles/kernel/kernel_volume.h
@@ -51,14 +51,11 @@ ccl_device float sigma_from_value(float value, float geom_factor)
 #endif
 }
 
-ccl_device float get_sigma_sample(KernelGlobals *kg, ShaderData *sd, int path_flag, float3 P)
+ccl_device float get_sigma_sample(KernelGlobals *kg, ShaderData *sd, int path_flag, ShaderContext ctx, float3 P)
 {
 	sd->P = P;
 
-	/* todo: the SHADER_CONTEXT here an in other places is wrong, it should be
-	 * defined such that the same context can't be active at the same time more
-	 * than once, this does not seem to be the case now */
-	shader_eval_volume(kg, sd, 0.0f, path_flag, SHADER_CONTEXT_MAIN);
+	shader_eval_volume(kg, sd, 0.0f, path_flag, ctx);
 
 	/* todo: this assumes global density and is broken, density is per closure! */
 	int sampled = 0;
@@ -68,7 +65,7 @@ ccl_device float get_sigma_sample(KernelGlobals *kg, ShaderData *sd, int path_fl
 	return sigma_from_value(v, 1.0f);
 }
 
-ccl_device  float3 kernel_volume_get_final_homogeneous_extinction_tsd(KernelGlobals *kg, ShaderData *sd, float trandp, Ray ray, int path_flag)
+ccl_device  float3 kernel_volume_get_final_homogeneous_extinction_tsd(KernelGlobals *kg, ShaderData *sd, Ray ray, int path_flag, ShaderContext ctx)
 {
 	// return 3 transition extinction coefficients based on particle BRDF, base density and color
 	// make sense only for homogeneous volume for now
@@ -79,7 +76,7 @@ ccl_device  float3 kernel_volume_get_final_homogeneous_extinction_tsd(KernelGlob
 	float3 res_sigma = make_float3(1.0f, 1.0f, 1.0f);
 	if((sd->flag & SD_HAS_VOLUME) != 0) { // check for empty volume shader
 		// base sigma
-		float base_sigma = get_sigma_sample(kg, sd, path_flag, ray.P);
+		float base_sigma = get_sigma_sample(kg, sd, path_flag, ctx, ray.P);
 
 		// get transition probability
 		// or flux that pass forward even if catched by particle.
@@ -93,7 +90,7 @@ ccl_device  float3 kernel_volume_get_final_homogeneous_extinction_tsd(KernelGlob
 		transition_pdf = single_peaked_henyey_greenstein(1.0f, 0.6);
 #endif
 
-		shader_eval_volume(kg, sd, 0.0f, path_flag, SHADER_CONTEXT_MAIN);
+		shader_eval_volume(kg, sd, 0.0f, path_flag, ctx);
 
 		/* todo: this assumes global density and is broken, color is per closure! */
 		int sampled = 0;
@@ -125,9 +122,11 @@ ccl_device  float3 kernel_volume_get_final_homogeneous_extinction_tsd(KernelGlob
 }
 
 /* unused */
-ccl_device float kernel_volume_homogeneous_pdf( KernelGlobals *kg, ShaderData *sd, float distance)
+ccl_device float kernel_volume_homogeneous_pdf( KernelGlobals *kg, ShaderData *sd, ShaderContext ctx, float distance)
 {
-	float sigma = get_sigma_sample(kg, sd, 0, make_float3(0.0f, 0.0f, 0.0f));
+	/* todo: do we need path_flag? */
+	float sigma = get_sigma_sample(kg, sd, 0, ctx, make_float3(0.0f, 0.0f, 0.0f));
+
 #ifdef __VOLUME_USE_GUARANTEE_HIT_PROB
 	return sigma * exp(-distance * sigma) * VOLUME_GUARANTEE_HIT_PROB;
 #else
@@ -135,7 +134,7 @@ ccl_device float kernel_volume_homogeneous_pdf( KernelGlobals *kg, ShaderData *s
 #endif
 }
 
-ccl_device float3 kernel_volume_get_final_homogeneous_extinction(KernelGlobals *kg, float trandp, int media_volume_shader)
+ccl_device float3 kernel_volume_get_final_homogeneous_extinction(KernelGlobals *kg, ShaderContext ctx, int media_volume_shader)
 {
 	ShaderData tsd;
 	Ray ray;
@@ -148,7 +147,7 @@ ccl_device float3 kernel_volume_get_final_homogeneous_extinction(KernelGlobals *
 	float3 res_sigma = make_float3(1.0f, 1.0f, 1.0f);
 	if((tsd.flag & SD_HAS_VOLUME) != 0) { // check for empty volume shader
 		// base sigma
-		float base_sigma = get_sigma_sample(kg, &tsd, path_flag, ray.P);
+		float base_sigma = get_sigma_sample(kg, &tsd, path_flag, ctx, ray.P);
 
 		// get transition probability
 		BsdfEval eval;
@@ -217,7 +216,7 @@ ccl_device int get_media_volume_shader(KernelGlobals *kg, float3 P, int bounce)
 
 /* Volumetric sampling */
 ccl_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)
+	Ray ray, int path_flag, ShaderContext ctx, 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 millenniums
@@ -231,7 +230,7 @@ ccl_device int kernel_volumetric_woodcock_sampler(KernelGlobals *kg, RNG *rng_co
 	
 	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, path_flag, ray.P + ray.D * s));
+		max_sigma_t = max(max_sigma_t , get_sigma_sample(kg, sd, path_flag, ctx, ray.P + ray.D * s));
 	
 	int i = 0;
 	float t = 0;
@@ -247,7 +246,7 @@ ccl_device int kernel_volumetric_woodcock_sampler(KernelGlobals *kg, RNG *rng_co
 		// *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, path_flag, ray.P + ray.D * t) / max_sigma_t)) < rand_congruential() && 
+	while((sigma_factor = (get_sigma_sample(kg, sd, path_flag, ctx, ray.P + ray.D * t) / max_sigma_t)) < rand_congruential() && 
 		t < (end - magic_eps) &&
 		i++ < max_iter);
 
@@ -260,7 +259,7 @@ ccl_device int kernel_volumetric_woodcock_sampler(KernelGlobals *kg, RNG *rng_co
 
 	// 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))) {
-		float sigma = get_sigma_sample(kg, sd, path_flag, ray.P + ray.D * t);
+		float sigma = get_sigma_sample(kg, sd, path_flag, ctx, ray.P + ray.D * t);
 		if(sigma < magic_eps)
 			return 0;
 
@@ -269,7 +268,7 @@ ccl_device int kernel_volumetric_woodcock_sampler(KernelGlobals *kg, RNG *rng_co
 		*pdf *= sigma * r;
 		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, path_flag, ray.P + ray.D * t) > magic_eps) {
+			if(get_sigma_sample(kg, sd, path_flag, ctx, ray.P + ray.D * t) > magic_eps) {
 				*new_t = t;
 				sd->P = ray.P + ray.D * t;
 				return 1;
@@ -280,7 +279,7 @@ ccl_device int kernel_volumetric_woodcock_sampler(KernelGlobals *kg, RNG *rng_co
 	return 0;
 }
 ccl_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)
+	Ray ray, int path_flag, ShaderContext ctx, 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 millenniums
@@ -308,7 +307,7 @@ ccl_device int kernel_volumetric_woodcock_sampler2(KernelGlobals *kg, RNG *rng_c
 		// *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, path_flag, ray.P + ray.D * t) / max_sigma_t)) < rand_congruential() && 
+	while((sigma_factor = (get_sigma_sample(kg, sd, path_flag, ctx, ray.P + ray.D * t) / max_sigma_t)) < rand_congruential() && 
 		(t < (end - magic_eps)) &&
 		i++ < max_iter);
 
@@ -325,7 +324,7 @@ ccl_device int kernel_volumetric_woodcock_sampler2(KernelGlobals *kg, RNG *rng_c
 	// 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 < (end - magic_eps))) {
-		float sigma = get_sigma_sample(kg, sd, path_flag, ray.P + ray.D * t);
+		float sigma = get_sigma_sample(kg, sd, path_flag, ctx, ray.P + ray.D * t);
 		if(sigma < magic_eps) 
 			return 0;
 		// t += -logf( rand_congruential()) / sigma;
@@ -334,7 +333,7 @@ ccl_device int kernel_volumetric_woodcock_sampler2(KernelGlobals *kg, RNG *rng_c
 		*pdf *= sigma * r;
 		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, path_flag, ray.P + ray.D * t) > magic_eps) {
+			if(get_sigma_sample(kg, sd, path_flag, ctx, ray.P + ray.D * t) > magic_eps) {
 				*new_t = t;
 				sd->P = ray.P + ray.D * t;
 				return 1;
@@ -346,7 +345,7 @@ ccl_device int kernel_volumetric_woodcock_sampler2(KernelGlobals *kg, RNG *rng_c
 	return 0;
 }
 ccl_device int kernel_volumetric_marching_sampler(KernelGlobals *kg, RNG *rng_congruential, ShaderData *sd,
-	Ray ray, int path_flag, float end, float *new_t, float *pdf)
+	Ray ray, int path_flag, ShaderContext ctx, float end, float *new_t, float *pdf)
 {	
 	int max_steps = kernel_data.integrator.volume_max_iterations;
 	//float step = end != FLT_MAX ? end / max_steps : kernel_data.integrator.volume_cell_step;
@@ -370,7 +369,7 @@ ccl_device int kernel_volumetric_marching_sampler(KernelGlobals *kg, RNG *rng_co
 		current_cell_near_boundary_distance += step;
 		t = current_cell_near_boundary_distance + random_jitter_offset;
 		previous_cell_average_sigma = current_cell_average_sigma;
-		current_cell_average_sigma = get_sigma_sample(kg, sd, path_flag, ray.P + ray.D * t);
+		current_cell_a

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list