41struct VolumeIntegrateResult {
46 ShaderVolumePhases direct_phases;
47# if defined(__PATH_GUIDING__)
48 VolumeSampleMethod direct_sample_method;
52 bool indirect_scatter;
55 ShaderVolumePhases indirect_phases;
62# define OVERLAP_EXP 5e-4f
64# define VOLUME_MAX_STEPS 1024
66# define MANTISSA_BITS 23
73struct VolumeShaderCoefficients {
79struct EquiangularCoefficients {
81 Interval<float> t_range;
85template<const
bool shadow,
typename IntegratorGenericState>
87 const IntegratorGenericState
state,
95 volume_shader_eval<shadow>(kg,
state, sd, path_visibility, path_flag);
108 volume_shader_eval<false>(kg,
state, sd, path_visibility, path_flag);
115 coeff->sigma_t = (sd->runtime_flag &
SR_EXTINCTION) ? sd->closure_transparent_extinction :
117 coeff->emission = (sd->runtime_flag &
SR_EMISSION) ? sd->closure_emission_background :
121 for (
int i = 0; i < sd->num_closure; i++) {
122 const ccl_private ShaderClosure *sc = &sd->closure[i];
125 coeff->sigma_s += sc->weight;
150struct OctreeTracing {
178 bool no_overlap =
false;
181 Extrema<float> sigma = 0.0f;
189 enum Dimension { DIM_X = 1U << 0
U, DIM_Y = 1U << 1U, DIM_Z = 1U << 2U };
210 const auto positive = ray_D > 0.0f;
211 octant_mask = (!!positive.x * DIM_X) | (!!positive.y * DIM_Y) | (!!positive.z * DIM_Z);
212 local_P =
select(positive, 3.0f - local_P, local_P);
218 ray_D = -
fabs(ray_D);
221 ray_P = local_P - ray_D * t.
min;
224 return all(local_P > 1.0f);
246 select(t == tmax, bbox_min - half_size, ray_D * tmax + ray_P));
249 const uint diff = (current_P.
x ^ next_P.
x) | (current_P.
y ^ next_P.
y) |
250 (current_P.
z ^ next_P.
z);
260 const float3 bbox_min = floor_pos();
263 float3 intersect_t = (bbox_min - ray_P) / ray_D;
271 find_next_pos(bbox_min, intersect_t, tmax);
273 return fminf(tmax, ray_tmax);
282 return (
x |
y |
z) ^ octant_mask;
289 return knode->first_child == -1;
295 while (!volume_node_is_leaf(octree.node)) {
297 const int child_index = octree.node->first_child + octree.get_octant();
304template<const
bool shadow,
typename IntegratorGenericState>
308 const IntegratorGenericState
state,
311 const uint32_t path_flag,
317 const VolumeStack entry
321# ifdef __KERNEL_HIP__
323 const ccl_private VolumeStack &entry = octree.entry;
325 const bool homogeneous = volume_is_homogeneous(kg, entry);
326 const int samples = homogeneous ? 1 : 4;
327 const float shade_offset = homogeneous ?
330 const float step_size = t.length() /
float(samples);
333 sd->num_closure_left = 0;
336 for (
int i = 0; i < samples; i++) {
337 const float shade_t = t.min + (shade_offset + i) * step_size;
338 sd->P = ray->P + ray->D * shade_t;
340 sd->closure_transparent_extinction =
zero_float3();
343 volume_shader_eval_entry<shadow, KERNEL_FEATURE_NODE_MASK_VOLUME>(
344 kg,
state, sd, entry, path_visibility, path_flag);
346 const float sigma =
reduce_max(sd->closure_transparent_extinction);
347 const float emission =
reduce_max(sd->closure_emission_background);
349 extrema =
merge(extrema,
fmaxf(sigma, emission));
363template<const
bool shadow,
typename IntegratorGenericState>
367 const IntegratorGenericState
state,
371 const uint32_t path_flag)
379# ifdef __KERNEL_HIP__
380 return volume_estimate_extrema<shadow>(
381 kg, ray, sd,
state, rng_state, path_visibility, path_flag, octree);
383 return volume_estimate_extrema<shadow>(
384 kg, ray, sd,
state, rng_state, path_visibility, path_flag, octree.t, octree.entry);
394 while ((entry.shader &
SHADER_MASK) != kroot->shader) {
402template<const
bool shadow,
typename IntegratorGenericState>
406 const IntegratorGenericState
state,
409 const uint32_t path_flag,
411 const VolumeStack skip,
414 const VolumeStack entry = volume_stack_read<shadow>(
state,
index);
420 if (entry.object == skip.object && entry.shader == skip.shader) {
430 float3 local_P = ray->P, local_D = ray->D;
438 if (local.to_octree_space(local_P, local_D, kroot->scale, kroot->translation)) {
439 volume_voxel_get(kg, local);
440 local.t.max = local.ray_voxel_intersect(ray->tmax);
445 local.t.max = ray->tmax;
448 local.sigma = volume_object_get_extrema<shadow>(
449 kg, ray, sd,
state, local, rng_state, path_visibility, path_flag);
457template<const
bool shadow,
typename IntegratorGenericState>
461 const IntegratorGenericState
state,
464 const uint32_t path_flag,
467 if (global.no_overlap) {
469 return !global.t.is_empty();
472 const VolumeStack skip = global.entry;
477 OctreeTracing local(global.t.min);
478 if (!volume_octree_setup_single<shadow>(
479 kg, ray, sd,
state, rng_state, path_visibility, path_flag, local, skip, i))
484 global.sigma += local.sigma;
485 if (local.t.max <= global.t.max) {
487 local.sigma = global.sigma;
493 global.no_overlap =
true;
496 return global.node && !global.t.is_empty();
500template<const
bool shadow,
typename IntegratorGenericState>
504 const IntegratorGenericState
state,
507 const uint32_t path_flag,
510 if (octree.t.max >= ray->tmax) {
515 if (octree.next_scale > MANTISSA_BITS) {
516 if (
fabsf(octree.t.max - ray->tmax) <= OVERLAP_EXP) {
523 octree.t = {octree.t.max, ray->tmax};
525 volume_find_octree_root(kg, octree.entry)->id);
531 for (; octree.scale < octree.next_scale; octree.scale++) {
537 volume_voxel_get(kg, octree);
540 octree.t.min = octree.t.max;
541 octree.t.max = octree.ray_voxel_intersect(ray->tmax);
544 octree.sigma = volume_object_get_extrema<shadow>(
545 kg, ray, sd,
state, octree, rng_state, path_visibility, path_flag);
546 return volume_octree_setup<shadow>(
547 kg, ray, sd,
state, rng_state, path_visibility, path_flag, octree);
566 const uint32_t path_flag,
573 const float tmin = octree.t.
min;
575 while (octree.t.is_empty() || sigma.
range() * octree.t.length() < 1.0f) {
576 if (!volume_octree_advance<true>(
577 kg, ray, sd,
state, rng_state, path_visibility, path_flag, octree))
579 return !octree.t.is_empty();
582 octree.sigma = sigma =
merge(sigma, octree.sigma);
605template<const
bool shadow,
typename IntegratorGenericState>
607 IntegratorGenericState
state,
614 const uint32_t path_flag)
616 constexpr float r = 0.9f;
620 const float expected_steps = sigma_c *
ray_length;
622 const int k =
clamp(
int(
roundf(expected_steps)), 1, VOLUME_MAX_STEPS);
631 constexpr int cut_off = 4;
634 const int N = (sigma_c == 0.0f) ?
639 const int samples =
N * k;
647 for (
int i = 0; i < k; i++) {
648 const float shade_t =
min(t.
max, t.
min + (shade_offset + i) * step_size);
649 sd->P = ray->P + ray->D * shade_t;
650 tau_k += volume_shader_eval_extinction<shadow>(kg,
state, sd, path_visibility, path_flag);
663 for (
int n = 0; n <
N; n++) {
665 for (
int i = 0; i < k; i++) {
666 const int step = i *
N + n;
667 const float shade_t =
min(t.
max, t.
min + (shade_offset +
step) * step_size);
668 sd->P = ray->P + ray->D * shade_t;
670 const Spectrum tau = step_size * volume_shader_eval_extinction<shadow>(
671 kg,
state, sd, path_visibility, path_flag);
674 tau_j[
step % 2] += tau * 2.0f;
687 return T_k + (T_j_1 - T_j) / pmf;
698 if (volume_is_homogeneous<true>(kg,
state)) {
699 const Spectrum extinction = volume_shader_eval_extinction<true>(
717 OctreeTracing octree(ray->tmin);
720 if (!volume_octree_setup<true>(
721 kg, ray, sd,
state, &rng_state, path_visibility, path_flag, octree))
726 while (volume_octree_advance_shadow(
727 kg, ray, sd,
state, &rng_state, path_visibility, path_flag, octree))
729 const float sigma = octree.sigma.
range();
730 *throughput *= volume_transmittance<true>(
731 kg,
state, ray, sd, sigma, octree.t, &rng_state, path_visibility, path_flag);
736 octree.t.min = octree.t.max;
747# define VOLUME_SAMPLE_PDF_CUTOFF 1e-8f
754 const float delta =
dot((coeffs.P - ray->P), ray->D);
755 const float D =
len(coeffs.P - ray->P - ray->D * delta);
760 const float tmin = coeffs.t_range.min;
761 const float tmax = coeffs.t_range.max;
763 const float theta_a =
atan2f(tmin - delta,
D);
764 const float theta_b =
atan2f(tmax - delta,
D);
765 const float theta_d = theta_b - theta_a;
769 return mix(tmin, tmax, xi);
772 const float t_ =
D *
tanf((xi * theta_b) + (1 - xi) * theta_a);
773 *pdf =
D / (theta_d * (
D *
D + t_ * t_));
775 return clamp(delta + t_, tmin, tmax);
780 const float sample_t)
782 const float delta =
dot((coeffs.P - ray->P), ray->D);
783 const float D =
len(coeffs.P - ray->P - ray->D * delta);
788 const float tmin = coeffs.t_range.min;
789 const float tmax = coeffs.t_range.max;
791 const float theta_a =
atan2f(tmin - delta,
D);
792 const float theta_b =
atan2f(tmax - delta,
D);
793 const float theta_d = theta_b - theta_a;
798 const float t_ = sample_t - delta;
799 const float pdf =
D / (theta_d * (
D *
D + t_ * t_));
825 return !t_range->is_empty();
831 const int runtime_flag,
836 Spectrum emission = coeff->emission;
839 const Spectrum optical_depth = coeff->sigma_t * t;
840 emission *=
select(optical_depth > 1e-5f,
841 (1.0f -
exp(-optical_depth)) / coeff->sigma_t,
843 t * (1.0f - 0.5f * optical_depth));
854struct VolumeIntegrateState {
859 VolumeSampleMethod direct_sample_method;
863 float equiangular_pdf;
883 float majorant_scale;
885 float direct_rr_scale;
889# ifdef __DENOISING_FEATURES__
912 if (vstate.direct_sample_method != VOLUME_SAMPLE_EQUIANGULAR || vstate.use_mis ||
919 if (interval.contains(
result.direct_t)) {
921 t = {interval.min,
result.direct_t};
922 result.direct_scatter =
true;
931 result.direct_throughput *= volume_transmittance<false>(
932 kg,
state, ray, sd, sigma.range(), t, rng_state, path_visibility, path_flag);
939 const bool equiangular,
944 const float sigma_max = octree.sigma.max * vstate.majorant_scale;
945 residual_optical_depth = (octree.t.max - vstate.t) * sigma_max;
946 if (sigma_max == 0.0f) {
951 vstate.t += vstate.dt;
953 const bool segment_has_equiangular = equiangular && octree.t.contains(
result.direct_t);
954 if (segment_has_equiangular && vstate.t >
result.direct_t && !
result.direct_scatter) {
956 result.direct_scatter =
true;
957 result.direct_throughput =
result.indirect_throughput * vstate.transmittance *
958 vstate.direct_rr_scale;
959 vstate.sample_dt =
result.direct_t - vstate.t + vstate.dt;
960 vstate.distance_pdf = vstate.transmittance * sigma_max;
961 vstate.sigma_max = sigma_max;
965 return vstate.t > octree.t.max;
975 const uint32_t path_flag,
980 if (vstate.step++ > VOLUME_MAX_STEPS) {
985 float residual_optical_depth;
987 const bool equiangular = (vstate.direct_sample_method == VOLUME_SAMPLE_EQUIANGULAR) &&
991 volume_indirect_scatter_advance(octree, equiangular, residual_optical_depth, vstate, result))
994 if (!volume_octree_advance<false>(
995 kg, ray, sd,
state, rng_state, path_visibility, path_flag, octree))
1000 vstate.optical_depth += octree.sigma.max * octree.t.length();
1001 vstate.t = octree.t.min;
1002 volume_equiangular_transmittance(
1003 kg,
state, ray, octree.sigma, octree.t, sd, rng_state, vstate, result);
1006 vstate.rscatter =
saturatef(1.0f - (1.0f - vstate.rscatter) *
expf(residual_optical_depth));
1028struct VolumeSampleCandidate {
1033# ifdef __DENOISING_FEATURES__
1041struct VolumeSampleReservoir {
1042 float total_weight = 0.0f;
1044 VolumeSampleCandidate candidate;
1050 const VolumeSampleCandidate new_candidate)
1052 if (!(weight > 0.0f)) {
1056 total_weight += weight;
1057 const float thresh = weight / total_weight;
1059 if ((rand <= thresh) || (total_weight == weight)) {
1061 candidate = new_candidate;
1065 rand = (rand - thresh) / (1.0f - thresh);
1075 return total_weight == 0.0f;
1087 const ccl_global float *accumulated_optical_depth = buffer +
1092 return (*count == 0.0f) ?
FLT_MAX : *accumulated_optical_depth / *count;
1117 const float L_volume = L_transmitted + L_scattered;
1120 if (L_volume == 0.0f) {
1122 vstate.scatter_prob = 0.5f;
1127 vstate.scatter_prob =
fminf(L_scattered / L_volume, 0.9999f);
1130 const float optical_depth = volume_majorant_optical_depth(kg, buffer);
1135 vstate.majorant_scale = (optical_depth == 0.0f) ?
1137 -
fast_logf(1.0f - vstate.scatter_prob) / optical_depth;
1138 if (vstate.majorant_scale < 1.0f) {
1139 vstate.majorant_scale = 1.0f;
1140 vstate.scatter_prob = safe_divide(vstate.scatter_prob, 1.0f - fast_expf(-optical_depth));
1143 vstate.scatter_prob = 1.0f;
1157 if (reservoir.is_empty()) {
1162 (vstate.direct_sample_method == VOLUME_SAMPLE_DISTANCE);
1165 result.indirect_throughput = reservoir.candidate.throughput;
1166 vstate.emission = reservoir.candidate.emission;
1167# ifdef __DENOISING_FEATURES__
1168 vstate.albedo = reservoir.candidate.albedo;
1170 result.indirect_t = reservoir.candidate.t;
1172 if (sample_distance) {
1175 result.direct_scatter =
true;
1178 if (vstate.use_mis) {
1179 vstate.distance_pdf = reservoir.candidate.distance_pdf;
1185 const uint lcg_state = reservoir.candidate.lcg_state;
1187 if (sample_distance) {
1189 result.direct_throughput = reservoir.candidate.throughput * reservoir.total_weight;
1190 vstate.distance_pdf = reservoir.candidate.distance_pdf;
1194 vstate.emission =
mix(vstate.emission, reservoir.candidate.emission, reservoir.total_weight);
1195# ifdef __DENOISING_FEATURES__
1196 vstate.albedo =
mix(vstate.albedo, reservoir.candidate.albedo, reservoir.total_weight);
1199 const float unguided_scatter_prob = reservoir.total_weight;
1200 float guided_scatter_prob;
1203 guided_scatter_prob = 1.0f;
1207 const float alpha = 0.75f;
1208 reservoir.total_weight =
mix(reservoir.total_weight, vstate.scatter_prob, alpha);
1209 guided_scatter_prob = reservoir.total_weight;
1212 reservoir.add_sample(
1213 1.0f - guided_scatter_prob,
1215 { vstate.emission, reservoir.candidate.t,
result.indirect_throughput, 0.0f, vstate.albedo }
1217 {vstate.emission, reservoir.candidate.t,
result.indirect_throughput, 0.0f}
1222 const bool scatter = (reservoir.candidate.distance_pdf > 0.0f);
1223 const float scale =
scatter ? unguided_scatter_prob / guided_scatter_prob :
1224 (1.0f - unguided_scatter_prob) / (1.0f - guided_scatter_prob);
1225 result.indirect_throughput = reservoir.candidate.throughput *
scale;
1227 if (!
scatter && !sample_distance) {
1233 sd->P = ray->P + ray->D * reservoir.candidate.t;
1234 sd->lcg_state = lcg_state;
1236 if (!volume_shader_sample(kg,
state, sd, &coeff)) {
1242 if (sample_distance) {
1244 result.direct_scatter =
true;
1245 result.direct_t = reservoir.candidate.t;
1246 volume_shader_copy_phases(&
result.direct_phases, sd);
1251 result.indirect_scatter =
true;
1252 result.indirect_t = reservoir.candidate.t;
1253 volume_shader_copy_phases(&
result.indirect_phases, sd);
1267 return (
result.direct_scatter &&
result.indirect_scatter);
1279 if (
result.direct_scatter &&
result.indirect_scatter) {
1284 if (thresh > 0.05f) {
1290 const bool equiangular = (vstate.direct_sample_method == VOLUME_SAMPLE_EQUIANGULAR) &&
1291 vstate.use_mis && !
result.direct_scatter;
1293 const bool has_scatter_samples = !reservoir.is_empty() && !equiangular;
1298 if (absorption_only || has_scatter_samples) {
1299 if (reservoir.rand > thresh) {
1301 if (equiangular || (vstate.direct_sample_method == VOLUME_SAMPLE_DISTANCE)) {
1308 reservoir.rand =
saturatef(reservoir.rand / thresh);
1309 result.indirect_throughput /= thresh;
1314 if (reservoir.rand > thresh) {
1315 result.direct_scatter =
true;
1317 reservoir.rand = (reservoir.rand - thresh) / (1.0f - thresh);
1320 reservoir.rand /= thresh;
1321 vstate.direct_rr_scale /= thresh;
1323 reservoir.rand =
saturatef(reservoir.rand);
1337 const float sigma_max,
1346 const ccl_private VolumeShaderCoefficients &coeff,
1352 const Spectrum sigma_c = coeff.sigma_s + sigma_n;
1365 return dot(coeff.sigma_s / sigma_c, channel_pdf);
1370 const float sigma_max,
1376 const uint lcg_state,
1379 const float weight = vstate.transmittance * prob_s;
1380 const Spectrum throughput =
result.indirect_throughput * sigma_s / prob_s;
1384 reservoir.add_sample(
1387 {vstate.emission, vstate.t, throughput, weight * sigma_max, vstate.albedo, lcg_state}
1389 weight, {vstate.emission, vstate.t, throughput, weight * sigma_max, lcg_state}
1393 else if (!
result.indirect_scatter) {
1396 if (reservoir.rand <= prob_s) {
1398 reservoir.rand /= prob_s;
1401 result.indirect_scatter =
true;
1402 volume_shader_copy_phases(&
result.indirect_phases, sd);
1403 reservoir.add_sample(
1406 {vstate.emission, vstate.t, throughput, weight * sigma_max, vstate.albedo, lcg_state}
1408 weight, {vstate.emission, vstate.t, throughput, weight * sigma_max, lcg_state}
1412 if (vstate.direct_sample_method == VOLUME_SAMPLE_DISTANCE) {
1413 result.direct_scatter =
true;
1414 volume_shader_copy_phases(&
result.direct_phases, sd);
1419 reservoir.rand = (reservoir.rand - prob_s) / (1.0f - prob_s);
1421 reservoir.rand =
saturatef(reservoir.rand);
1441ccl_device void volume_integrate_step_scattering(
1445 const float sigma_max,
1451 if (volume_russian_roulette_termination(
state, reservoir, result, vstate)) {
1455 sd->P = ray->P + ray->D * vstate.t;
1457 const uint lcg_state = sd->lcg_state;
1458 if (!volume_shader_sample(kg,
state, sd, &coeff)) {
1466 const Spectrum sigma_n = volume_null_event_coefficients(coeff.sigma_t, sigma_max, majorant);
1467 if (majorant != sigma_max) {
1479 result.indirect_throughput *=
expf((sigma_max - majorant) * vstate.dt) / sigma_max;
1482 result.indirect_throughput /= majorant;
1488 vstate.emission +=
result.indirect_throughput * coeff.emission;
1489 if (!
result.indirect_scatter) {
1498 result.indirect_throughput *= sigma_n;
1502# ifdef __DENOISING_FEATURES__
1505 vstate.albedo +=
result.indirect_throughput * coeff.sigma_s;
1510 const float prob_s = volume_scatter_probability(coeff, sigma_n,
result.indirect_throughput);
1511 volume_sample_indirect_scatter(
1512 sigma_max, prob_s, coeff.sigma_s, sd, vstate, result, lcg_state, reservoir);
1515 const float prob_n = 1.0f - prob_s;
1517 vstate.transmittance *= prob_n;
1529 if (vstate.direct_sample_method != VOLUME_SAMPLE_EQUIANGULAR || !
result.direct_scatter) {
1533 sd->P = ray->P + ray->D *
result.direct_t;
1535 if (volume_shader_sample(kg,
state, sd, &coeff) && (sd->runtime_flag &
SR_SCATTER)) {
1536 volume_shader_copy_phases(&
result.direct_phases, sd);
1538 if (vstate.use_mis) {
1541 const Spectrum sigma_n = volume_null_event_coefficients(
1542 coeff.sigma_t, vstate.sigma_max, majorant);
1543 if ((vstate.sample_dt !=
FLT_MAX) && (majorant != vstate.sigma_max)) {
1544 result.direct_throughput *=
expf((vstate.sigma_max - majorant) * vstate.sample_dt);
1546 vstate.distance_pdf *= volume_scatter_probability(coeff, sigma_n,
result.direct_throughput);
1553 result.direct_scatter =
false;
1592 const ccl_private EquiangularCoefficients &equiangular_coeffs,
1595 if (!vstate.use_mis || !
result.direct_scatter) {
1600 if (vstate.direct_sample_method == VOLUME_SAMPLE_DISTANCE) {
1601 const float equiangular_pdf = volume_equiangular_pdf(ray, equiangular_coeffs,
result.direct_t);
1605 kernel_assert(vstate.direct_sample_method == VOLUME_SAMPLE_EQUIANGULAR);
1606 mis_weight =
power_heuristic(vstate.equiangular_pdf, vstate.distance_pdf);
1609 result.direct_throughput *= 2.0f * mis_weight;
1616 const VolumeSampleMethod direct_sample_method,
1624 vstate.direct_sample_method = direct_sample_method;
1625 vstate.use_mis = (direct_sample_method == VOLUME_SAMPLE_MIS);
1626 if (vstate.use_mis) {
1627 if (vstate.rscatter < 0.5f) {
1628 vstate.direct_sample_method = VOLUME_SAMPLE_DISTANCE;
1629 vstate.rscatter *= 2.0f;
1633 vstate.rscatter = (vstate.rscatter - 0.5f) * 2.0f;
1634 vstate.direct_sample_method = VOLUME_SAMPLE_EQUIANGULAR;
1638 vstate.distance_pdf = 0.0f;
1639 vstate.equiangular_pdf = 0.0f;
1640 vstate.sigma_max = 0.0f;
1641 vstate.transmittance = 1.0f;
1643 vstate.optical_depth = 0.0f;
1647 vstate.scatter_prob = 1.0f;
1648 vstate.majorant_scale = 1.0f;
1649 vstate.direct_rr_scale = 1.0f;
1651# ifdef __DENOISING_FEATURES__
1660 const ccl_private EquiangularCoefficients &equiangular_coeffs,
1664 result.direct_throughput = (vstate.direct_sample_method == VOLUME_SAMPLE_NONE) ?
1667 result.indirect_throughput = throughput;
1670 if (vstate.direct_sample_method == VOLUME_SAMPLE_EQUIANGULAR) {
1671 result.direct_t = volume_equiangular_sample(
1672 ray, equiangular_coeffs, vstate.rscatter, &vstate.equiangular_pdf);
1675# if defined(__PATH_GUIDING__)
1676 result.direct_sample_method = vstate.direct_sample_method;
1686 const float ray_length,
1687 const ccl_private VolumeShaderCoefficients &coeff,
1692 if (attenuation_only) {
1708 buffer +
kernel_data.film.pass_volume_scatter_denoised);
1710 buffer +
kernel_data.film.pass_volume_transmit_denoised);
1711 const Spectrum L_volume = L_transmitted + L_scattered;
1722 const float optical_depth = volume_majorant_optical_depth(kg, buffer);
1725 guided_scatter_prob =
clamp(
1730 return mix(attenuation, guided_scatter_prob, 0.75f);
1749 sd->P = ray->P + ray->D * ray->tmin;
1751 if (!volume_shader_sample(kg,
state, sd, &coeff)) {
1755 const float ray_length = ray->tmax - ray->tmin;
1761 const Spectrum emission = volume_emission_integrate(&coeff, sd->runtime_flag, ray_length);
1762 vstate.emission = throughput * emission;
1770 result.indirect_throughput *= transmittance;
1778 vstate.albedo = albedo * (1.0f - transmittance) * throughput;
1786 vstate.albedo + transmittance, throughput, &rchannel, &channel_pdf);
1788 const Spectrum scatter_prob = volume_scatter_probability_homogeneous(
1792 if (vstate.rscatter < scatter_pdf_channel) {
1794 vstate.rscatter /= scatter_pdf_channel;
1799 result.indirect_t = ray->tmin + dt;
1801 const float indirect_distance_pdf =
dot(distance_pdf * scatter_prob, channel_pdf);
1804 indirect_distance_pdf);
1805 volume_shader_copy_phases(&
result.indirect_phases, sd);
1809 const float indirect_distance_pdf =
dot((1.0f - scatter_prob), channel_pdf);
1810 result.indirect_throughput *=
safe_divide(transmittance, indirect_distance_pdf);
1811 vstate.rscatter = (vstate.rscatter - scatter_pdf_channel) / (1.0f - scatter_pdf_channel);
1816 if (vstate.direct_sample_method == VOLUME_SAMPLE_NONE) {
1823 volume_shader_copy_phases(&
result.direct_phases, sd);
1828 if (vstate.direct_sample_method == VOLUME_SAMPLE_DISTANCE) {
1831 result.direct_t = ray->tmin + dt;
1833 vstate.distance_pdf =
dot(distance_pdf, channel_pdf);
1835 result.direct_throughput *=
safe_divide(coeff.sigma_s * transmittance, vstate.distance_pdf);
1838 kernel_assert(vstate.direct_sample_method == VOLUME_SAMPLE_EQUIANGULAR);
1839 const float dt =
result.direct_t - ray->tmin;
1841 result.direct_throughput *=
safe_divide(coeff.sigma_s * transmittance, vstate.equiangular_pdf);
1842 if (vstate.use_mis) {
1863 OctreeTracing octree(ray->tmin);
1866 if (!volume_octree_setup<false>(
1867 kg, ray, sd,
state, &rng_state, path_visibility, path_flag, octree))
1873 vstate.optical_depth = octree.sigma.max * octree.t.length();
1882 volume_equiangular_transmittance(
1883 kg,
state, ray, octree.sigma, octree.t, sd, &rng_state, vstate, result);
1885 while (volume_integrate_advance(
1886 kg, ray, sd,
state, &rng_state, path_visibility, path_flag, octree, vstate, result))
1888 const float sigma_max = octree.sigma.max * vstate.majorant_scale;
1889 volume_integrate_step_scattering(kg,
state, ray, sigma_max, sd, vstate, result, reservoir);
1891 if (volume_integrate_should_stop(result)) {
1896 volume_distance_sampling_finalize(kg,
state, ray, sd, vstate, result, reservoir);
1897 volume_equiangular_direct_scatter(kg,
state, ray, sd, vstate, result);
1925 ray->tmax - ray->tmin,
1940 equiangular_coeffs->P = ls->P;
1942 return volume_valid_direct_ray_segment(kg, ray->P, ray->D, &equiangular_coeffs->t_range, ls);
1956 return VOLUME_SAMPLE_NONE;
1959 if (!integrate_volume_sample_direct_light(kg,
state, ray, sd, rng_state, coeffs, ls)) {
1960 return VOLUME_SAMPLE_NONE;
1964 const bool has_equiangular_sample = (ls->t !=
FLT_MAX);
1965 return has_equiangular_sample ? volume_stack_sample_method(kg,
state) : VOLUME_SAMPLE_DISTANCE;
1980 EquiangularCoefficients equiangular_coeffs = {
zero_float3(), {ray->tmin, ray->tmax}};
1981 const VolumeSampleMethod direct_sample_method = volume_direct_sample_method(
1982 kg,
state, ray, sd, rng_state, &equiangular_coeffs, ls);
1986 volume_integrate_state_init(kg,
state, direct_sample_method, rng_state, ray->tmin, vstate);
1989 volume_integrate_result_init(
state, ray, vstate, equiangular_coeffs, result);
1991 if (volume_is_homogeneous<false>(kg,
state)) {
1992 volume_integrate_homogeneous(
1993 kg,
state, ray, sd, rng_state,
render_buffer, vstate, equiangular_coeffs.t_range, result);
1996 volume_integrate_heterogeneous(kg,
state, ray, sd, *rng_state,
render_buffer, vstate, result);
1999 volume_direct_scatter_mis(ray, vstate, equiangular_coeffs, result);
2002 if (!
is_zero(vstate.emission)) {
2009# ifdef __DENOISING_FEATURES__
2012 film_write_denoising_features_volume(
2045template<const
bool shadow>
2048 const float object_step_size,
2053 vstep->t.min = vstep->t.max = tmin;
2055 if (object_step_size ==
FLT_MAX) {
2057 vstep->size = tmax - tmin;
2058 vstep->shade_offset = 0.0f;
2059 vstep->offset = 1.0f;
2060 vstep->max_steps = 1;
2064 vstep->max_steps =
kernel_data.integrator.volume_max_steps;
2065 const float t = tmax - tmin;
2066 float step_size =
min(object_step_size, t);
2068 if (t > vstep->max_steps * step_size) {
2070 step_size = t / (
float)vstep->max_steps;
2073 vstep->size = step_size;
2080 vstep->offset = 1.0f;
2093 if (vstep.t.max == ray->tmax) {
2099 vstep.t.min = vstep.t.max;
2100 vstep.t.max =
min(ray->tmax, ray->tmin + (
step + vstep.offset) * vstep.size);
2101 const float shade_t =
mix(vstep.t.min, vstep.t.max, vstep.shade_offset);
2102 *shade_P = ray->P + ray->D * shade_t;
2104 return step < vstep.max_steps;
2112 const float object_step_size)
2126 volume_step_init<true>(kg, &rng_state, object_step_size, ray->tmin, ray->tmax, &vstep);
2130 for (
int step = 0; volume_ray_marching_advance(
step, ray, &sd->P, vstep);
step++) {
2132 const Spectrum sigma_t = volume_shader_eval_extinction<true>(
2137 sum += (-sigma_t * vstep.t.length());
2138 if ((
step & 0x07) == 0) {
2139 tp = *throughput *
exp(sum);
2148 if (vstep.t.max == ray->tmax) {
2150 tp = *throughput *
exp(sum);
2156struct VolumeRayMarchingState {
2162 VolumeSampleMethod direct_sample_method;
2165 float equiangular_pdf;
2171 const VolumeSampleMethod direct_sample_method,
2178 vstate.direct_sample_method = direct_sample_method;
2179 vstate.use_mis = (direct_sample_method == VOLUME_SAMPLE_MIS);
2180 if (vstate.use_mis) {
2181 if (vstate.rscatter < 0.5f) {
2182 vstate.rscatter *= 2.0f;
2183 vstate.direct_sample_method = VOLUME_SAMPLE_DISTANCE;
2186 vstate.rscatter = (vstate.rscatter - 0.5f) * 2.0f;
2187 vstate.direct_sample_method = VOLUME_SAMPLE_EQUIANGULAR;
2190 vstate.equiangular_pdf = 0.0f;
2191 vstate.distance_pdf = 1.0f;
2195ccl_device bool volume_sample_indirect_scatter_ray_marching(
2205 if (
result.indirect_scatter) {
2213 if (1.0f - vstate.rscatter >= sample_transmittance) {
2219 const float new_dt = -
logf(1.0f - vstate.rscatter) / sample_sigma_t;
2220 const float new_t = t.min + new_dt;
2225 const float distance_pdf =
dot(channel_pdf, coeff.sigma_t * new_transmittance);
2227 if (vstate.distance_pdf * distance_pdf > VOLUME_SAMPLE_PDF_CUTOFF) {
2229 result.indirect_scatter =
true;
2230 result.indirect_t = new_t;
2231 result.indirect_throughput *= coeff.sigma_s * new_transmittance / distance_pdf;
2232 if (vstate.direct_sample_method == VOLUME_SAMPLE_DISTANCE) {
2233 vstate.distance_pdf *= distance_pdf;
2236 volume_shader_copy_phases(&
result.indirect_phases, sd);
2243 const float distance_pdf =
dot(channel_pdf, transmittance);
2244 result.indirect_throughput *= transmittance / distance_pdf;
2245 if (vstate.direct_sample_method == VOLUME_SAMPLE_DISTANCE) {
2246 vstate.distance_pdf *= distance_pdf;
2250 vstate.rscatter = 1.0f - (1.0f - vstate.rscatter) / sample_transmittance;
2260 const ccl_private EquiangularCoefficients &equiangular_coeffs,
2275 albedo,
result.indirect_throughput, &vstate.rchannel, &channel_pdf);
2278 if (vstate.direct_sample_method == VOLUME_SAMPLE_EQUIANGULAR && !
result.direct_scatter) {
2279 if (t.contains(
result.direct_t) && vstate.equiangular_pdf > VOLUME_SAMPLE_PDF_CUTOFF) {
2280 const float new_dt =
result.direct_t - t.min;
2283 result.direct_scatter =
true;
2285 vstate.equiangular_pdf);
2286 volume_shader_copy_phases(&
result.direct_phases, sd);
2289 if (vstate.use_mis) {
2290 const float distance_pdf = vstate.distance_pdf *
2291 dot(channel_pdf, coeff.sigma_t * new_transmittance);
2292 const float mis_weight = 2.0f *
power_heuristic(vstate.equiangular_pdf, distance_pdf);
2293 result.direct_throughput *= mis_weight;
2297 result.direct_throughput *= transmittance;
2298 vstate.distance_pdf *=
dot(channel_pdf, transmittance);
2303 if (volume_sample_indirect_scatter_ray_marching(
2304 transmittance, channel_pdf, channel, sd, coeff, t, vstate, result))
2306 if (vstate.direct_sample_method == VOLUME_SAMPLE_DISTANCE) {
2309 result.direct_scatter =
true;
2312 volume_shader_copy_phases(&
result.direct_phases, sd);
2315 if (vstate.use_mis) {
2316 const float equiangular_pdf = volume_equiangular_pdf(
2317 ray, equiangular_coeffs,
result.indirect_t);
2318 const float mis_weight =
power_heuristic(vstate.distance_pdf, equiangular_pdf);
2319 result.direct_throughput *= 2.0f * mis_weight;
2336 const float object_step_size,
2342 EquiangularCoefficients equiangular_coeffs = {
zero_float3(), {ray->tmin, ray->tmax}};
2343 const VolumeSampleMethod direct_sample_method = volume_direct_sample_method(
2344 kg,
state, ray, sd, rng_state, &equiangular_coeffs, ls);
2348 volume_step_init<false>(kg, rng_state, object_step_size, ray->tmin, ray->tmax, &vstep);
2352 volume_ray_marching_state_init(kg, rng_state, direct_sample_method, vstate);
2356 result.direct_throughput = (vstate.direct_sample_method == VOLUME_SAMPLE_NONE) ?
2359 result.indirect_throughput = throughput;
2362 if (vstate.direct_sample_method == VOLUME_SAMPLE_EQUIANGULAR) {
2363 result.direct_t = volume_equiangular_sample(
2364 ray, equiangular_coeffs, vstate.rscatter, &vstate.equiangular_pdf);
2366# if defined(__PATH_GUIDING__)
2367 result.direct_sample_method = vstate.direct_sample_method;
2370# ifdef __DENOISING_FEATURES__
2377 for (
int step = 0; volume_ray_marching_advance(
step, ray, &sd->P, vstep);
step++) {
2380 if (volume_shader_sample(kg,
state, sd, &coeff)) {
2381 const int runtime_flag = sd->runtime_flag;
2384 const float dt = vstep.t.length();
2393 if (!
result.indirect_scatter) {
2394 const Spectrum emission = volume_emission_integrate(&coeff, runtime_flag, dt);
2395 accum_emission +=
result.indirect_throughput * emission;
2401# ifdef __DENOISING_FEATURES__
2403 if (write_denoising_features && (runtime_flag &
SR_SCATTER)) {
2405 accum_albedo +=
result.indirect_throughput * albedo * (
one_spectrum() - transmittance);
2410 volume_ray_marching_step_scattering(
2411 sd, ray, equiangular_coeffs, coeff, transmittance, vstep.t, vstate, result);
2415 result.indirect_throughput *= transmittance;
2416 result.direct_throughput *= transmittance;
2419 if (volume_integrate_should_stop(result)) {
2426 if (!
is_zero(accum_emission)) {
2433# ifdef __DENOISING_FEATURES__
2435 if (write_denoising_features) {
2436 film_write_denoising_features_volume(
2453#
if defined(__PATH_GUIDING__)
2496 kg, ls.shader, ls.prim, ls.type !=
LIGHT_TRIANGLE, light_shader_eval);
2500 const float phase_pdf = volume_shader_phase_eval(
2501 kg,
state, sd, phases, ls.D, &phase_eval, ls.shader);
2503 bsdf_eval_mul(&phase_eval, light_shader_eval * ls.eval_fac / ls.pdf * mis_weight);
2540 const Spectrum throughput_phase = throughput * phase_sum;
2572 state, path, render_pixel_index);
2574 state, path, rng_offset);
2576 state, path, rng_pixel);
2584 state, path, diffuse_bounce);
2586 state, path, glossy_bounce);
2588 state, path, transmission_bounce);
2590 state, path, volume_bounds_bounce);
2596# if defined(__PATH_GUIDING__)
2600 state, guiding, path_segment);
2601 INTEGRATOR_STATE(shadow_state, shadow_path, guiding_light_linking_mis_weight) = 0.0f;
2605 integrator_state_copy_volume_stack_to_shadow(kg, shadow_state,
state);
2624 float phase_pdf = 0.0f;
2625 float unguided_phase_pdf = 0.0f;
2628 float sampled_roughness = 1.0f;
2631# if defined(__PATH_GUIDING__) && PATH_GUIDING_LEVEL >= 4
2635 label = volume_shader_phase_guided_sample(kg,
2644 &unguided_phase_pdf,
2645 &sampled_roughness);
2656 label = volume_shader_phase_sample(
2657 sd, phases, svc, rand_phase, &phase_eval, &phase_wo, &phase_pdf, &sampled_roughness);
2663 unguided_phase_pdf = phase_pdf;
2670# ifdef __LIGHT_TREE__
2676# ifdef __RAY_DIFFERENTIALS__
2689 kg,
state, phase_weight, phase_pdf,
normalize(phase_wo), sampled_roughness);
2693 const Spectrum throughput_phase = throughput * phase_weight;
2705 const float3 previous_P = ray->P + ray->D * ray->tmin;
2710# ifdef __LIGHT_LINKING__
2729# if defined(__PATH_GUIDING__) && PATH_GUIDING_LEVEL >= 1
2735 bool guiding_generated_new_segment =
false;
2736 float rand_phase_guiding = 0.5f;
2746 state, path, continuation_probability));
2747 if (continuation_probability == 0.0f) {
2752 if (
result.direct_scatter) {
2753 const float3 direct_P = ray->P + result.direct_t * ray->D;
2755# if defined(__PATH_GUIDING__)
2756 if (kernel_data.integrator.use_guiding) {
2757# if PATH_GUIDING_LEVEL >= 1
2758 if (result.indirect_scatter && result.direct_t == result.indirect_t) {
2761 const float3 transmittance_weight = spectrum_to_rgb(
2762 safe_divide_color(result.indirect_throughput, initial_throughput));
2763 guiding_record_volume_transmission(kg, state, transmittance_weight);
2764 guiding_record_volume_segment(kg, state, direct_P, sd->wi);
2765 guiding_generated_new_segment = true;
2766 unlit_throughput = result.indirect_throughput / continuation_probability;
2767 rand_phase_guiding = path_state_rng_1D(kg, rng_state, PRNG_VOLUME_PHASE_GUIDING_DISTANCE);
2775 float3 scatterEval = one_float3();
2776 if (INTEGRATOR_STATE(state, guiding, path_segment)) {
2777 const pgl_vec3f scatteringWeight =
2778 INTEGRATOR_STATE(state, guiding, path_segment)->scatteringWeight;
2779 scatterEval = make_float3(scatteringWeight.x, scatteringWeight.y, scatteringWeight.z);
2780 unlit_throughput = safe_divide(unlit_throughput, scatterEval);
2782 unlit_throughput *= continuation_probability;
2783 rand_phase_guiding = path_state_rng_1D(
2784 kg, rng_state, PRNG_VOLUME_PHASE_GUIDING_EQUIANGULAR);
2787# if PATH_GUIDING_LEVEL >= 4
2788 if ((kernel_data.kernel_features & KERNEL_FEATURE_PATH_GUIDING)) {
2790 volume_shader_prepare_guiding(
2791 kg, state, rand_phase_guiding, direct_P, ray->D, &result.direct_phases);
2797 result.direct_throughput /= continuation_probability;
2798 integrate_volume_direct_light(kg,
2804#
if defined(__PATH_GUIDING__)
2807 result.direct_throughput,
2815 if (
result.indirect_scatter) {
2816# if defined(__PATH_GUIDING__) && PATH_GUIDING_LEVEL >= 1
2817 if (!guiding_generated_new_segment) {
2818 const float3 transmittance_weight = spectrum_to_rgb(
2819 safe_divide_color(result.indirect_throughput, initial_throughput));
2820 guiding_record_volume_transmission(kg, state, transmittance_weight);
2823 result.indirect_throughput /= continuation_probability;
2827 if (
result.indirect_scatter) {
2828 sd->P = ray->P +
result.indirect_t * ray->D;
2830# if defined(__PATH_GUIDING__)
2832# if PATH_GUIDING_LEVEL >= 1
2833 if (!guiding_generated_new_segment) {
2837# if PATH_GUIDING_LEVEL >= 4
2842 volume_shader_prepare_guiding(
2843 kg,
state, rand_phase_guiding, sd->P, ray->D, &
result.indirect_phases);
2849 if (integrate_volume_phase_scatter(kg,
state, sd, ray, rng_state, &
result.indirect_phases)) {
2854# if defined(__PATH_GUIDING__)
2874 if (integrator_state_volume_stack_is_empty(kg,
state)) {
2894 VolumeIntegrateResult
result = {};
2895 volume_integrate_null_scattering(kg,
state, ray, &sd, &rng_state,
render_buffer, &ls, result);
2901 return volume_integrate_event(kg,
state, ray, &sd, &rng_state, ls, result);
2912 if (integrator_state_volume_stack_is_empty(kg,
state)) {
2932 VolumeIntegrateResult
result = {};
2934 const float step_size = volume_stack_step_size<false>(kg,
state);
2935 volume_integrate_ray_marching(
2942 return volume_integrate_event(kg,
state, ray, &sd, &rng_state, ls, result);
2964 volume_stack_clean(kg,
state);
2974template<DeviceKernel volume_kernel>
2994#ifdef __SHADOW_LINKING__
2995 if (shadow_linking_schedule_intersection_kernel<volume_kernel>(kg,
state)) {
3013 integrator_shade_volume_setup(kg,
state, &ray, &isect);
3033 integrator_shade_volume_setup(kg,
state, &ray, &isect);
blender::float3 packed_float3
ccl_device_inline bool area_light_valid_ray_segment(const ccl_global KernelAreaLight *light, float3 P, float3 D, ccl_private Interval< float > *t_range)
SIMD_FORCE_INLINE const btScalar & z() const
Return the z value.
ccl_device_inline Spectrum safe_divide_color(Spectrum a, Spectrum b, const float fallback=0.0f)
ccl_device_inline bool light_sample_terminate(KernelGlobals kg, ccl_private BsdfEval *ccl_restrict eval, const float rand_terminate)
ccl_device_inline void light_sample_to_volume_shadow_ray(const ccl_private ShaderData *ccl_restrict sd, const ccl_private LightSample *ccl_restrict ls, const float3 P, ccl_private Ray *ray)
ccl_device_inline float light_sample_mis_weight_nee(KernelGlobals kg, const float nee_pdf, const float forward_pdf)
CCL_NAMESPACE_BEGIN ccl_device bool light_sample_shader_eval_nee_constant(KernelGlobals kg, const int shader_id, const int prim, const bool is_light, ccl_private Spectrum &eval)
ccl_device_inline bool light_sample_from_volume_segment(KernelGlobals kg, const float3 rand, const float time, const float3 P, const float3 D, const float t, const int object_receiver, const int bounce, const uint32_t path_flag, ccl_private LightSample *ls)
#define kernel_assert(cond)
#define KERNEL_FEATURE_LIGHT_TREE
#define CLOSURE_IS_VOLUME(type)
#define ccl_device_forceinline
#define KERNEL_FEATURE_PATH_GUIDING
#define ccl_optional_struct_init
#define kernel_data_fetch(name, index)
#define ccl_device_inline
#define KERNEL_FEATURE_LIGHT_PASSES
#define __DENOISING_FEATURES__
#define KERNEL_FEATURE_LIGHT_LINKING
#define VOLUME_OCTREE_MAX_DEPTH
#define ccl_device_noinline
#define ccl_device_inline_method
#define CCL_NAMESPACE_END
ccl_device_forceinline float differential_make_compact(const float dD)
IMETHOD Vector diff(const Vector &a, const Vector &b, double dt)
VecBase< float, D > normalize(VecOp< float, D >) RET
float dot(VecOp< float, D >, VecOp< float, D >) RET
bool all(VecOp< bool, D >) RET
VecBase< float, D > step(VecOp< float, D >, VecOp< float, D >) RET
constexpr T clamp(T, U, U) RET
VecBase< float, 3 > float3
float3x3 scale(float3x3 mat, float2 scale)
float safe_divide(float a, float b)
float reduce_add(float2 a)
float reduce_min(float2 a)
float reduce_max(float2 a)
ccl_device_forceinline void integrator_intersect_next_kernel_after_volume(KernelGlobals kg, IntegratorState state, const ccl_private Intersection *ccl_restrict isect, ccl_global float *ccl_restrict render_buffer)
ccl_device_forceinline float volume_phase_widen_dD(const KernelGlobals kg, const float prev_dD, const float sampled_roughness)
#define VOLUME_THROUGHPUT_EPSILON
ccl_device Spectrum volume_color_transmittance(Spectrum sigma, const float t)
ccl_device int volume_sample_channel(Spectrum albedo, Spectrum throughput, ccl_private float *rand, ccl_private Spectrum *pdf)
ccl_device_inline Spectrum volume_sample_channel_pdf(Spectrum albedo, Spectrum throughput)
ccl_device float volume_channel_get(Spectrum value, const int channel)
ccl_gpu_kernel_postfix ccl_global KernelWorkTile const int ccl_global float * render_buffer
@ OBJECT_INVERSE_TRANSFORM
ccl_device_inline float object_volume_density(KernelGlobals kg, const int object)
ccl_device_inline int object_lightgroup(KernelGlobals kg, const int object)
ccl_device_inline Transform object_fetch_transform(KernelGlobals kg, const int object, enum ObjectTransform type)
ccl_device_forceinline void guiding_record_volume_segment(ccl_attr_maybe_unused KernelGlobals kg, ccl_attr_maybe_unused IntegratorState state, ccl_attr_maybe_unused const float3 P, ccl_attr_maybe_unused const float3 I)
ccl_device_forceinline void guiding_record_volume_bounce(ccl_attr_maybe_unused KernelGlobals kg, ccl_attr_maybe_unused IntegratorState state, ccl_attr_maybe_unused const Spectrum weight, ccl_attr_maybe_unused const float pdf, ccl_attr_maybe_unused const float3 wo, ccl_attr_maybe_unused const float roughness)
ccl_device_forceinline void guiding_record_volume_emission(ccl_attr_maybe_unused KernelGlobals kg, ccl_attr_maybe_unused IntegratorState state, ccl_attr_maybe_unused const Spectrum Le)
ccl_device_inline bool light_sample(KernelGlobals kg, const int lamp, const float2 rand, const float3 P, const float3 N, const int runtime_flags, const uint32_t path_flag, ccl_private LightSample *ls)
ccl_device_inline bool light_link_object_match(KernelGlobals kg, const int receiver, const int emitter)
ccl_device_inline int light_link_receiver_nee(KernelGlobals kg, const ccl_private ShaderData *sd)
ccl_device_inline int light_link_receiver_forward(KernelGlobals kg, IntegratorState state)
uint32_t PathRayVisibility
@ SR_BSDF_HAS_TRANSMISSION
@ PRNG_VOLUME_EXPANSION_ORDER
@ PRNG_VOLUME_SHADE_OFFSET
@ PRNG_VOLUME_PHASE_GUIDING_DISTANCE
@ PRNG_VOLUME_COLOR_CHANNEL
@ PRNG_VOLUME_SCATTER_DISTANCE
@ PATH_RAY_TERMINATE_IN_NEXT_VOLUME
@ PATH_RAY_DENOISING_FEATURES
@ PATH_RAY_VOLUME_PRIMARY_TRANSMIT
@ PATH_RAY_VISIBILITY_VOLUME_SCATTER
@ PATH_RAY_VISIBILITY_CAMERA
@ PATH_RAY_VISIBILITY_SHADOW
@ SD_OBJECT_TRANSFORM_APPLIED
@ DEVICE_KERNEL_INTEGRATOR_SHADE_VOLUME_RAY_MARCHING
@ DEVICE_KERNEL_INTEGRATOR_SHADE_LIGHT_NEE
@ DEVICE_KERNEL_INTEGRATOR_SHADE_VOLUME
@ DEVICE_KERNEL_INTEGRATOR_INTERSECT_SHADOW
@ DEVICE_KERNEL_INTEGRATOR_INTERSECT_CLOSEST
ccl_device_inline uint lcg_state_init(const uint rng_hash, const uint rng_offset, const uint sample, const uint scramble)
ccl_device_inline bool triangle_light_valid_ray_segment(KernelGlobals kg, const float3 P, const float3 D, ccl_private Interval< float > *t_range, const ccl_private LightSample *ls)
ccl_device_inline bool bsdf_eval_is_zero(ccl_private BsdfEval *eval)
ccl_device_inline void film_write_volume_emission(KernelGlobals kg, ConstIntegratorState state, const Spectrum L, ccl_global float *ccl_restrict render_buffer, const int lightgroup=LIGHTGROUP_NONE)
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)
OrientationBounds merge(const OrientationBounds &cone_a, const OrientationBounds &cone_b)
ccl_device_inline uint count_leading_zeros(const uint x)
ccl_device_inline int power_of_2(const int a)
ccl_device_inline bool isfinite_safe(const float f)
ccl_device_inline dual1 len(const ccl_private dual< T > &a)
ccl_device_inline dual3 fabs(const ccl_private dual3 &a)
ccl_device_inline float fast_logf(const float x)
ccl_device_inline float2 mask(const MaskType mask, const float2 a)
CCL_NAMESPACE_BEGIN ccl_device_inline float3 zero_float3()
ccl_device_inline uint3 float3_as_uint3(const float3 f)
#define PROFILING_INIT(kg, event)
ccl_device float power_heuristic(const float a, const float b)
int size(const AssetLibraryReference *library_reference)
constexpr float ray_length
closure color scatter(string phase, float Anisotropy, float IOR, float Backscatter, float Alpha, float Diameter)
ccl_device_inline float path_state_rng_1D(KernelGlobals kg, const ccl_private RNGState *rng_state, const int dimension)
ccl_device_inline void shadow_path_state_rng_load(ConstIntegratorShadowState state, ccl_private RNGState *rng_state)
ccl_device_inline float path_state_rng_light_termination(KernelGlobals kg, const ccl_private RNGState *state)
ccl_device_inline void path_state_rng_load(ConstIntegratorState state, ccl_private RNGState *rng_state)
ccl_device_inline void path_state_next(KernelGlobals kg, IntegratorState state, const int label, const int runtime_flag)
ccl_device_inline void path_state_rng_scramble(ccl_private RNGState *rng_state, const int seed)
ccl_device_inline float2 path_state_rng_2D(KernelGlobals kg, const ccl_private RNGState *rng_state, const int dimension)
ccl_device_inline float3 path_state_rng_3D(KernelGlobals kg, const ccl_private RNGState *rng_state, const int dimension)
ccl_device_forceinline float path_rng_1D(KernelGlobals kg, const uint rng_pixel, const uint sample, const int dimension)
@ PROFILING_SHADE_VOLUME_INTEGRATE
@ PROFILING_SHADE_VOLUME_SETUP
@ PROFILING_SHADE_VOLUME_DIRECT_LIGHT
@ PROFILING_SHADE_VOLUME_INDIRECT_LIGHT
ccl_device_inline float sample_exponential_distribution(const float rand, const float lambda)
ccl_device_inline int sample_geometric_distribution(const float rand, const float r, ccl_private float &pmf, const int cut_off=INT_MAX)
ccl_device_inline Spectrum pdf_exponential_distribution(const float x, const Spectrum lambda, const Interval< float > t)
ccl_device void integrator_shade_volume_ray_marching(KernelGlobals kg, IntegratorState state, ccl_global float *ccl_restrict render_buffer)
ccl_device void integrator_shade_volume(KernelGlobals kg, IntegratorState state, ccl_global float *ccl_restrict render_buffer)
ccl_device_inline void integrator_next_kernel_after_shade_volume(KernelGlobals kg, const IntegratorState state, ccl_global float *ccl_restrict render_buffer, const ccl_private Intersection *ccl_restrict isect, const VolumeIntegrateEvent event)
KERNEL_FEATURE_LIGHT_PASSES KERNEL_FEATURE_PATH_GUIDING bsdf_eval_average
KERNEL_FEATURE_LIGHT_PASSES KERNEL_FEATURE_PATH_GUIDING float
KERNEL_FEATURE_LIGHT_PASSES unlit_throughput
ccl_device_inline bool spot_light_valid_ray_segment(KernelGlobals kg, const ccl_global KernelLight *klight, const float3 P, const float3 D, ccl_private Interval< float > *t_range)
IntegratorShadowStateCPU * IntegratorShadowState
#define INTEGRATOR_STATE_WRITE(state, nested_struct, member)
#define INTEGRATOR_STATE(state, nested_struct, member)
#define INTEGRATOR_STATE_ARRAY(state, nested_struct, array_index, member)
IntegratorStateCPU * IntegratorState
const IntegratorStateCPU * ConstIntegratorState
ccl_device_forceinline void integrator_path_cache_miss(IntegratorState, const DeviceKernel)
ccl_device_forceinline void integrator_path_next(IntegratorState state, const DeviceKernel current_kernel, const DeviceKernel next_kernel)
ccl_device_forceinline void integrator_path_terminate(KernelGlobals kg, IntegratorState state, ccl_global float *ccl_restrict render_buffer, const DeviceKernel current_kernel)
ccl_device_forceinline IntegratorShadowState integrator_shadow_path_init(ccl_attr_maybe_unused KernelGlobals kg, IntegratorState state, const DeviceKernel next_kernel, const bool is_ao)
ccl_device_forceinline void integrator_state_write_shadow_ray_self(IntegratorShadowState state, const ccl_private Ray *ccl_restrict ray)
ccl_device_forceinline void integrator_state_read_ray(ConstIntegratorState state, ccl_private Ray *ccl_restrict ray)
ccl_device_forceinline void integrator_state_write_shadow_ray(IntegratorShadowState state, const ccl_private Ray *ccl_restrict ray)
ccl_device_forceinline void integrator_state_read_isect(ConstIntegratorState state, ccl_private Intersection *ccl_restrict isect)
ccl_device_inline_method T range() const
ccl_device_inline_method T length() const
ccl_device_inline_method bool is_empty() const
packed_float3 PackedSpectrum
CCL_NAMESPACE_BEGIN ccl_device_forceinline ccl_global float * film_pass_pixel_render_buffer(KernelGlobals kg, ConstIntegratorState state, ccl_global float *ccl_restrict render_buffer)
ccl_device_inline float3 kernel_read_pass_rgbe(const ccl_global float *ccl_restrict buffer)