Fix T39804: cycles smoke domain visible in rendering.
authorBrecht Van Lommel <brechtvanlommel@gmail.com>
Thu, 29 May 2014 12:12:12 +0000 (14:12 +0200)
committerBrecht Van Lommel <brechtvanlommel@gmail.com>
Thu, 29 May 2014 12:51:02 +0000 (14:51 +0200)
Transparent objects could become subtly visible by the different sampling
patterns for pixels covered and not covered by the object. It still converged
to the right solution but that can take a while. Now we try to use the same
sampling pattern here.

intern/cycles/kernel/kernel_path.h
intern/cycles/kernel/kernel_path_state.h
intern/cycles/kernel/kernel_random.h
intern/cycles/kernel/kernel_types.h
intern/cycles/kernel/kernel_volume.h

index 3ef472b248e6ca6fc29dc97e84719a23f806edff..d760af15def0aaf4399d5e8a18ee318d2bb943a6 100644 (file)
@@ -281,7 +281,7 @@ ccl_device void kernel_path_indirect(KernelGlobals *kg, RNG *rng, Ray ray,
                /* setup shading */
                ShaderData sd;
                shader_setup_from_ray(kg, &sd, &isect, &ray, state.bounce, state.transparent_bounce);
-               float rbsdf = path_state_rng_1D(kg, rng, &state, PRNG_BSDF);
+               float rbsdf = path_state_rng_1D_for_decision(kg, rng, &state, PRNG_BSDF);
                shader_eval_surface(kg, &sd, rbsdf, state.flag, SHADER_CONTEXT_INDIRECT);
 #ifdef __BRANCHED_PATH__
                shader_merge_closures(&sd);
@@ -315,7 +315,7 @@ ccl_device void kernel_path_indirect(KernelGlobals *kg, RNG *rng, Ray ray,
                        break;
                }
                else if(probability != 1.0f) {
-                       float terminate = path_state_rng_1D(kg, rng, &state, PRNG_TERMINATE);
+                       float terminate = path_state_rng_1D_for_decision(kg, rng, &state, PRNG_TERMINATE);
 
                        if(terminate >= probability)
                                break;
@@ -785,7 +785,7 @@ ccl_device float4 kernel_path_integrate(KernelGlobals *kg, RNG *rng, int sample,
                /* setup shading */
                ShaderData sd;
                shader_setup_from_ray(kg, &sd, &isect, &ray, state.bounce, state.transparent_bounce);
-               float rbsdf = path_state_rng_1D(kg, rng, &state, PRNG_BSDF);
+               float rbsdf = path_state_rng_1D_for_decision(kg, rng, &state, PRNG_BSDF);
                shader_eval_surface(kg, &sd, rbsdf, state.flag, SHADER_CONTEXT_MAIN);
 
                /* holdout */
@@ -840,7 +840,7 @@ ccl_device float4 kernel_path_integrate(KernelGlobals *kg, RNG *rng, int sample,
                        break;
                }
                else if(probability != 1.0f) {
-                       float terminate = path_state_rng_1D(kg, rng, &state, PRNG_TERMINATE);
+                       float terminate = path_state_rng_1D_for_decision(kg, rng, &state, PRNG_TERMINATE);
 
                        if(terminate >= probability)
                                break;
@@ -1325,7 +1325,7 @@ ccl_device float4 kernel_branched_path_integrate(KernelGlobals *kg, RNG *rng, in
                                break;
                        }
                        else if(probability != 1.0f) {
-                               float terminate = path_state_rng_1D(kg, rng, &state, PRNG_TERMINATE);
+                               float terminate = path_state_rng_1D_for_decision(kg, rng, &state, PRNG_TERMINATE);
 
                                if(terminate >= probability)
                                        break;
index 406654c1741e124603d9a8b933a296e6ac4b8f51..39780c0edb0b50d7d63d988d1998617870a07544 100644 (file)
@@ -63,8 +63,8 @@ ccl_device_inline void path_state_next(KernelGlobals *kg, PathState *state, int
                state->flag |= PATH_RAY_TRANSPARENT;
                state->transparent_bounce++;
 
-               /* random number generator next bounce */
-               state->rng_offset += PRNG_BOUNCE_NUM;
+               /* don't increase random number generator offset here, to avoid some
+                * unwanted patterns, see path_state_rng_1D_for_decision */
 
                if(!kernel_data.integrator.transparent_shadows)
                        state->flag |= PATH_RAY_MIS_SKIP;
index 31cb6ff6abd4dd487573d7c6d37aab9412b5b379..ac04b3168a1fe13817c23cf73fd196480393c2ed 100644 (file)
@@ -266,6 +266,19 @@ ccl_device_inline float path_state_rng_1D(KernelGlobals *kg, RNG *rng, PathState
        return path_rng_1D(kg, rng, state->sample, state->num_samples, state->rng_offset + dimension);
 }
 
+ccl_device_inline float path_state_rng_1D_for_decision(KernelGlobals *kg, RNG *rng, PathState *state, int dimension)
+{
+       /* the rng_offset is not increased for transparent bounces. if we do then
+        * fully transparent objects can become subtly visible by the different
+        * sampling patterns used where the transparent object is.
+        *
+        * however for some random numbers that will determine if we next bounce
+        * is transparent we do need to increase the offset to avoid always making
+        * the same decision */
+       int rng_offset = state->rng_offset + state->transparent_bounce*PRNG_BOUNCE_NUM;
+       return path_rng_1D(kg, rng, state->sample, state->num_samples, rng_offset + dimension);
+}
+
 ccl_device_inline void path_state_rng_2D(KernelGlobals *kg, RNG *rng, PathState *state, int dimension, float *fx, float *fy)
 {
        path_rng_2D(kg, rng, state->sample, state->num_samples, state->rng_offset + dimension, fx, fy);
index 11445aa1c939ea6d2757e68e67bd72cba8da0244..7edbf5ab172287ecb0d6cba6df2ab987dcef9dfa 100644 (file)
@@ -686,9 +686,10 @@ typedef struct PathState {
        int flag;          
 
        /* random number generator state */
-       int rng_offset;    /* dimension offset */
-       int sample;        /* path sample number */
-       int num_samples;   /* total number of times this path will be sampled */
+       int rng_offset;                 /* dimension offset */
+       int rng_offset_bsdf;    /* dimension offset for picking bsdf */
+       int sample;                     /* path sample number */
+       int num_samples;                /* total number of times this path will be sampled */
 
        /* bounce counting */
        int bounce;
index 75c81940bbbf644a4902bf885249073c7ae8329a..49e4cf64de4f54d5c9dfeb6ef437ca9716b819bc 100644 (file)
@@ -322,11 +322,11 @@ ccl_device VolumeIntegrateResult kernel_volume_integrate_homogeneous(KernelGloba
 
                /* pick random color channel, we use the Veach one-sample
                 * model with balance heuristic for the channels */
-               float rphase = path_state_rng_1D(kg, rng, state, PRNG_PHASE);
+               float rphase = path_state_rng_1D_for_decision(kg, rng, state, PRNG_PHASE);
                int channel = (int)(rphase*3.0f);
                sd->randb_closure = rphase*3.0f - channel;
 
-               float xi = path_state_rng_1D(kg, rng, state, PRNG_SCATTER_DISTANCE);
+               float xi = path_state_rng_1D_for_decision(kg, rng, state, PRNG_SCATTER_DISTANCE);
 
                /* decide if we will hit or miss */
                float sample_sigma_t = kernel_volume_channel_get(sigma_t, channel);
@@ -461,9 +461,9 @@ ccl_device VolumeIntegrateResult kernel_volume_integrate_heterogeneous(KernelGlo
                                if(channel == -1) {
                                        /* pick random color channel, we use the Veach one-sample
                                         * model with balance heuristic for the channels */
-                                       xi = path_state_rng_1D(kg, rng, state, PRNG_SCATTER_DISTANCE);
+                                       xi = path_state_rng_1D_for_decision(kg, rng, state, PRNG_SCATTER_DISTANCE);
 
-                                       float rphase = path_state_rng_1D(kg, rng, state, PRNG_PHASE);
+                                       float rphase = path_state_rng_1D_for_decision(kg, rng, state, PRNG_PHASE);
                                        channel = (int)(rphase*3.0f);
                                        sd->randb_closure = rphase*3.0f - channel;
                                }
@@ -710,11 +710,11 @@ ccl_device VolumeIntegrateResult kernel_volume_decoupled_scatter(
 
        /* pick random color channel, we use the Veach one-sample
         * model with balance heuristic for the channels */
-       float rphase = path_state_rng_1D(kg, rng, state, PRNG_PHASE);
+       float rphase = path_state_rng_1D_for_decision(kg, rng, state, PRNG_PHASE);
        int channel = (int)(rphase*3.0f);
        sd->randb_closure = rphase*3.0f - channel;
 
-       float xi = path_state_rng_1D(kg, rng, state, PRNG_SCATTER_DISTANCE);
+       float xi = path_state_rng_1D_for_decision(kg, rng, state, PRNG_SCATTER_DISTANCE);
 
        VolumeStep *step;
        float3 transmittance;