12 #ifdef __BACKGROUND_MIS__
24 int cdf_width = res_x + 1;
31 int step =
count >> 1;
32 int middle = first + step;
42 int index_v =
max(0, first - 1);
51 float v = (index_v + dv) / res_y;
57 int step =
count >> 1;
58 int middle = first + step;
60 if (
kernel_data_fetch(light_background_conditional_cdf, index_v * cdf_width + middle).y <
69 int index_u =
max(0, first - 1);
73 index_v * cdf_width + index_u);
75 index_v * cdf_width + index_u + 1);
77 index_v * cdf_width + res_x);
81 float u = (index_u + du) / res_x;
85 float denom = (
M_2PI_F *
M_PI_F * sin_theta) * cdf_last_u.
x * cdf_last_v.
x;
87 if (sin_theta == 0.0f || denom == 0.0f)
90 *pdf = (cdf_u.
x * cdf_v.
x) / denom;
104 int cdf_width = res_x + 1;
108 if (sin_theta == 0.0f)
116 index_v * cdf_width + res_x);
119 float denom = (
M_2PI_F *
M_PI_F * sin_theta) * cdf_last_u.
x * cdf_last_v.
x;
126 index_v * cdf_width + index_u);
129 return (cdf_u.
x * cdf_v.
x) / denom;
135 int portal =
kernel_data.background.portal_offset + index;
138 *lightpos =
make_float3(klight->co[0], klight->co[1], klight->co[2]);
139 *dir =
make_float3(klight->area.dir[0], klight->area.dir[1], klight->area.dir[2]);
142 if (
dot(*dir,
P - *lightpos) > 1e-4f)
151 float portal_pdf = 0.0f;
153 int num_possible = 0;
154 for (
int p = 0; p <
kernel_data.background.num_portals; p++) {
155 if (p == ignore_portal)
159 if (!background_portal_data_fetch_and_check_side(kg,
P, p, &lightpos, &dir))
168 int portal =
kernel_data.background.portal_offset + p;
171 klight->area.axisu[0], klight->area.axisu[1], klight->area.axisu[2]);
173 klight->area.axisv[0], klight->area.axisv[1], klight->area.axisv[2]);
174 bool is_round = (klight->area.invarea < 0.0f);
201 if (ignore_portal >= 0) {
206 return (num_possible > 0) ? portal_pdf / num_possible : 0.0f;
211 int num_possible_portals = 0;
212 for (
int p = 0; p <
kernel_data.background.num_portals; p++) {
214 if (background_portal_data_fetch_and_check_side(kg,
P, p, &lightpos, &dir))
215 num_possible_portals++;
217 return num_possible_portals;
229 randv *= num_possible;
230 int portal = (int)randv;
236 for (
int p = 0; p <
kernel_data.background.num_portals; p++) {
239 if (!background_portal_data_fetch_and_check_side(kg,
P, p, &lightpos, &dir))
244 int portal =
kernel_data.background.portal_offset + p;
247 klight->area.axisu[0], klight->area.axisu[1], klight->area.axisu[2]);
249 klight->area.axisv[0], klight->area.axisv[1], klight->area.axisv[2]);
250 bool is_round = (klight->area.invarea < 0.0f);
254 lightpos +=
ellipse_sample(axisu * 0.5f, axisv * 0.5f, randu, randv);
264 *pdf /= num_possible;
297 float portal_method_pdf =
kernel_data.background.portal_weight;
298 float sun_method_pdf =
kernel_data.background.sun_weight;
299 float map_method_pdf =
kernel_data.background.map_weight;
302 if (portal_method_pdf > 0.0f) {
304 num_portals = background_num_possible_portals(kg,
P);
305 if (num_portals == 0) {
306 portal_method_pdf = 0.0f;
310 float pdf_fac = (portal_method_pdf + sun_method_pdf + map_method_pdf);
311 if (pdf_fac == 0.0f) {
317 pdf_fac = 1.0f / pdf_fac;
318 portal_method_pdf *= pdf_fac;
319 sun_method_pdf *= pdf_fac;
320 map_method_pdf *= pdf_fac;
326 float sun_method_cdf = portal_method_pdf + sun_method_pdf;
330 if (randu < portal_method_pdf) {
333 if (portal_method_pdf != 1.0f) {
334 randu /= portal_method_pdf;
339 D = background_portal_sample(kg,
P, randu, randv, num_portals, &portal, pdf);
340 if (num_portals > 1) {
342 *pdf += background_portal_pdf(kg,
P,
D, portal,
NULL);
346 if (portal_method_pdf == 1.0f) {
349 *pdf *= portal_method_pdf;
351 else if (randu < sun_method_cdf) {
354 if (sun_method_pdf != 1.0f) {
355 randu = (randu - portal_method_pdf) / sun_method_pdf;
358 D = background_sun_sample(kg, randu, randv, pdf);
361 if (sun_method_pdf == 1.0f) {
364 *pdf *= sun_method_pdf;
369 if (map_method_pdf != 1.0f) {
370 randu = (randu - sun_method_cdf) / map_method_pdf;
373 D = background_map_sample(kg, randu, randv, pdf);
376 if (map_method_pdf == 1.0f) {
379 *pdf *= map_method_pdf;
383 if (method != 0 && portal_method_pdf != 0.0f) {
384 *pdf += portal_method_pdf * background_portal_pdf(kg,
P,
D, -1,
NULL);
386 if (method != 1 && sun_method_pdf != 0.0f) {
387 *pdf += sun_method_pdf * background_sun_pdf(kg,
D);
389 if (method != 2 && map_method_pdf != 0.0f) {
390 *pdf += map_method_pdf * background_map_pdf(kg,
D);
397 float portal_method_pdf =
kernel_data.background.portal_weight;
398 float sun_method_pdf =
kernel_data.background.sun_weight;
399 float map_method_pdf =
kernel_data.background.map_weight;
401 float portal_pdf = 0.0f;
404 if (portal_method_pdf > 0.0f) {
406 bool is_possible =
false;
407 portal_pdf = background_portal_pdf(kg,
P, direction, -1, &is_possible);
412 portal_method_pdf = 0.0f;
416 float pdf_fac = (portal_method_pdf + sun_method_pdf + map_method_pdf);
417 if (pdf_fac == 0.0f) {
422 pdf_fac = 1.0f / pdf_fac;
423 portal_method_pdf *= pdf_fac;
424 sun_method_pdf *= pdf_fac;
425 map_method_pdf *= pdf_fac;
427 float pdf = portal_pdf * portal_method_pdf;
428 if (sun_method_pdf != 0.0f) {
429 pdf += background_sun_pdf(kg, direction) * sun_method_pdf;
431 if (map_method_pdf != 0.0f) {
432 pdf += background_map_pdf(kg, direction) * map_method_pdf;
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei GLfloat GLfloat GLfloat GLfloat const GLubyte *bitmap _GL_VOID_RET _GL_VOID GLenum const void *lists _GL_VOID_RET _GL_VOID const GLdouble *equation _GL_VOID_RET _GL_VOID GLdouble GLdouble blue _GL_VOID_RET _GL_VOID GLfloat GLfloat blue _GL_VOID_RET _GL_VOID GLint GLint blue _GL_VOID_RET _GL_VOID GLshort GLshort blue _GL_VOID_RET _GL_VOID GLubyte GLubyte blue _GL_VOID_RET _GL_VOID GLuint GLuint blue _GL_VOID_RET _GL_VOID GLushort GLushort blue _GL_VOID_RET _GL_VOID GLbyte GLbyte GLbyte alpha _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble alpha _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat alpha _GL_VOID_RET _GL_VOID GLint GLint GLint alpha _GL_VOID_RET _GL_VOID GLshort GLshort GLshort alpha _GL_VOID_RET _GL_VOID GLubyte GLubyte GLubyte alpha _GL_VOID_RET _GL_VOID GLuint GLuint GLuint alpha _GL_VOID_RET _GL_VOID GLushort GLushort GLushort alpha _GL_VOID_RET _GL_VOID GLenum mode _GL_VOID_RET _GL_VOID GLint y
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei GLfloat GLfloat GLfloat GLfloat const GLubyte *bitmap _GL_VOID_RET _GL_VOID GLenum const void *lists _GL_VOID_RET _GL_VOID const GLdouble *equation _GL_VOID_RET _GL_VOID GLdouble GLdouble blue _GL_VOID_RET _GL_VOID GLfloat GLfloat blue _GL_VOID_RET _GL_VOID GLint GLint blue _GL_VOID_RET _GL_VOID GLshort GLshort blue _GL_VOID_RET _GL_VOID GLubyte GLubyte blue _GL_VOID_RET _GL_VOID GLuint GLuint blue _GL_VOID_RET _GL_VOID GLushort GLushort blue _GL_VOID_RET _GL_VOID GLbyte GLbyte GLbyte alpha _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble alpha _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat alpha _GL_VOID_RET _GL_VOID GLint GLint GLint alpha _GL_VOID_RET _GL_VOID GLshort GLshort GLshort alpha _GL_VOID_RET _GL_VOID GLubyte GLubyte GLubyte alpha _GL_VOID_RET _GL_VOID GLuint GLuint GLuint alpha _GL_VOID_RET _GL_VOID GLushort GLushort GLushort alpha _GL_VOID_RET _GL_VOID GLenum mode _GL_VOID_RET _GL_VOID GLint GLsizei GLsizei GLenum type _GL_VOID_RET _GL_VOID GLsizei GLenum GLenum const void *pixels _GL_VOID_RET _GL_VOID const void *pointer _GL_VOID_RET _GL_VOID GLdouble v _GL_VOID_RET _GL_VOID GLfloat v _GL_VOID_RET _GL_VOID GLint GLint i2 _GL_VOID_RET _GL_VOID GLint j _GL_VOID_RET _GL_VOID GLfloat param _GL_VOID_RET _GL_VOID GLint param _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble GLdouble GLdouble zFar _GL_VOID_RET _GL_UINT GLdouble *equation _GL_VOID_RET _GL_VOID GLenum GLint *params _GL_VOID_RET _GL_VOID GLenum GLfloat *v _GL_VOID_RET _GL_VOID GLenum GLfloat *params _GL_VOID_RET _GL_VOID GLfloat *values _GL_VOID_RET _GL_VOID GLushort *values _GL_VOID_RET _GL_VOID GLenum GLfloat *params _GL_VOID_RET _GL_VOID GLenum GLdouble *params _GL_VOID_RET _GL_VOID GLenum GLint *params _GL_VOID_RET _GL_VOID GLsizei const void *pointer _GL_VOID_RET _GL_VOID GLsizei const void *pointer _GL_VOID_RET _GL_BOOL GLfloat param _GL_VOID_RET _GL_VOID GLint param _GL_VOID_RET _GL_VOID GLenum GLfloat param _GL_VOID_RET _GL_VOID GLenum GLint param _GL_VOID_RET _GL_VOID GLushort pattern _GL_VOID_RET _GL_VOID GLdouble GLdouble GLint GLint const GLdouble *points _GL_VOID_RET _GL_VOID GLdouble GLdouble GLint GLint GLdouble GLdouble GLint GLint const GLdouble *points _GL_VOID_RET _GL_VOID GLdouble GLdouble u2 _GL_VOID_RET _GL_VOID GLdouble GLdouble GLint GLdouble GLdouble v2 _GL_VOID_RET _GL_VOID GLenum GLfloat param _GL_VOID_RET _GL_VOID GLenum GLint param _GL_VOID_RET _GL_VOID GLenum mode _GL_VOID_RET _GL_VOID GLdouble GLdouble nz _GL_VOID_RET _GL_VOID GLfloat GLfloat nz _GL_VOID_RET _GL_VOID GLint GLint nz _GL_VOID_RET _GL_VOID GLshort GLshort nz _GL_VOID_RET _GL_VOID GLsizei const void *pointer _GL_VOID_RET _GL_VOID GLsizei const GLfloat *values _GL_VOID_RET _GL_VOID GLsizei const GLushort *values _GL_VOID_RET _GL_VOID GLint param _GL_VOID_RET _GL_VOID const GLuint const GLclampf *priorities _GL_VOID_RET _GL_VOID GLdouble y _GL_VOID_RET _GL_VOID GLfloat y _GL_VOID_RET _GL_VOID GLint y _GL_VOID_RET _GL_VOID GLshort y _GL_VOID_RET _GL_VOID GLdouble GLdouble z _GL_VOID_RET _GL_VOID GLfloat GLfloat z _GL_VOID_RET _GL_VOID GLint GLint z _GL_VOID_RET _GL_VOID GLshort GLshort z _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble w _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat w _GL_VOID_RET _GL_VOID GLint GLint GLint w _GL_VOID_RET _GL_VOID GLshort GLshort GLshort w _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble y2 _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat y2 _GL_VOID_RET _GL_VOID GLint GLint GLint y2 _GL_VOID_RET _GL_VOID GLshort GLshort GLshort y2 _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble z _GL_VOID_RET _GL_VOID GLdouble GLdouble z _GL_VOID_RET _GL_VOID GLuint *buffer _GL_VOID_RET _GL_VOID GLdouble t _GL_VOID_RET _GL_VOID GLfloat t _GL_VOID_RET _GL_VOID GLint t _GL_VOID_RET _GL_VOID GLshort t _GL_VOID_RET _GL_VOID GLdouble t
ATTR_WARN_UNUSED_RESULT const BMVert * v
SIMD_FORCE_INLINE btScalar angle(const btVector3 &v) const
Return the angle between this and another vector.
ccl_device_inline float3 ellipse_sample(float3 ru, float3 rv, float randu, float randv)
ccl_device float lamp_light_pdf(KernelGlobals kg, const float3 Ng, const float3 I, float t)
CCL_NAMESPACE_BEGIN ccl_device_inline float rect_light_sample(float3 P, ccl_private float3 *light_p, float3 axisu, float3 axisv, float randu, float randv, bool sample_coord)
#define kernel_assert(cond)
#define ccl_device_inline
#define CCL_NAMESPACE_END
ccl_device float3 equirectangular_to_direction(float u, float v)
ccl_device float2 direction_to_equirectangular(float3 dir)
const KernelGlobalsCPU *ccl_restrict KernelGlobals
#define kernel_data_fetch(name, index)
ccl_device_inline float2 normalize_len(const float2 &a, float *t)
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 quad_u, float3 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)
T dot(const vec_base< T, Size > &a, const vec_base< T, Size > &b)
T clamp(const T &a, const T &min, const T &max)
vec_base< T, Size > normalize(const vec_base< T, Size > &v)
ccl_device float3 sample_uniform_sphere(float u1, float u2)
ccl_device_inline void sample_uniform_cone(const float3 N, float angle, float randu, float randv, ccl_private float3 *omega_in, ccl_private float *pdf)
ccl_device_inline float pdf_uniform_cone(const float3 N, float3 D, float angle)
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)
BLI_INLINE float D(const float *data, const int res[3], int x, int y, int z)