35 for (
int i = 0;
i < sd->num_closure;
i++) {
42 for (
int j =
i + 1; j < sd->num_closure; j++) {
48 sci->weight += scj->weight;
49 sci->sample_weight += scj->sample_weight;
51 const int size = sd->num_closure - (j + 1);
53 for (
int k = 0; k <
size; k++) {
69 phases->num_closure = 0;
71 for (
int i = 0;
i < sd->num_closure;
i++) {
72 const ccl_private ShaderClosure *from_sc = &sd->closure[
i];
86# if defined(__PATH_GUIDING__)
89 float rand_phase_guiding,
95 const int num_phases = phases->num_closure;
96 if (!
kernel_data.integrator.use_volume_guiding || num_phases == 0) {
101 const float volume_guiding_probability =
kernel_data.integrator.volume_guiding_probability;
106 float phase_weight = 1.0f;
108 if (num_phases > 1) {
112 for (phase_id = 0; phase_id < num_phases; phase_id++) {
114 sum += svc->sample_weight;
117 const float r = rand_phase_guiding *
sum;
118 float partial_sum = 0.0f;
120 for (phase_id = 0; phase_id < num_phases; phase_id++) {
126 rand_phase_guiding = (r - partial_sum) / svc->sample_weight;
127 phase_weight = svc->sample_weight /
sum;
131 partial_sum = next_sum;
135 phases->closure[phase_id].sample_weight *= volume_guiding_probability;
149 state, guiding, volume_guiding_sampling_prob) = volume_guiding_probability * phase_weight;
166 if (phases->num_closure > 1) {
169 float sum = phases->closure[0].sample_weight;
171 for (
int i = 1;
i < phases->num_closure;
i++) {
172 const float sample_weight = phases->closure[
i].sample_weight;
173 sum += sample_weight;
174 const float thresh = sample_weight /
sum;
177 if (rand_phase->x < thresh) {
179 rand_phase->x /= thresh;
182 rand_phase->x = (rand_phase->x - thresh) / (1.0f - thresh);
187 return &phases->closure[sampled];
195 float sum_sample_weight)
197 for (
int i = 0;
i < phases->num_closure;
i++) {
199 float phase_pdf = 0.0f;
202 if (phase_pdf != 0.0f) {
204 sum_pdf += phase_pdf * svc->sample_weight;
207 sum_sample_weight += svc->sample_weight;
211 return (sum_sample_weight > 0.0f) ? sum_pdf / sum_sample_weight : 0.0f;
219 float phase_pdf = 0.0f;
222 if (phase_pdf != 0.0f) {
235 const uint light_shader_flags)
239 float pdf = _volume_shader_phase_eval_mis(sd, phases, wo, phase_eval, 0.0f, 0.0f);
241# if defined(__PATH_GUIDING__) && PATH_GUIDING_LEVEL >= 4
245 state, guiding, volume_guiding_sampling_prob);
247 pdf = (guiding_sampling_prob * guide_pdf) + (1.0f - guiding_sampling_prob) * pdf;
261# if defined(__PATH_GUIDING__)
275 state, guiding, volume_guiding_sampling_prob);
279 bool sample_guiding =
false;
280 if (use_volume_guiding && rand_phase_guiding < guiding_sampling_prob) {
281 sample_guiding =
true;
282 rand_phase_guiding /= guiding_sampling_prob;
285 rand_phase_guiding -= guiding_sampling_prob;
286 rand_phase_guiding /= (1.0f - guiding_sampling_prob);
293 *unguided_phase_pdf = 0.0f;
294 float guide_pdf = 0.0f;
299 if (sample_guiding) {
304 if (guide_pdf != 0.0f) {
305 *unguided_phase_pdf = volume_shader_phase_eval(sd, svc, *wo, phase_eval);
306 *phase_pdf = (guiding_sampling_prob * guide_pdf) +
307 ((1.0f - guiding_sampling_prob) * (*unguided_phase_pdf));
316 if (*unguided_phase_pdf != 0.0f) {
319 *phase_pdf = *unguided_phase_pdf;
320 if (use_volume_guiding) {
322 *phase_pdf *= 1.0f - guiding_sampling_prob;
323 *phase_pdf += guiding_sampling_prob * guide_pdf;
362# ifdef __OBJECT_MOTION__
374 const float velocity_scale =
kernel_data_fetch(objects, sd->object).velocity_scale;
417 float3 velocity = primitive_volume_attribute<float3>(kg, sd, v_desc,
false);
421 sd->P =
P - (time - time_offset) * velocity_scale * velocity;
424 velocity = primitive_volume_attribute<float3>(kg, sd, v_desc,
false);
428 sd->P =
P - (time - time_offset) * velocity_scale * velocity;
431 sd->flag |= cubic_flag;
437template<const
bool shadow, const u
int node_feature_mask,
typename ConstIntegratorGenericState>
439 ConstIntegratorGenericState
state,
442 const uint32_t path_flag)
450 sd->object = entry.object;
451 sd->shader = entry.shader;
470# ifdef __OBJECT_MOTION__
475 volume_shader_motion_blur(kg, sd);
495template<const
bool shadow,
typename ConstIntegratorGenericState>
497 ConstIntegratorGenericState
state,
499 const uint32_t path_flag)
515 sd->num_closure_left = max_closures;
519 for (
int i = 0;;
i++) {
521 if (!volume_shader_eval_entry<shadow, KERNEL_FEATURE_NODE_MASK_VOLUME>(
522 kg,
state, sd, entry, path_flag))
531 volume_shader_merge_closures(sd);
static DBVT_INLINE btScalar size(const btDbvtVolume &a)
static T sum(const btAlignedObjectArray< T > &items)
void osl_eval_nodes< SHADER_TYPE_VOLUME >(const ThreadKernelGlobalsCPU *kg, const void *state, ShaderData *sd, const uint32_t path_flag)
#define kernel_assert(cond)
#define CLOSURE_IS_VOLUME_SCATTER(type)
#define MAX_VOLUME_CLOSURE
#define KERNEL_FEATURE_PATH_GUIDING
#define kernel_data_fetch(name, index)
#define KERNEL_FEATURE_OSL_SHADING
const ThreadKernelGlobalsCPU * KernelGlobals
#define ccl_device_inline
#define CCL_NAMESPACE_END
ccl_device bool volume_phase_equal(const ccl_private ShaderClosure *c1, const ccl_private ShaderClosure *c2)
ccl_device Spectrum volume_phase_eval(const ccl_private ShaderData *sd, const ccl_private ShaderVolumeClosure *svc, const float3 wo, ccl_private float *pdf)
ccl_device float volume_phase_get_g(const ccl_private ShaderVolumeClosure *svc)
ccl_device int volume_phase_sample(const ccl_private ShaderData *sd, const ccl_private ShaderVolumeClosure *svc, const float2 rand, ccl_private Spectrum *eval, ccl_private float3 *wo, ccl_private float *pdf)
ccl_device_inline void object_dir_transform(KernelGlobals kg, const ccl_private ShaderData *sd, ccl_private float3 *D)
ccl_device_forceinline bool guiding_phase_init(KernelGlobals kg, const float3 P, const float3 D, const float g, ccl_private float &rand)
ccl_device_forceinline float guiding_phase_pdf(KernelGlobals kg, const float3 wo)
ccl_device_forceinline float guiding_phase_sample(KernelGlobals kg, const float2 rand_phase, ccl_private float3 *wo)
ccl_device void svm_eval_nodes(KernelGlobals kg, ConstIntegratorGenericState state, ccl_private ShaderData *sd, ccl_global float *render_buffer, const uint32_t path_flag)
@ SD_IS_VOLUME_SHADER_EVAL
@ ATTR_STD_VOLUME_VELOCITY
@ PATH_RAY_ALL_VISIBILITY
@ SD_OBJECT_HAS_VOLUME_MOTION
CCL_NAMESPACE_BEGIN ccl_device_inline void bsdf_eval_init(ccl_private BsdfEval *eval, const ccl_private ShaderClosure *sc, const float3 wo, Spectrum value)
ccl_device_inline void bsdf_eval_accum(ccl_private BsdfEval *eval, const ccl_private ShaderClosure *sc, const float3 wo, Spectrum value)
ccl_device_inline void bsdf_eval_mul(ccl_private BsdfEval *eval, const float value)
ccl_device_inline Spectrum bsdf_eval_sum(const ccl_private BsdfEval *eval)
ccl_device_inline float reduce_min(const float2 a)
CCL_NAMESPACE_BEGIN ccl_device void shader_setup_object_transforms(KernelGlobals kg, ccl_private ShaderData *ccl_restrict sd, const float time)
#define INTEGRATOR_STATE_WRITE(state, nested_struct, member)
#define INTEGRATOR_STATE(state, nested_struct, member)
IntegratorStateCPU * IntegratorState
static bool find_attribute(const std::string &attributes, const char *search_attribute)