25 #if defined(__VOLUME__)
29 for (
int i = 0; i < sd->num_closure; i++) {
36 for (
int j = i + 1; j < sd->num_closure; j++) {
38 if (sci->type != scj->type) {
46 if (!(hgi->g == hgj->g)) {
50 sci->weight += scj->weight;
51 sci->sample_weight += scj->sample_weight;
53 int size = sd->num_closure - (j + 1);
55 for (
int k = 0; k <
size; k++) {
71 phases->num_closure = 0;
73 for (
int i = 0; i < sd->num_closure; i++) {
81 to_sc->
weight = from_sc->weight;
82 to_sc->sample_weight = from_sc->sample_weight;
83 to_sc->g = from_hg->g;
84 phases->num_closure++;
109 for (
int i = 0; i < sd->num_closure; i++) {
119 sc->sample_weight = 0.0f;
124 sc->sample_weight = 0.0f;
138 sd->num_closure > 1) {
141 for (
int i = 0; i < sd->num_closure; i++) {
144 sum += sc->sample_weight;
148 for (
int i = 0; i < sd->num_closure; i++) {
151 sc->sample_weight =
max(sc->sample_weight, 0.125f *
sum);
160 if (
kernel_data.integrator.filter_glossy != FLT_MAX
165 float blur_pdf =
kernel_data.integrator.filter_glossy *
168 if (blur_pdf < 1.0f) {
169 float blur_roughness =
sqrtf(1.0f - blur_pdf) * 0.5f;
171 for (
int i = 0; i < sd->num_closure; i++) {
186 return dot(sd->N, omega_in) < 0.0f;
215 const bool is_transmission,
219 float sum_sample_weight,
220 const uint light_shader_flags)
224 for (
int i = 0; i < sd->num_closure; i++) {
233 float bsdf_pdf = 0.0f;
234 float3 eval =
bsdf_eval(kg, sd, sc, omega_in, is_transmission, &bsdf_pdf);
236 if (bsdf_pdf != 0.0f) {
238 sum_pdf += bsdf_pdf * sc->sample_weight;
242 sum_sample_weight += sc->sample_weight;
246 return (sum_sample_weight > 0.0f) ? sum_pdf / sum_sample_weight : 0.0f;
249 #ifndef __KERNEL_CUDA__
258 const bool is_transmission,
260 const uint light_shader_flags)
265 kg, sd, omega_in, is_transmission,
NULL,
bsdf_eval, 0.0f, 0.0f, light_shader_flags);
274 if (sd->num_closure > 1) {
278 for (
int i = 0; i < sd->num_closure; i++) {
282 sum += sc->sample_weight;
286 float r = (*randu) *
sum;
287 float partial_sum = 0.0f;
289 for (
int i = 0; i < sd->num_closure; i++) {
293 float next_sum = partial_sum + sc->sample_weight;
299 *randu = (
r - partial_sum) / sc->sample_weight;
303 partial_sum = next_sum;
308 return &sd->closure[sampled];
316 float3 weight = bssrdf_sc->weight;
318 if (sd->num_closure > 1) {
320 for (
int i = 0; i < sd->num_closure; i++) {
324 sum += sc->sample_weight;
327 weight *=
sum / bssrdf_sc->sample_weight;
352 label =
bsdf_sample(kg, sd, sc, randu, randv, &eval, omega_in, domega_in, pdf);
357 if (sd->num_closure > 1) {
359 float sweight = sc->sample_weight;
361 kg, sd, *omega_in, is_transmission, sc,
bsdf_eval, *pdf * sweight, sweight, 0);
371 float sum_weight = 0.0f;
373 for (
int i = 0; i < sd->num_closure; i++) {
381 sum_weight += weight;
385 return (sum_weight > 0.0f) ?
roughness / sum_weight : 0.0f;
394 return sd->closure_transparent_extinction;
404 for (
int i = 0; i < sd->num_closure; i++) {
408 sc->sample_weight = 0.0f;
431 for (
int i = 0; i < sd->num_closure; i++) {
445 for (
int i = 0; i < sd->num_closure; i++) {
459 for (
int i = 0; i < sd->num_closure; i++) {
473 for (
int i = 0; i < sd->num_closure; i++) {
484 const float ao_factor,
490 for (
int i = 0; i < sd->num_closure; i++) {
495 eval += sc->weight * ao_factor;
504 #ifdef __SUBSURFACE__
509 for (
int i = 0; i < sd->num_closure; i++) {
549 return sd->closure_emission_background;
578 weight =
one_float3() - sd->closure_transparent_extinction;
580 for (
int i = 0; i < sd->num_closure; i++) {
594 for (
int i = 0; i < sd->num_closure; i++) {
597 weight += sc->weight;
607 template<u
int node_feature_mask,
typename ConstIntegratorGenericState>
609 ConstIntegratorGenericState
state,
613 bool use_caustics_storage =
false)
627 sd->num_closure_left = max_closures;
632 OSLShader::eval_background(kg,
state, sd, path_flag);
635 OSLShader::eval_surface(kg,
state, sd, path_flag);
642 svm_eval_nodes<node_feature_mask, SHADER_TYPE_SURFACE>(kg,
state, sd,
buffer, path_flag);
645 sd->closure_emission_background =
make_float3(0.8f, 0.8f, 0.8f);
671 float sum_sample_weight)
673 for (
int i = 0; i < phases->num_closure; i++) {
678 float phase_pdf = 0.0f;
681 if (phase_pdf != 0.0f) {
683 sum_pdf += phase_pdf * svc->sample_weight;
686 sum_sample_weight += svc->sample_weight;
689 return (sum_sample_weight > 0.0f) ? sum_pdf / sum_sample_weight : 0.0f;
700 return _shader_volume_phase_multi_eval(sd, phases, omega_in, -1, phase_eval, 0.0f, 0.0f);
715 if (phases->num_closure > 1) {
719 for (sampled = 0; sampled < phases->num_closure; sampled++) {
721 sum += svc->sample_weight;
724 float r = randu *
sum;
725 float partial_sum = 0.0f;
727 for (sampled = 0; sampled < phases->num_closure; sampled++) {
733 randu = (
r - partial_sum) / svc->sample_weight;
737 partial_sum = next_sum;
740 if (sampled == phases->num_closure) {
786 template<const
bool shadow,
typename StackReadOp,
typename ConstIntegratorGenericState>
788 ConstIntegratorGenericState
state,
791 StackReadOp stack_read)
807 sd->num_closure_left = max_closures;
811 for (
int i = 0;; i++) {
819 sd->object = entry.
object;
821 sd->shader = entry.
shader;
830 # ifdef __OBJECT_MOTION__
833 shader_setup_object_transforms(kg, sd, sd->time);
840 const float velocity_scale =
kernel_data_fetch(objects, sd->object).velocity_scale;
880 float3 velocity = primitive_volume_attribute_float3(kg, sd, v_desc);
884 sd->P =
P - (
time - time_offset) * velocity_scale * velocity;
887 velocity = primitive_volume_attribute_float3(kg, sd, v_desc);
891 sd->P =
P - (
time - time_offset) * velocity_scale * velocity;
900 OSLShader::eval_volume(kg,
state, sd, path_flag);
905 svm_eval_nodes<KERNEL_FEATURE_NODE_MASK_VOLUME, SHADER_TYPE_VOLUME>(
913 shader_merge_volume_closures(sd);
923 template<
typename ConstIntegratorGenericState>
925 ConstIntegratorGenericState
state,
929 sd->num_closure_left = 0;
939 svm_eval_nodes<KERNEL_FEATURE_NODE_MASK_DISPLACEMENT, SHADER_TYPE_DISPLACEMENT>(
MINLINE float safe_sqrtf(float a)
_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 GLdouble r _GL_VOID_RET _GL_VOID GLfloat GLfloat r _GL_VOID_RET _GL_VOID GLint GLint r _GL_VOID_RET _GL_VOID GLshort GLshort r _GL_VOID_RET _GL_VOID GLdouble GLdouble r
_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 type
ccl_device_inline void bsdf_eval_accum(ccl_private BsdfEval *eval, const ClosureType closure_type, float3 value)
CCL_NAMESPACE_BEGIN ccl_device_inline void bsdf_eval_init(ccl_private BsdfEval *eval, const ClosureType closure_type, float3 value)
ccl_device_inline ccl_private ShaderClosure * bsdf_alloc(ccl_private ShaderData *sd, int size, float3 weight)
ccl_device_inline int bsdf_sample(KernelGlobals kg, ccl_private ShaderData *sd, ccl_private const ShaderClosure *sc, float randu, float randv, ccl_private float3 *eval, ccl_private float3 *omega_in, ccl_private differential3 *domega_in, ccl_private float *pdf)
ccl_device_inline float bsdf_get_roughness_squared(ccl_private const ShaderClosure *sc)
ccl_device void bsdf_blur(KernelGlobals kg, ccl_private ShaderClosure *sc, float roughness)
ccl_device float3 bsdf_eval(KernelGlobals kg, ccl_private ShaderData *sd, ccl_private const ShaderClosure *sc, const float3 omega_in, const bool is_transmission, ccl_private float *pdf)
ccl_device int bsdf_diffuse_setup(ccl_private DiffuseBsdf *bsdf)
static DBVT_INLINE btScalar size(const btDbvtVolume &a)
static T sum(const btAlignedObjectArray< T > &items)
#define kernel_assert(cond)
#define ccl_device_forceinline
#define ccl_device_inline
#define CCL_NAMESPACE_END
const KernelGlobalsCPU *ccl_restrict KernelGlobals
#define kernel_data_fetch(name, index)
ccl_device float3 emissive_simple_eval(const float3 Ng, const float3 I)
ccl_device int volume_phase_sample(ccl_private const ShaderData *sd, ccl_private const ShaderVolumeClosure *svc, float randu, float randv, ccl_private float3 *eval, ccl_private float3 *omega_in, ccl_private differential3 *domega_in, ccl_private float *pdf)
ccl_device float3 volume_phase_eval(ccl_private const ShaderData *sd, ccl_private const ShaderVolumeClosure *svc, float3 omega_in, ccl_private float *pdf)
ccl_global float * buffer
ccl_device_inline AttributeDescriptor find_attribute(KernelGlobals kg, ccl_private const ShaderData *sd, uint id)
ccl_device_inline void object_dir_transform(KernelGlobals kg, ccl_private const ShaderData *sd, ccl_private float3 *D)
ccl_device float3 shader_bsdf_average_normal(KernelGlobals kg, ccl_private const ShaderData *sd)
ccl_device void shader_bsdf_disable_transparency(KernelGlobals kg, ccl_private ShaderData *sd)
ccl_device_inline float3 shader_bssrdf_sample_weight(ccl_private const ShaderData *ccl_restrict sd, ccl_private const ShaderClosure *ccl_restrict bssrdf_sc)
ccl_device float shader_bsdf_average_roughness(ccl_private const ShaderData *sd)
ccl_device float shader_cryptomatte_id(KernelGlobals kg, int shader)
ccl_device void shader_eval_displacement(KernelGlobals kg, ConstIntegratorGenericState state, ccl_private ShaderData *sd)
ccl_device float3 shader_emissive_eval(ccl_private const ShaderData *sd)
ccl_device void shader_eval_surface(KernelGlobals kg, ConstIntegratorGenericState state, ccl_private ShaderData *ccl_restrict sd, ccl_global float *ccl_restrict buffer, uint32_t path_flag, bool use_caustics_storage=false)
ccl_device float3 shader_bsdf_transparency(KernelGlobals kg, ccl_private const ShaderData *sd)
ccl_device float3 shader_background_eval(ccl_private const ShaderData *sd)
ccl_device_inline ccl_private const ShaderClosure * shader_bsdf_bssrdf_pick(ccl_private const ShaderData *ccl_restrict sd, ccl_private float *randu)
ccl_device_inline float _shader_bsdf_multi_eval(KernelGlobals kg, ccl_private ShaderData *sd, const float3 omega_in, const bool is_transmission, ccl_private const ShaderClosure *skip_sc, ccl_private BsdfEval *result_eval, float sum_pdf, float sum_sample_weight, const uint light_shader_flags)
ccl_device float3 shader_bsdf_transmission(KernelGlobals kg, ccl_private const ShaderData *sd)
ccl_device_inline bool shader_bsdf_is_transmission(ccl_private const ShaderData *sd, const float3 omega_in)
ccl_device float3 shader_bsdf_ao(KernelGlobals kg, ccl_private const ShaderData *sd, const float ao_factor, ccl_private float3 *N_)
ccl_device float3 shader_bsdf_diffuse(KernelGlobals kg, ccl_private const ShaderData *sd)
ccl_device_forceinline bool _shader_bsdf_exclude(ClosureType type, uint light_shader_flags)
ccl_device bool shader_constant_emission_eval(KernelGlobals kg, int shader, ccl_private float3 *eval)
ccl_device float3 shader_bsdf_glossy(KernelGlobals kg, ccl_private const ShaderData *sd)
ccl_device float shader_bsdf_eval(KernelGlobals kg, ccl_private ShaderData *sd, const float3 omega_in, const bool is_transmission, ccl_private BsdfEval *bsdf_eval, const uint light_shader_flags)
ccl_device float3 shader_holdout_apply(KernelGlobals kg, ccl_private ShaderData *sd)
ccl_device float3 shader_bsdf_alpha(KernelGlobals kg, ccl_private const ShaderData *sd)
ccl_device int shader_bsdf_sample_closure(KernelGlobals kg, ccl_private ShaderData *sd, ccl_private const ShaderClosure *sc, float randu, float randv, ccl_private BsdfEval *bsdf_eval, ccl_private float3 *omega_in, ccl_private differential3 *domega_in, ccl_private float *pdf)
CCL_NAMESPACE_BEGIN ccl_device_inline void shader_prepare_surface_closures(KernelGlobals kg, ConstIntegratorState state, ccl_private ShaderData *sd, const uint32_t path_flag)
#define CLOSURE_IS_HOLDOUT(type)
#define CLOSURE_IS_BSDF_TRANSPARENT(type)
#define CLOSURE_IS_BSDF_TRANSMISSION(type)
#define CLOSURE_IS_BSDF(type)
#define CLOSURE_IS_BSDF_GLOSSY(type)
#define CLOSURE_IS_BSDF_DIFFUSE(type)
#define CLOSURE_IS_BSDF_OR_BSSRDF(type)
@ CLOSURE_VOLUME_HENYEY_GREENSTEIN_ID
@ CLOSURE_BSDF_TRANSPARENT_ID
#define CLOSURE_IS_BSSRDF(type)
@ FILTER_CLOSURE_EMISSION
@ FILTER_CLOSURE_TRANSPARENT
@ FILTER_CLOSURE_DIRECT_LIGHT
@ FILTER_CLOSURE_TRANSMISSION
@ SD_HAS_CONSTANT_EMISSION
#define MAX_VOLUME_CLOSURE
@ ATTR_STD_VOLUME_VELOCITY
@ SHADER_EXCLUDE_TRANSMIT
@ SD_OBJECT_HAS_VOLUME_MOTION
#define CAUSTICS_MAX_CLOSURE
ccl_device_inline float average(const float2 &a)
ccl_device_inline float3 one_float3()
ccl_device_inline float3 zero_float3()
T dot(const vec_base< T, Size > &a, const vec_base< T, Size > &b)
vec_base< T, Size > normalize(const vec_base< T, Size > &v)
static const pxr::TfToken roughness("roughness", pxr::TfToken::Immortal)
const IntegratorStateCPU *ccl_restrict ConstIntegratorState
#define INTEGRATOR_STATE(state, nested_struct, member)
closure color bssrdf(string method, normal N, vector radius, color albedo) BUILTIN
static void eval_displacement(SubdivDisplacement *displacement, const int ptex_face_index, const float u, const float v, const float dPdu[3], const float dPdv[3], float r_D[3])