Blender  V3.3
bsdf_refraction.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 
13 /* REFRACTION */
14 
16 {
17  bsdf->type = CLOSURE_BSDF_REFRACTION_ID;
18  return SD_BSDF;
19 }
20 
22  const float3 I,
23  const float3 omega_in,
24  ccl_private float *pdf)
25 {
26  *pdf = 0.0f;
27  return make_float3(0.0f, 0.0f, 0.0f);
28 }
29 
31  const float3 I,
32  const float3 omega_in,
33  ccl_private float *pdf)
34 {
35  *pdf = 0.0f;
36  return make_float3(0.0f, 0.0f, 0.0f);
37 }
38 
40  float3 Ng,
41  float3 I,
42  float3 dIdx,
43  float3 dIdy,
44  float randu,
45  float randv,
46  ccl_private float3 *eval,
47  ccl_private float3 *omega_in,
48  ccl_private float3 *domega_in_dx,
49  ccl_private float3 *domega_in_dy,
50  ccl_private float *pdf)
51 {
52  ccl_private const MicrofacetBsdf *bsdf = (ccl_private const MicrofacetBsdf *)sc;
53  float m_eta = bsdf->ior;
54  float3 N = bsdf->N;
55 
56  float3 R, T;
57 #ifdef __RAY_DIFFERENTIALS__
58  float3 dRdx, dRdy, dTdx, dTdy;
59 #endif
60  bool inside;
61  float fresnel;
62  fresnel = fresnel_dielectric(m_eta,
63  N,
64  I,
65  &R,
66  &T,
68  dIdx,
69  dIdy,
70  &dRdx,
71  &dRdy,
72  &dTdx,
73  &dTdy,
74 #endif
75  &inside);
76 
77  if (!inside && fresnel != 1.0f) {
78  /* Some high number for MIS. */
79  *pdf = 1e6f;
80  *eval = make_float3(1e6f, 1e6f, 1e6f);
81  *omega_in = T;
82 #ifdef __RAY_DIFFERENTIALS__
83  *domega_in_dx = dTdx;
84  *domega_in_dy = dTdy;
85 #endif
86  }
87  else {
88  *pdf = 0.0f;
89  *eval = make_float3(0.0f, 0.0f, 0.0f);
90  }
92 }
93 
ccl_device float3 bsdf_refraction_eval_transmit(ccl_private const ShaderClosure *sc, const float3 I, const float3 omega_in, ccl_private float *pdf)
CCL_NAMESPACE_BEGIN ccl_device int bsdf_refraction_setup(ccl_private MicrofacetBsdf *bsdf)
ccl_device int bsdf_refraction_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_device float3 bsdf_refraction_eval_reflect(ccl_private const ShaderClosure *sc, const float3 I, const float3 omega_in, ccl_private float *pdf)
CCL_NAMESPACE_BEGIN ccl_device float fresnel_dielectric(float eta, const float3 N, const float3 I, ccl_private float3 *R, ccl_private float3 *T, ccl_private bool *is_inside)
Definition: bsdf_util.h:13
#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_REFRACTION_ID
@ SD_BSDF
Definition: kernel/types.h:742
#define __RAY_DIFFERENTIALS__
Definition: kernel/types.h:62
@ LABEL_TRANSMIT
Definition: kernel/types.h:317
@ LABEL_SINGULAR
Definition: kernel/types.h:321
ShaderClosure
Definition: kernel/types.h:726
#define N
#define T
#define R
#define make_float3(x, y, z)
Definition: metal/compat.h:204
#define I