21 int cdf_width = res_x + 1;
28 int step =
count >> 1;
29 int middle = first + step;
39 int index_v =
max(0, first - 1);
48 float v = (index_v + dv) / res_y;
54 int step =
count >> 1;
55 int middle = first + step;
57 if (
kernel_data_fetch(light_background_conditional_cdf, index_v * cdf_width + middle).y <
67 int index_u =
max(0, first - 1);
71 index_v * cdf_width + index_u);
73 index_v * cdf_width + index_u + 1);
75 index_v * cdf_width + res_x);
79 float u = (index_u + du) / res_x;
88 *pdf = (cdf_u.
x * cdf_v.
x) / denom;
102 int cdf_width = res_x + 1;
114 index_v * cdf_width + res_x);
124 index_v * cdf_width + index_u);
127 return (cdf_u.
x * cdf_v.
x) / denom;
133 int portal =
kernel_data.integrator.portal_offset + index;
136 *lightpos = klight->co;
137 *dir = klight->area.dir;
140 if (
dot(*dir,
P - *lightpos) > 1e-4f)
149 float portal_pdf = 0.0f;
151 int num_possible = 0;
152 for (
int p = 0; p <
kernel_data.integrator.num_portals; p++) {
153 if (p == ignore_portal)
166 int portal =
kernel_data.integrator.portal_offset + p;
169 const float3 axis_u = klight->area.axis_u;
170 const float len_u = klight->area.len_u;
171 const float3 axis_v = klight->area.axis_v;
172 const float len_v = klight->area.len_v;
173 const float3 inv_extent_u = axis_u / len_u;
174 const float3 inv_extent_v = axis_v / len_v;
176 bool is_round = (klight->area.invarea < 0.0f);
200 P, &lightpos, axis_u, len_u, axis_v, len_v,
zero_float2(),
false);
204 if (ignore_portal >= 0) {
209 return (num_possible > 0) ? portal_pdf / num_possible : 0.0f;
214 int num_possible_portals = 0;
215 for (
int p = 0; p <
kernel_data.integrator.num_portals; p++) {
218 num_possible_portals++;
220 return num_possible_portals;
231 rand.
y *= num_possible;
232 int portal = (
int)rand.
y;
238 for (
int p = 0; p <
kernel_data.integrator.num_portals; p++) {
246 int portal =
kernel_data.integrator.portal_offset + p;
248 const float3 axis_u = klight->area.axis_u;
249 const float3 axis_v = klight->area.axis_v;
250 const float len_u = klight->area.len_u;
251 const float len_v = klight->area.len_v;
252 bool is_round = (klight->area.invarea < 0.0f);
256 lightpos +=
ellipse_sample(axis_u * len_u * 0.5f, axis_v * len_v * 0.5f, rand);
266 *pdf /= num_possible;
299 float portal_method_pdf =
kernel_data.background.portal_weight;
300 float sun_method_pdf =
kernel_data.background.sun_weight;
301 float map_method_pdf =
kernel_data.background.map_weight;
304 if (portal_method_pdf > 0.0f) {
307 if (num_portals == 0) {
308 portal_method_pdf = 0.0f;
312 float pdf_fac = (portal_method_pdf + sun_method_pdf + map_method_pdf);
313 if (pdf_fac == 0.0f) {
315 *pdf = 1.0f / M_4PI_F;
319 pdf_fac = 1.0f / pdf_fac;
320 portal_method_pdf *= pdf_fac;
321 sun_method_pdf *= pdf_fac;
322 map_method_pdf *= pdf_fac;
328 float sun_method_cdf = portal_method_pdf + sun_method_pdf;
332 if (rand.
x < portal_method_pdf) {
335 if (portal_method_pdf != 1.0f) {
336 rand.
x /= portal_method_pdf;
342 if (num_portals > 1) {
348 if (portal_method_pdf == 1.0f) {
351 *pdf *= portal_method_pdf;
353 else if (rand.
x < sun_method_cdf) {
356 if (sun_method_pdf != 1.0f) {
357 rand.
x = (rand.
x - portal_method_pdf) / sun_method_pdf;
363 if (sun_method_pdf == 1.0f) {
366 *pdf *= sun_method_pdf;
371 if (map_method_pdf != 1.0f) {
372 rand.
x = (rand.
x - sun_method_cdf) / map_method_pdf;
378 if (map_method_pdf == 1.0f) {
381 *pdf *= map_method_pdf;
385 if (method != 0 && portal_method_pdf != 0.0f) {
388 if (method != 1 && sun_method_pdf != 0.0f) {
391 if (method != 2 && map_method_pdf != 0.0f) {
399 float portal_method_pdf =
kernel_data.background.portal_weight;
400 float sun_method_pdf =
kernel_data.background.sun_weight;
401 float map_method_pdf =
kernel_data.background.map_weight;
403 float portal_pdf = 0.0f;
406 if (portal_method_pdf > 0.0f) {
408 bool is_possible =
false;
414 portal_method_pdf = 0.0f;
418 float pdf_fac = (portal_method_pdf + sun_method_pdf + map_method_pdf);
419 if (pdf_fac == 0.0f) {
421 return 1.0f / M_4PI_F;
424 pdf_fac = 1.0f / pdf_fac;
425 portal_method_pdf *= pdf_fac;
426 sun_method_pdf *= pdf_fac;
427 map_method_pdf *= pdf_fac;
429 float pdf = portal_pdf * portal_method_pdf;
430 if (sun_method_pdf != 0.0f) {
433 if (map_method_pdf != 0.0f) {
440template<
bool in_volume_segment>
448 if (in_volume_segment) {
460 point_to_centroid = -centroid;
CCL_NAMESPACE_BEGIN ccl_device_inline float area_light_rect_sample(float3 P, ccl_private float3 *light_p, const float3 axis_u, const float len_u, const float3 axis_v, const float len_v, const float2 rand, bool sample_coord)
ATTR_WARN_UNUSED_RESULT const BMVert * v
ccl_device_inline float sin_theta(const float3 w)
SIMD_FORCE_INLINE btVector3 & normalize()
Normalize this vector x^2 + y^2 + z^2 = 1.
additional_info("compositor_sum_squared_difference_float_shared") .push_constant(Type output_img float dot(value.rgb, luminance_coefficients)") .define("LOAD(value)"
ccl_device float3 equirectangular_to_direction(float u, float v)
ccl_device float2 direction_to_equirectangular(float3 dir)
#define kernel_assert(cond)
const KernelGlobalsCPU *ccl_restrict KernelGlobals
#define kernel_data_fetch(name, index)
#define ccl_device_forceinline
#define ccl_device_inline
#define CCL_NAMESPACE_END
draw_view push_constant(Type::INT, "radiance_src") .push_constant(Type capture_info_buf storage_buf(1, Qualifier::READ, "ObjectBounds", "bounds_buf[]") .push_constant(Type draw_view int
ccl_device_inline float3 background_light_sample(KernelGlobals kg, float3 P, float2 rand, ccl_private float *pdf)
ccl_device_forceinline bool background_light_tree_parameters(const float3 centroid, const float t, ccl_private float &cos_theta_u, ccl_private float2 &distance, ccl_private float3 &point_to_centroid, ccl_private float &theta_d)
ccl_device_inline bool background_portal_data_fetch_and_check_side(KernelGlobals kg, float3 P, int index, ccl_private float3 *lightpos, ccl_private float3 *dir)
ccl_device float3 background_portal_sample(KernelGlobals kg, float3 P, float2 rand, int num_possible, ccl_private int *sampled_portal, ccl_private float *pdf)
ccl_device int background_num_possible_portals(KernelGlobals kg, float3 P)
CCL_NAMESPACE_BEGIN ccl_device float3 background_map_sample(KernelGlobals kg, float2 rand, ccl_private float *pdf)
ccl_device_inline float background_portal_pdf(KernelGlobals kg, float3 P, float3 direction, int ignore_portal, ccl_private bool *is_possible)
ccl_device float background_light_pdf(KernelGlobals kg, float3 P, float3 direction)
ccl_device_inline float background_sun_pdf(KernelGlobals kg, float3 D)
ccl_device float background_map_pdf(KernelGlobals kg, float3 direction)
ccl_device_inline float3 background_sun_sample(KernelGlobals kg, float2 rand, ccl_private float *pdf)
ccl_device_inline float3 ellipse_sample(float3 ru, float3 rv, float2 rand)
ccl_device float light_pdf_area_to_solid_angle(const float3 Ng, const float3 I, float t)
CCL_NAMESPACE_BEGIN ccl_device_inline float2 zero_float2()
ccl_device_inline float2 normalize_len(const float2 a, ccl_private float *t)
CCL_NAMESPACE_BEGIN ccl_device_inline float3 zero_float3()
ccl_device bool ray_quad_intersect(float3 ray_P, float3 ray_D, float ray_tmin, float ray_tmax, float3 quad_P, float3 inv_quad_u, float3 inv_quad_v, float3 quad_n, ccl_private float3 *isect_P, ccl_private float *isect_t, ccl_private float *isect_u, ccl_private float *isect_v, bool ellipse)
ccl_device float3 sample_uniform_sphere(const float2 rand)
ccl_device_inline float pdf_uniform_cone(const float3 N, float3 D, float angle)
ccl_device_inline float3 sample_uniform_cone(const float3 N, const float one_minus_cos_angle, const float2 rand, ccl_private float *cos_theta, ccl_private float *pdf)
ccl_device_inline float inverse_lerp(float a, float b, float x)
ccl_device_inline int float_to_int(float f)
ccl_device_inline float3 float4_to_float3(const float4 a)
ccl_device_inline float one_minus_cos(const float angle)
ccl_device_inline int clamp(int a, int mn, int mx)