Blender  V2.93
subd_patch.cpp
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 /* Parts adapted from code in the public domain in NVidia Mesh Tools. */
18 
19 #include "render/mesh.h"
20 
21 #include "subd/subd_patch.h"
22 
23 #include "util/util_math.h"
24 #include "util/util_types.h"
25 
27 
28 /* De Casteljau Evaluation */
29 
30 static void decasteljau_cubic(float3 *P, float3 *dt, float t, const float3 cp[4])
31 {
32  float3 d0 = cp[0] + t * (cp[1] - cp[0]);
33  float3 d1 = cp[1] + t * (cp[2] - cp[1]);
34  float3 d2 = cp[2] + t * (cp[3] - cp[2]);
35 
36  d0 += t * (d1 - d0);
37  d1 += t * (d2 - d1);
38 
39  *P = d0 + t * (d1 - d0);
40  if (dt)
41  *dt = d1 - d0;
42 }
43 
44 static void decasteljau_bicubic(
45  float3 *P, float3 *du, float3 *dv, const float3 cp[16], float u, float v)
46 {
47  float3 ucp[4], utn[4];
48 
49  /* interpolate over u */
50  decasteljau_cubic(ucp + 0, utn + 0, u, cp);
51  decasteljau_cubic(ucp + 1, utn + 1, u, cp + 4);
52  decasteljau_cubic(ucp + 2, utn + 2, u, cp + 8);
53  decasteljau_cubic(ucp + 3, utn + 3, u, cp + 12);
54 
55  /* interpolate over v */
56  decasteljau_cubic(P, dv, v, ucp);
57  if (du)
58  decasteljau_cubic(du, NULL, v, utn);
59 }
60 
61 /* Linear Quad Patch */
62 
63 void LinearQuadPatch::eval(float3 *P, float3 *dPdu, float3 *dPdv, float3 *N, float u, float v)
64 {
65  float3 d0 = interp(hull[0], hull[1], u);
66  float3 d1 = interp(hull[2], hull[3], u);
67 
68  *P = interp(d0, d1, v);
69 
70  if (dPdu && dPdv) {
71  *dPdu = interp(hull[1] - hull[0], hull[3] - hull[2], v);
72  *dPdv = interp(hull[2] - hull[0], hull[3] - hull[1], u);
73  }
74 
75  if (N) {
76  *N = normalize(
77  interp(interp(normals[0], normals[1], u), interp(normals[2], normals[3], u), v));
78  }
79 }
80 
82 {
84 
85  for (int i = 0; i < 4; i++)
86  bbox.grow(hull[i]);
87 
88  return bbox;
89 }
90 
91 /* Bicubic Patch */
92 
93 void BicubicPatch::eval(float3 *P, float3 *dPdu, float3 *dPdv, float3 *N, float u, float v)
94 {
95  if (N) {
96  float3 dPdu_, dPdv_;
97  decasteljau_bicubic(P, &dPdu_, &dPdv_, hull, u, v);
98 
99  if (dPdu && dPdv) {
100  *dPdu = dPdu_;
101  *dPdv = dPdv_;
102  }
103 
104  *N = normalize(cross(dPdu_, dPdv_));
105  }
106  else {
107  decasteljau_bicubic(P, dPdu, dPdv, hull, u, v);
108  }
109 }
110 
112 {
113  BoundBox bbox = BoundBox::empty;
114 
115  for (int i = 0; i < 16; i++)
116  bbox.grow(hull[i]);
117 
118  return bbox;
119 }
120 
_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 BMVert * v
BoundBox bound()
Definition: subd_patch.cpp:111
float3 hull[16]
Definition: subd_patch.h:55
void eval(float3 *P, float3 *dPdu, float3 *dPdv, float3 *N, float u, float v)
Definition: subd_patch.cpp:93
float3 hull[4]
Definition: subd_patch.h:44
BoundBox bound()
Definition: subd_patch.cpp:81
float3 normals[4]
Definition: subd_patch.h:45
void eval(float3 *P, float3 *dPdu, float3 *dPdv, float3 *N, float u, float v)
Definition: subd_patch.cpp:63
#define CCL_NAMESPACE_END
static float P(float k)
Definition: math_interp.c:41
params N
__forceinline void grow(const float3 &pt)
Definition: util_boundbox.h:55
static void decasteljau_bicubic(float3 *P, float3 *du, float3 *dv, const float3 cp[16], float u, float v)
Definition: subd_patch.cpp:44
static CCL_NAMESPACE_BEGIN void decasteljau_cubic(float3 *P, float3 *dt, float t, const float3 cp[4])
Definition: subd_patch.cpp:30
__forceinline avxf cross(const avxf &a, const avxf &b)
Definition: util_avxf.h:119
ccl_device_inline float2 normalize(const float2 &a)
ccl_device_inline float2 interp(const float2 &a, const float2 &b, float t)