Blender  V2.93
bsdf_oren_nayar.h
Go to the documentation of this file.
1 /*
2  * Copyright 2011-2013 Blender Foundation
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #ifndef __BSDF_OREN_NAYAR_H__
18 #define __BSDF_OREN_NAYAR_H__
19 
21 
22 typedef ccl_addr_space struct OrenNayarBsdf {
24 
25  float roughness;
26  float a;
27  float b;
29 
30 static_assert(sizeof(ShaderClosure) >= sizeof(OrenNayarBsdf), "OrenNayarBsdf is too large!");
31 
33  float3 n,
34  float3 v,
35  float3 l)
36 {
37  const OrenNayarBsdf *bsdf = (const OrenNayarBsdf *)sc;
38  float nl = max(dot(n, l), 0.0f);
39  float nv = max(dot(n, v), 0.0f);
40  float t = dot(l, v) - nl * nv;
41 
42  if (t > 0.0f)
43  t /= max(nl, nv) + FLT_MIN;
44  float is = nl * (bsdf->a + bsdf->b * t);
45  return make_float3(is, is, is);
46 }
47 
49 {
50  float sigma = bsdf->roughness;
51 
52  bsdf->type = CLOSURE_BSDF_OREN_NAYAR_ID;
53 
54  sigma = saturate(sigma);
55 
56  float div = 1.0f / (M_PI_F + ((3.0f * M_PI_F - 4.0f) / 6.0f) * sigma);
57 
58  bsdf->a = 1.0f * div;
59  bsdf->b = sigma * div;
60 
61  return SD_BSDF | SD_BSDF_HAS_EVAL;
62 }
63 
65 {
66  const OrenNayarBsdf *bsdf_a = (const OrenNayarBsdf *)a;
67  const OrenNayarBsdf *bsdf_b = (const OrenNayarBsdf *)b;
68 
69  return (isequal_float3(bsdf_a->N, bsdf_b->N)) && (bsdf_a->roughness == bsdf_b->roughness);
70 }
71 
73  const float3 I,
74  const float3 omega_in,
75  float *pdf)
76 {
77  const OrenNayarBsdf *bsdf = (const OrenNayarBsdf *)sc;
78  if (dot(bsdf->N, omega_in) > 0.0f) {
79  *pdf = 0.5f * M_1_PI_F;
80  return bsdf_oren_nayar_get_intensity(sc, bsdf->N, I, omega_in);
81  }
82  else {
83  *pdf = 0.0f;
84  return make_float3(0.0f, 0.0f, 0.0f);
85  }
86 }
87 
89  const float3 I,
90  const float3 omega_in,
91  float *pdf)
92 {
93  return make_float3(0.0f, 0.0f, 0.0f);
94 }
95 
97  float3 Ng,
98  float3 I,
99  float3 dIdx,
100  float3 dIdy,
101  float randu,
102  float randv,
103  float3 *eval,
104  float3 *omega_in,
105  float3 *domega_in_dx,
106  float3 *domega_in_dy,
107  float *pdf)
108 {
109  const OrenNayarBsdf *bsdf = (const OrenNayarBsdf *)sc;
110  sample_uniform_hemisphere(bsdf->N, randu, randv, omega_in, pdf);
111 
112  if (dot(Ng, *omega_in) > 0.0f) {
113  *eval = bsdf_oren_nayar_get_intensity(sc, bsdf->N, I, *omega_in);
114 
115 #ifdef __RAY_DIFFERENTIALS__
116  // TODO: find a better approximation for the bounce
117  *domega_in_dx = (2.0f * dot(bsdf->N, dIdx)) * bsdf->N - dIdx;
118  *domega_in_dy = (2.0f * dot(bsdf->N, dIdy)) * bsdf->N - dIdy;
119 #endif
120  }
121  else {
122  *pdf = 0.0f;
123  *eval = make_float3(0.0f, 0.0f, 0.0f);
124  }
125 
126  return LABEL_REFLECT | LABEL_DIFFUSE;
127 }
128 
130 
131 #endif /* __BSDF_OREN_NAYAR_H__ */
_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 BMLoop * l
ATTR_WARN_UNUSED_RESULT const BMVert * v
ccl_device float3 bsdf_oren_nayar_eval_transmit(const ShaderClosure *sc, const float3 I, const float3 omega_in, float *pdf)
ccl_device int bsdf_oren_nayar_sample(const ShaderClosure *sc, float3 Ng, float3 I, float3 dIdx, float3 dIdy, float randu, float randv, float3 *eval, float3 *omega_in, float3 *domega_in_dx, float3 *domega_in_dy, float *pdf)
ccl_device int bsdf_oren_nayar_setup(OrenNayarBsdf *bsdf)
ccl_device float3 bsdf_oren_nayar_eval_reflect(const ShaderClosure *sc, const float3 I, const float3 omega_in, float *pdf)
ccl_device float3 bsdf_oren_nayar_get_intensity(const ShaderClosure *sc, float3 n, float3 v, float3 l)
CCL_NAMESPACE_BEGIN typedef ccl_addr_space struct OrenNayarBsdf OrenNayarBsdf
ccl_device bool bsdf_oren_nayar_merge(const ShaderClosure *a, const ShaderClosure *b)
#define ccl_addr_space
#define ccl_device
#define CCL_NAMESPACE_END
#define make_float3(x, y, z)
ccl_device_inline void sample_uniform_hemisphere(const float3 N, float randu, float randv, float3 *omega_in, float *pdf)
@ SD_BSDF_HAS_EVAL
Definition: kernel_types.h:849
@ SD_BSDF
Definition: kernel_types.h:847
@ LABEL_DIFFUSE
Definition: kernel_types.h:330
@ LABEL_REFLECT
Definition: kernel_types.h:329
ShaderClosure
Definition: kernel_types.h:831
static unsigned a[3]
Definition: RandGen.cpp:92
#define I
@ CLOSURE_BSDF_OREN_NAYAR_ID
Definition: svm_types.h:535
float max
ccl_device_inline float saturate(float a)
Definition: util_math.h:315
#define M_1_PI_F
Definition: util_math.h:52
#define M_PI_F
Definition: util_math.h:43
ccl_device_inline float dot(const float2 &a, const float2 &b)
ccl_device_inline bool isequal_float3(const float3 a, const float3 b)