Blender V5.0
bsdf_transparent.h
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2009-2010 Sony Pictures Imageworks Inc., et al. All Rights Reserved.
2 * SPDX-FileCopyrightText: 2011-2022 Blender Foundation
3 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 *
6 * Adapted code from Open Shading Language. */
7
8#pragma once
9
10#include "kernel/types.h"
11
13
15
17 const Spectrum weight,
18 const uint32_t path_flag)
19{
20 /* Check cutoff weight. */
21 const float sample_weight = fabsf(average(weight));
22 if (!(sample_weight >= CLOSURE_WEIGHT_CUTOFF)) {
23 return;
24 }
25
26 sd->closure_transparent_extinction += weight;
27
28 if (sd->flag & SD_TRANSPARENT) {
29 /* Add weight to existing transparent BSDF. */
30 for (int i = 0; i < sd->num_closure; i++) {
31 ccl_private ShaderClosure *sc = &sd->closure[i];
32
33 if (sc->type == CLOSURE_BSDF_TRANSPARENT_ID) {
34 sc->weight += weight;
35 sc->sample_weight += sample_weight;
36 break;
37 }
38 }
39 }
40 else {
41 sd->flag |= SD_BSDF | SD_TRANSPARENT;
42
43 if (path_flag & PATH_RAY_TERMINATE) {
44 /* In this case the number of closures is set to zero to disable
45 * all others, but we still want to get transparency so increase
46 * the number just for this. */
47 sd->num_closure_left = 1;
48 }
49
50 /* Create new transparent BSDF. */
51 ccl_private ShaderClosure *bsdf = closure_alloc(
52 sd, sizeof(ShaderClosure), CLOSURE_BSDF_TRANSPARENT_ID, weight);
53
54 if (bsdf) {
55 bsdf->sample_weight = sample_weight;
56 bsdf->N = sd->N;
57 }
58 else if (path_flag & PATH_RAY_TERMINATE) {
59 sd->num_closure_left = 0;
60 }
61 }
62}
63
65 const float3 /*wi*/,
66 const float3 /*wo*/,
67 ccl_private float *pdf)
68{
69 *pdf = 0.0f;
70 return zero_spectrum();
71}
72
73ccl_device int bsdf_transparent_sample(const ccl_private ShaderClosure * /*sc*/,
74 const float3 /*Ng*/,
75 const float3 wi,
78 ccl_private float *pdf)
79{
80 // only one direction is possible
81 *wo = -wi;
82 /* Some high number for MIS. */
83 *pdf = 1e6f;
84 *eval = one_spectrum() * 1e6f;
86}
87
CCL_NAMESPACE_BEGIN ccl_device ccl_private ShaderClosure * closure_alloc(ccl_private ShaderData *sd, const uint size, ClosureType type, Spectrum weight)
Definition alloc.h:11
CCL_NAMESPACE_BEGIN ccl_device void bsdf_transparent_setup(ccl_private ShaderData *sd, const Spectrum weight, const uint32_t path_flag)
ccl_device int bsdf_transparent_sample(const ccl_private ShaderClosure *, const float3, const float3 wi, ccl_private Spectrum *eval, ccl_private float3 *wo, ccl_private float *pdf)
ccl_device Spectrum bsdf_transparent_eval(const ccl_private ShaderClosure *, const float3, const float3, ccl_private float *pdf)
#define one_spectrum
#define zero_spectrum
#define ccl_private
#define CCL_NAMESPACE_END
#define CLOSURE_WEIGHT_CUTOFF
@ CLOSURE_BSDF_TRANSPARENT_ID
@ SD_BSDF
@ SD_TRANSPARENT
@ PATH_RAY_TERMINATE
@ LABEL_TRANSMIT
@ LABEL_TRANSPARENT
float average(point a)
Definition node_math.h:144
#define fabsf
#define ccl_device
i
Definition text_draw.cc:230
float3 Spectrum