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++) {
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;
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];
197 float sum_sample_weight)
199 for (
int i = 0; i < phases->num_closure; i++) {
202 if (svc == skip_svc) {
206 float phase_pdf = 0.0f;
209 if (phase_pdf != 0.0f) {
211 sum_pdf += phase_pdf * svc->sample_weight;
214 sum_sample_weight += svc->sample_weight;
218 return (sum_sample_weight > 0.0f) ? sum_pdf / sum_sample_weight : 0.0f;
227 const uint light_shader_flags)
231 float pdf = _volume_shader_phase_eval_mis(sd, phases, wo,
nullptr, phase_eval, 0.0f, 0.0f);
233# if defined(__PATH_GUIDING__) && PATH_GUIDING_LEVEL >= 4
237 state, guiding, volume_guiding_sampling_prob);
239 pdf = (guiding_sampling_prob * guide_pdf) + (1.0f - guiding_sampling_prob) * pdf;
271 if (phases->num_closure > 1) {
274 *pdf = _volume_shader_phase_eval_mis(
275 sd, phases, *wo, svc, phase_eval, *pdf * sample_weight, sample_weight);
285# if defined(__PATH_GUIDING__)
300 state, guiding, volume_guiding_sampling_prob);
304 bool sample_guiding =
false;
305 if (use_volume_guiding && rand_phase_guiding < guiding_sampling_prob) {
306 sample_guiding =
true;
307 rand_phase_guiding /= guiding_sampling_prob;
310 rand_phase_guiding -= guiding_sampling_prob;
311 rand_phase_guiding /= (1.0f - guiding_sampling_prob);
317 *unguided_phase_pdf = 0.0f;
318 float guide_pdf = 0.0f;
322 if (sample_guiding) {
328 if (guide_pdf != 0.0f) {
329 *unguided_phase_pdf = _volume_shader_phase_eval_mis(
330 sd, phases, *wo,
nullptr, phase_eval, 0.0f, 0.0f);
331 *phase_pdf = (guiding_sampling_prob * guide_pdf) +
332 ((1.0f - guiding_sampling_prob) * (*unguided_phase_pdf));
339 label = volume_shader_phase_sample(
340 sd, phases, svc, rand_phase, phase_eval, wo, unguided_phase_pdf, sampled_roughness);
342 if (*unguided_phase_pdf != 0.0f) {
343 *phase_pdf = *unguided_phase_pdf;
344 if (use_volume_guiding) {
346 *phase_pdf *= 1.0f - guiding_sampling_prob;
347 *phase_pdf += guiding_sampling_prob * guide_pdf;
365# ifdef __OBJECT_MOTION__
377 const float velocity_scale =
421 float3 velocity = primitive_volume_attribute<float3>(kg, sd, v_desc,
false);
425 sd->P =
P - (
time - time_offset) * velocity_scale * velocity;
428 velocity = primitive_volume_attribute<float3>(kg, sd, v_desc,
false);
432 sd->P =
P - (
time - time_offset) * velocity_scale * velocity;
435 sd->shader_flag |= cubic_flag;
441template<const
bool shadow, const u
int64_t node_feature_mask,
typename ConstIntegratorGenericState>
443 ConstIntegratorGenericState
state,
447 const uint32_t path_flag)
455 sd->object = entry.object;
456 sd->shader = entry.shader;
464 if (shadow && !(
kernel_data_fetch(objects, sd->object).visibility & path_visibility)) {
472# ifdef __OBJECT_MOTION__
477 volume_shader_motion_blur(kg, sd);
491 kg,
state, sd,
nullptr, path_visibility, path_flag);
498template<const
bool shadow,
typename ConstIntegratorGenericState>
500 ConstIntegratorGenericState
state,
503 const uint32_t path_flag)
521 sd->num_closure_left = max_closures;
526 for (
int i = 0;; i++) {
527 const VolumeStack entry = volume_stack_read<shadow>(
state, i);
528 if (!volume_shader_eval_entry<shadow, KERNEL_FEATURE_NODE_MASK_VOLUME>(
529 kg,
state, sd, entry, path_visibility, path_flag))
538 volume_shader_merge_closures(sd);
static DBVT_INLINE btScalar size(const btDbvtVolume &a)
#define kernel_assert(cond)
#define CLOSURE_IS_VOLUME_SCATTER(type)
#define ccl_attr_maybe_unused
#define MAX_VOLUME_CLOSURE
#define KERNEL_FEATURE_PATH_GUIDING
#define kernel_data_fetch(name, index)
#define KERNEL_FEATURE_OSL_SHADING
#define ccl_device_inline
#define CCL_NAMESPACE_END
float reduce_min(float2 a)
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_NAMESPACE_BEGIN ccl_device_forceinline bool is_attribute_found(const ccl_private AttributeDescriptor &desc)
ccl_device_inline AttributeDescriptor find_attribute(const ccl_global AttributeMap *attributes_map, uint attr_offset, const int prim, const uint64_t id)
ccl_device_inline void object_dir_transform(KernelGlobals kg, const ccl_private ShaderData *sd, ccl_private float3 *D)
ccl_device_forceinline float guiding_phase_sample(ccl_attr_maybe_unused KernelGlobals kg, ccl_attr_maybe_unused const float2 rand_phase, ccl_attr_maybe_unused ccl_private float3 *wo)
ccl_device_forceinline bool guiding_phase_init(ccl_attr_maybe_unused KernelGlobals kg, ccl_attr_maybe_unused const float3 P, ccl_attr_maybe_unused const float3 D, ccl_attr_maybe_unused const float g, ccl_attr_maybe_unused ccl_private float &rand)
ccl_device_forceinline float guiding_phase_pdf(ccl_attr_maybe_unused KernelGlobals kg, ccl_attr_maybe_unused const float3 wo)
void osl_eval_nodes(const ThreadKernelGlobalsCPU *kg, ConstIntegratorGenericState state, ShaderData *sd, PathRayVisibility path_visibility, uint32_t path_flag)
ccl_device void svm_eval_nodes(KernelGlobals kg, ConstIntegratorGenericState state, ccl_private ShaderData *sd, ccl_global float *render_buffer, const PathRayVisibility path_visibility, const uint32_t path_flag)
uint32_t PathRayVisibility
@ SR_IS_VOLUME_SHADER_EVAL
@ PATH_RAY_VISIBILITY_SHADOW
@ SD_OBJECT_HAS_VOLUME_MOTION
@ ATTR_STD_VOLUME_VELOCITY
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)
std::string time(const std::tm &date_time, TimeFormat format=TimeFormat::H24)
constexpr StringRefNull velocity
ResultT eval(const Uniform &uni, const ViewMatrices view, ScreenThicknessParameters thickness_params, sampler2D hiz_tx, sampler2D screen_radiance_tx, sampler2D screen_normal_tx, float3 vP, float3 vN, float4 noise, float2 pixel_size, float search_distance, float angle_bias, const int slice_count, const int sample_count, const bool reversed, const bool ao_only)
float sample_weight(float3 out_direction, float3 in_direction, float linear_roughness)
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
KERNEL_FEATURE_LIGHT_PASSES KERNEL_FEATURE_DENOISING KERNEL_STRUCT_VOLUME_STACK_SIZE KERNEL_FEATURE_PATH_GUIDING sample_volume_guiding_rand