Blender  V2.93
kernel_differential.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 
18 
19 /* See "Tracing Ray Differentials", Homan Igehy, 1999. */
20 
22  const differential3 dP,
23  float3 D,
24  const differential3 dD,
25  float3 Ng,
26  float t)
27 {
28  /* ray differential transfer through homogeneous medium, to
29  * compute dPdx/dy at a shading point from the incoming ray */
30 
31  float3 tmp = D / dot(D, Ng);
32  float3 tmpx = dP.dx + t * dD.dx;
33  float3 tmpy = dP.dy + t * dD.dy;
34 
35  dP_->dx = tmpx - dot(tmpx, Ng) * tmp;
36  dP_->dy = tmpy - dot(tmpy, Ng) * tmp;
37 }
38 
40 {
41  /* compute dIdx/dy at a shading point, we just need to negate the
42  * differential of the ray direction */
43 
44  dI->dx = -dD.dx;
45  dI->dy = -dD.dy;
46 }
47 
50  float3 dPdu,
51  float3 dPdv,
52  differential3 dP,
53  float3 Ng)
54 {
55  /* now we have dPdx/dy from the ray differential transfer, and dPdu/dv
56  * from the primitive, we can compute dudx/dy and dvdx/dy. these are
57  * mainly used for differentials of arbitrary mesh attributes. */
58 
59  /* find most stable axis to project to 2D */
60  float xn = fabsf(Ng.x);
61  float yn = fabsf(Ng.y);
62  float zn = fabsf(Ng.z);
63 
64  if (zn < xn || zn < yn) {
65  if (yn < xn || yn < zn) {
66  dPdu.x = dPdu.y;
67  dPdv.x = dPdv.y;
68  dP.dx.x = dP.dx.y;
69  dP.dy.x = dP.dy.y;
70  }
71 
72  dPdu.y = dPdu.z;
73  dPdv.y = dPdv.z;
74  dP.dx.y = dP.dx.z;
75  dP.dy.y = dP.dy.z;
76  }
77 
78  /* using Cramer's rule, we solve for dudx and dvdx in a 2x2 linear system,
79  * and the same for dudy and dvdy. the denominator is the same for both
80  * solutions, so we compute it only once.
81  *
82  * dP.dx = dPdu * dudx + dPdv * dvdx;
83  * dP.dy = dPdu * dudy + dPdv * dvdy; */
84 
85  float det = (dPdu.x * dPdv.y - dPdv.x * dPdu.y);
86 
87  if (det != 0.0f)
88  det = 1.0f / det;
89 
90  du->dx = (dP.dx.x * dPdv.y - dP.dx.y * dPdv.x) * det;
91  dv->dx = (dP.dx.y * dPdu.x - dP.dx.x * dPdu.y) * det;
92 
93  du->dy = (dP.dy.x * dPdv.y - dP.dy.y * dPdv.x) * det;
94  dv->dy = (dP.dy.y * dPdu.x - dP.dy.x * dPdu.y) * det;
95 }
96 
98 {
99  differential d;
100  d.dx = 0.0f;
101  d.dy = 0.0f;
102 
103  return d;
104 }
105 
107 {
108  differential3 d;
109  d.dx = zero_float3();
110  d.dy = zero_float3();
111 
112  return d;
113 }
114 
_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
#define ccl_addr_space
#define ccl_device
#define CCL_NAMESPACE_END
#define fabsf(x)
ccl_device void differential_incoming(ccl_addr_space differential3 *dI, const differential3 dD)
ccl_device void differential_dudv(ccl_addr_space differential *du, ccl_addr_space differential *dv, float3 dPdu, float3 dPdv, differential3 dP, float3 Ng)
ccl_device differential differential_zero()
ccl_device differential3 differential3_zero()
CCL_NAMESPACE_BEGIN ccl_device void differential_transfer(ccl_addr_space differential3 *dP_, const differential3 dP, float3 D, const differential3 dD, float3 Ng, float t)
float z
Definition: sky_float3.h:35
float y
Definition: sky_float3.h:35
float x
Definition: sky_float3.h:35
ccl_device_inline float dot(const float2 &a, const float2 &b)
ccl_device_inline float3 zero_float3()
BLI_INLINE float D(const float *data, const int res[3], int x, int y, int z)
Definition: voxel.c:29