Code cleanup / Cycles: Remove some unused hair code.
[blender.git] / intern / cycles / render / curves.cpp
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 #include "device.h"
18 #include "curves.h"
19 #include "mesh.h"
20 #include "object.h"
21 #include "scene.h"
22
23 #include "util_foreach.h"
24 #include "util_map.h"
25 #include "util_progress.h"
26 #include "util_vector.h"
27
28 CCL_NAMESPACE_BEGIN
29
30 /* Curve functions */
31
32 void curvebounds(float *lower, float *upper, float3 *p, int dim)
33 {
34         float *p0 = &p[0].x;
35         float *p1 = &p[1].x;
36         float *p2 = &p[2].x;
37         float *p3 = &p[3].x;
38
39         float fc = 0.71f;
40         float curve_coef[4];
41         curve_coef[0] = p1[dim];
42         curve_coef[1] = -fc*p0[dim] + fc*p2[dim];
43         curve_coef[2] = 2.0f * fc * p0[dim] + (fc - 3.0f) * p1[dim] + (3.0f - 2.0f * fc) * p2[dim] - fc * p3[dim];
44         curve_coef[3] = -fc * p0[dim] + (2.0f - fc) * p1[dim] + (fc - 2.0f) * p2[dim] + fc * p3[dim];
45
46         float discroot = curve_coef[2] * curve_coef[2] - 3 * curve_coef[3] * curve_coef[1];
47         float ta = -1.0f;
48         float tb = -1.0f;
49         if(discroot >= 0) {
50                 discroot = sqrt(discroot);
51                 ta = (-curve_coef[2] - discroot) / (3 * curve_coef[3]);
52                 tb = (-curve_coef[2] + discroot) / (3 * curve_coef[3]);
53                 ta = (ta > 1.0f || ta < 0.0f) ? -1.0f : ta;
54                 tb = (tb > 1.0f || tb < 0.0f) ? -1.0f : tb;
55         }
56
57         *upper = max(p1[dim],p2[dim]);
58         *lower = min(p1[dim],p2[dim]);
59         float exa = p1[dim];
60         float exb = p2[dim];
61         float t2;
62         float t3;
63         if(ta >= 0.0f) {
64                 t2 = ta * ta;
65                 t3 = t2 * ta;
66                 exa = curve_coef[3] * t3 + curve_coef[2] * t2 + curve_coef[1] * ta + curve_coef[0];
67         }
68         if(tb >= 0.0f) {
69                 t2 = tb * tb;
70                 t3 = t2 * tb;
71                 exb = curve_coef[3] * t3 + curve_coef[2] * t2 + curve_coef[1] * tb + curve_coef[0];
72         }
73         *upper = max(*upper, max(exa,exb));
74         *lower = min(*lower, min(exa,exb));
75 }
76
77 /* Hair System Manager */
78
79 CurveSystemManager::CurveSystemManager()
80 {
81         primitive = CURVE_LINE_SEGMENTS;
82         curve_shape = CURVE_THICK;
83         line_method = CURVE_CORRECTED;
84         triangle_method = CURVE_CAMERA_TRIANGLES;
85         resolution = 3;
86         subdivisions = 3;
87
88         encasing_ratio = 1.01f;
89         minimum_width = 0.0f;
90         maximum_width = 0.0f;
91
92         use_curves = true;
93         use_encasing = true;
94         use_backfacing = false;
95         use_tangent_normal = false;
96         use_tangent_normal_geometry = false;
97
98         need_update = true;
99         need_mesh_update = false;
100 }
101
102 CurveSystemManager::~CurveSystemManager()
103 {
104 }
105
106 void CurveSystemManager::device_update(Device *device, DeviceScene *dscene, Scene *scene, Progress& progress)
107 {
108         if(!need_update)
109                 return;
110
111         device_free(device, dscene);
112
113         progress.set_status("Updating Hair settings", "Copying Hair settings to device");
114
115         KernelCurves *kcurve= &dscene->data.curve;
116
117         kcurve->curveflags = 0;
118
119         if(use_curves) {
120                 if(primitive == CURVE_SEGMENTS || primitive == CURVE_RIBBONS)
121                         kcurve->curveflags |= CURVE_KN_INTERPOLATE;
122                 if(primitive == CURVE_RIBBONS)
123                         kcurve->curveflags |= CURVE_KN_RIBBONS;
124
125                 if(line_method == CURVE_ACCURATE)
126                         kcurve->curveflags |= CURVE_KN_ACCURATE;
127                 else if(line_method == CURVE_CORRECTED)
128                         kcurve->curveflags |= CURVE_KN_INTERSECTCORRECTION;
129
130                 if(use_tangent_normal)
131                         kcurve->curveflags |= CURVE_KN_TANGENTGNORMAL;
132                 if(use_tangent_normal_geometry)
133                         kcurve->curveflags |= CURVE_KN_TRUETANGENTGNORMAL;
134                 if(use_backfacing)
135                         kcurve->curveflags |= CURVE_KN_BACKFACING;
136                 if(use_encasing)
137                         kcurve->curveflags |= CURVE_KN_ENCLOSEFILTER;
138
139                 kcurve->encasing_ratio = encasing_ratio;
140                 kcurve->minimum_width = minimum_width;
141                 kcurve->maximum_width = maximum_width;
142                 kcurve->subdivisions = subdivisions;
143         }
144
145         if(progress.get_cancel()) return;
146
147         need_update = false;
148 }
149
150 void CurveSystemManager::device_free(Device *device, DeviceScene *dscene)
151 {
152
153 }
154
155 bool CurveSystemManager::modified(const CurveSystemManager& CurveSystemManager)
156 {
157         return !(curve_shape == CurveSystemManager.curve_shape &&
158                 line_method == CurveSystemManager.line_method &&
159                 primitive == CurveSystemManager.primitive &&
160                 use_encasing == CurveSystemManager.use_encasing &&
161                 use_tangent_normal == CurveSystemManager.use_tangent_normal &&
162                 use_tangent_normal_geometry == CurveSystemManager.use_tangent_normal_geometry &&
163                 encasing_ratio == CurveSystemManager.encasing_ratio &&
164                 minimum_width == CurveSystemManager.minimum_width &&
165                 maximum_width == CurveSystemManager.maximum_width &&
166                 use_backfacing == CurveSystemManager.use_backfacing &&
167                 triangle_method == CurveSystemManager.triangle_method &&
168                 resolution == CurveSystemManager.resolution &&
169                 use_curves == CurveSystemManager.use_curves &&
170                 subdivisions == CurveSystemManager.subdivisions);
171 }
172
173 bool CurveSystemManager::modified_mesh(const CurveSystemManager& CurveSystemManager)
174 {
175         return !(primitive == CurveSystemManager.primitive &&
176                 curve_shape == CurveSystemManager.curve_shape &&
177                 triangle_method == CurveSystemManager.triangle_method &&
178                 resolution == CurveSystemManager.resolution &&
179                 use_curves == CurveSystemManager.use_curves);
180 }
181
182 void CurveSystemManager::tag_update(Scene *scene)
183 {
184         need_update = true;
185 }
186
187 void CurveSystemManager::tag_update_mesh()
188 {
189         need_mesh_update = true;
190 }
191 CCL_NAMESPACE_END
192