Blender  V3.3
bsdf_transparent.h
Go to the documentation of this file.
1 /* SPDX-License-Identifier: BSD-3-Clause
2  *
3  * Adapted from Open Shading Language
4  * Copyright (c) 2009-2010 Sony Pictures Imageworks Inc., et al.
5  * All Rights Reserved.
6  *
7  * Modifications Copyright 2011-2022 Blender Foundation. */
8 
9 #pragma once
10 
12 
14  const float3 weight,
15  uint32_t path_flag)
16 {
17  /* Check cutoff weight. */
18  float sample_weight = fabsf(average(weight));
19  if (!(sample_weight >= CLOSURE_WEIGHT_CUTOFF)) {
20  return;
21  }
22 
23  if (sd->flag & SD_TRANSPARENT) {
24  sd->closure_transparent_extinction += weight;
25 
26  /* Add weight to existing transparent BSDF. */
27  for (int i = 0; i < sd->num_closure; i++) {
28  ccl_private ShaderClosure *sc = &sd->closure[i];
29 
30  if (sc->type == CLOSURE_BSDF_TRANSPARENT_ID) {
31  sc->weight += weight;
32  sc->sample_weight += sample_weight;
33  break;
34  }
35  }
36  }
37  else {
38  sd->flag |= SD_BSDF | SD_TRANSPARENT;
39  sd->closure_transparent_extinction = weight;
40 
41  if (path_flag & PATH_RAY_TERMINATE) {
42  /* In this case the number of closures is set to zero to disable
43  * all others, but we still want to get transparency so increase
44  * the number just for this. */
45  sd->num_closure_left = 1;
46  }
47 
48  /* Create new transparent BSDF. */
50  sd, sizeof(ShaderClosure), CLOSURE_BSDF_TRANSPARENT_ID, weight);
51 
52  if (bsdf) {
53  bsdf->sample_weight = sample_weight;
54  bsdf->N = sd->N;
55  }
56  else if (path_flag & PATH_RAY_TERMINATE) {
57  sd->num_closure_left = 0;
58  }
59  }
60 }
61 
63  const float3 I,
64  const float3 omega_in,
65  ccl_private float *pdf)
66 {
67  *pdf = 0.0f;
68  return make_float3(0.0f, 0.0f, 0.0f);
69 }
70 
72  const float3 I,
73  const float3 omega_in,
74  ccl_private float *pdf)
75 {
76  *pdf = 0.0f;
77  return make_float3(0.0f, 0.0f, 0.0f);
78 }
79 
81  float3 Ng,
82  float3 I,
83  float3 dIdx,
84  float3 dIdy,
85  float randu,
86  float randv,
87  ccl_private float3 *eval,
88  ccl_private float3 *omega_in,
89  ccl_private float3 *domega_in_dx,
90  ccl_private float3 *domega_in_dy,
91  ccl_private float *pdf)
92 {
93  // only one direction is possible
94  *omega_in = -I;
95 #ifdef __RAY_DIFFERENTIALS__
96  *domega_in_dx = -dIdx;
97  *domega_in_dy = -dIdy;
98 #endif
99  *pdf = 1;
100  *eval = make_float3(1, 1, 1);
102 }
103 
CCL_NAMESPACE_BEGIN ccl_device ccl_private ShaderClosure * closure_alloc(ccl_private ShaderData *sd, int size, ClosureType type, float3 weight)
Definition: alloc.h:8
ccl_device float3 bsdf_transparent_eval_reflect(ccl_private const ShaderClosure *sc, const float3 I, const float3 omega_in, ccl_private float *pdf)
ccl_device float3 bsdf_transparent_eval_transmit(ccl_private const ShaderClosure *sc, const float3 I, const float3 omega_in, ccl_private float *pdf)
ccl_device int bsdf_transparent_sample(ccl_private const ShaderClosure *sc, float3 Ng, float3 I, float3 dIdx, float3 dIdy, float randu, float randv, ccl_private float3 *eval, ccl_private float3 *omega_in, ccl_private float3 *domega_in_dx, ccl_private float3 *domega_in_dy, ccl_private float *pdf)
CCL_NAMESPACE_BEGIN ccl_device void bsdf_transparent_setup(ccl_private ShaderData *sd, const float3 weight, uint32_t path_flag)
#define ccl_device
Definition: cuda/compat.h:32
#define ccl_private
Definition: cuda/compat.h:48
#define CCL_NAMESPACE_END
Definition: cuda/compat.h:9
@ CLOSURE_BSDF_TRANSPARENT_ID
#define CLOSURE_WEIGHT_CUTOFF
@ SD_BSDF
Definition: kernel/types.h:742
@ SD_TRANSPARENT
Definition: kernel/types.h:754
@ PATH_RAY_TERMINATE
Definition: kernel/types.h:251
ShaderData
Definition: kernel/types.h:925
@ LABEL_TRANSMIT
Definition: kernel/types.h:317
@ LABEL_TRANSPARENT
Definition: kernel/types.h:322
ShaderClosure
Definition: kernel/types.h:726
ccl_device_inline float average(const float2 &a)
Definition: math_float2.h:170
#define fabsf(x)
Definition: metal/compat.h:219
#define make_float3(x, y, z)
Definition: metal/compat.h:204
#define I
unsigned int uint32_t
Definition: stdint.h:80