~ubuntu-branches/ubuntu/trusty/blender/trusty

« back to all changes in this revision

Viewing changes to intern/cycles/render/curves.cpp

  • Committer: Package Import Robot
  • Author(s): Jeremy Bicha
  • Date: 2013-03-06 12:08:47 UTC
  • mfrom: (1.5.1) (14.1.8 experimental)
  • Revision ID: package-import@ubuntu.com-20130306120847-frjfaryb2zrotwcg
Tags: 2.66a-1ubuntu1
* Resynchronize with Debian (LP: #1076930, #1089256, #1052743, #999024,
  #1122888, #1147084)
* debian/control:
  - Lower build-depends on libavcodec-dev since we're not
    doing the libav9 transition in Ubuntu yet

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright 2011, Blender Foundation.
 
3
 *
 
4
 * This program is free software; you can redistribute it and/or
 
5
 * modify it under the terms of the GNU General Public License
 
6
 * as published by the Free Software Foundation; either version 2
 
7
 * of the License, or (at your option) any later version.
 
8
 *
 
9
 * This program is distributed in the hope that it will be useful,
 
10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
12
 * GNU General Public License for more details.
 
13
 *
 
14
 * You should have received a copy of the GNU General Public License
 
15
 * along with this program; if not, write to the Free Software Foundation,
 
16
 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 
17
 */
 
18
 
 
19
#include "device.h"
 
20
#include "curves.h"
 
21
#include "mesh.h"
 
22
#include "object.h"
 
23
#include "scene.h"
 
24
 
 
25
#include "util_foreach.h"
 
26
#include "util_map.h"
 
27
#include "util_progress.h"
 
28
#include "util_vector.h"
 
29
 
 
30
CCL_NAMESPACE_BEGIN
 
31
 
 
32
/* Curve functions */
 
33
 
 
34
void curvebounds(float *lower, float *upper, float3 *p, int dim)
 
35
{
 
36
        float *p0 = &p[0].x;
 
37
        float *p1 = &p[1].x;
 
38
        float *p2 = &p[2].x;
 
39
        float *p3 = &p[3].x;
 
40
        float fc = 0.71f;
 
41
        float curve_coef[4];
 
42
        curve_coef[0] = p1[dim];
 
43
        curve_coef[1] = -fc*p0[dim] + fc*p2[dim];
 
44
        curve_coef[2] = 2.0f * fc * p0[dim] + (fc - 3.0f) * p1[dim] + (3.0f - 2.0f * fc) * p2[dim] - fc * p3[dim];
 
45
        curve_coef[3] = -fc * p0[dim] + (2.0f - fc) * p1[dim] + (fc - 2.0f) * p2[dim] + fc * p3[dim];
 
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
 
 
78
/* Hair System Manager */
 
79
 
 
80
CurveSystemManager::CurveSystemManager()
 
81
{
 
82
        primitive = CURVE_LINE_SEGMENTS;
 
83
        line_method = CURVE_CORRECTED;
 
84
        interpolation = CURVE_CARDINAL;
 
85
        triangle_method = CURVE_CAMERA_TRIANGLES;
 
86
        resolution = 3;
 
87
        segments = 1;
 
88
        subdivisions = 3;
 
89
 
 
90
        normalmix = 1.0f;
 
91
        encasing_ratio = 1.01f;
 
92
 
 
93
        use_curves = true;
 
94
        use_smooth = true;
 
95
        use_parents = false;
 
96
        use_encasing = true;
 
97
        use_backfacing = false;
 
98
        use_joined = false;
 
99
        use_tangent_normal = false;
 
100
        use_tangent_normal_geometry = false;
 
101
        use_tangent_normal_correction = false;
 
102
 
 
103
        need_update = true;
 
104
        need_mesh_update = false;
 
105
}
 
106
 
 
107
CurveSystemManager::~CurveSystemManager()
 
108
{
 
109
}
 
110
 
 
111
void CurveSystemManager::device_update(Device *device, DeviceScene *dscene, Scene *scene, Progress& progress)
 
112
{
 
113
        if(!need_update)
 
114
                return;
 
115
 
 
116
        device_free(device, dscene);
 
117
 
 
118
        progress.set_status("Updating Hair settings", "Copying Hair settings to device");
 
119
 
 
120
        KernelCurves *kcurve= &dscene->data.curve_kernel_data;
 
121
 
 
122
        kcurve->curveflags = 0;
 
123
 
 
124
        if(use_curves) {
 
125
                if(primitive == CURVE_SEGMENTS || primitive == CURVE_RIBBONS)
 
126
                        kcurve->curveflags |= CURVE_KN_INTERPOLATE;
 
127
                if(primitive == CURVE_RIBBONS)
 
128
                        kcurve->curveflags |= CURVE_KN_RIBBONS;
 
129
 
 
130
                if(line_method == CURVE_ACCURATE)
 
131
                        kcurve->curveflags |= CURVE_KN_ACCURATE;
 
132
                if(line_method == CURVE_CORRECTED)
 
133
                        kcurve->curveflags |= CURVE_KN_INTERSECTCORRECTION;
 
134
                if(line_method == CURVE_POSTCORRECTED)
 
135
                        kcurve->curveflags |= CURVE_KN_POSTINTERSECTCORRECTION;
 
136
 
 
137
                if(use_tangent_normal)
 
138
                        kcurve->curveflags |= CURVE_KN_TANGENTGNORMAL;
 
139
                if(use_tangent_normal_correction)
 
140
                        kcurve->curveflags |= CURVE_KN_NORMALCORRECTION;
 
141
                if(use_tangent_normal_geometry)
 
142
                        kcurve->curveflags |= CURVE_KN_TRUETANGENTGNORMAL;
 
143
                if(use_joined)
 
144
                        kcurve->curveflags |= CURVE_KN_CURVEDATA;
 
145
                if(use_backfacing)
 
146
                        kcurve->curveflags |= CURVE_KN_BACKFACING;
 
147
                if(use_encasing)
 
148
                        kcurve->curveflags |= CURVE_KN_ENCLOSEFILTER;
 
149
 
 
150
                kcurve->normalmix = normalmix;
 
151
                kcurve->encasing_ratio = encasing_ratio;
 
152
                kcurve->subdivisions = subdivisions;
 
153
        }
 
154
 
 
155
        if(progress.get_cancel()) return;
 
156
 
 
157
        need_update = false;
 
158
}
 
159
 
 
160
void CurveSystemManager::device_free(Device *device, DeviceScene *dscene)
 
161
{
 
162
 
 
163
}
 
164
 
 
165
bool CurveSystemManager::modified(const CurveSystemManager& CurveSystemManager)
 
166
{
 
167
        return !(line_method == CurveSystemManager.line_method &&
 
168
                interpolation == CurveSystemManager.interpolation &&
 
169
                primitive == CurveSystemManager.primitive &&
 
170
                use_encasing == CurveSystemManager.use_encasing &&
 
171
                use_tangent_normal == CurveSystemManager.use_tangent_normal &&
 
172
                use_tangent_normal_correction == CurveSystemManager.use_tangent_normal_correction &&
 
173
                use_tangent_normal_geometry == CurveSystemManager.use_tangent_normal_geometry &&
 
174
                encasing_ratio == CurveSystemManager.encasing_ratio &&
 
175
                use_backfacing == CurveSystemManager.use_backfacing &&
 
176
                normalmix == CurveSystemManager.normalmix &&
 
177
                use_smooth == CurveSystemManager.use_smooth &&
 
178
                triangle_method == CurveSystemManager.triangle_method &&
 
179
                resolution == CurveSystemManager.resolution &&
 
180
                use_curves == CurveSystemManager.use_curves &&
 
181
                use_joined == CurveSystemManager.use_joined &&
 
182
                segments == CurveSystemManager.segments &&
 
183
                use_parents == CurveSystemManager.use_parents &&
 
184
                subdivisions == CurveSystemManager.subdivisions);
 
185
}
 
186
 
 
187
bool CurveSystemManager::modified_mesh(const CurveSystemManager& CurveSystemManager)
 
188
{
 
189
        return !(primitive == CurveSystemManager.primitive &&
 
190
                interpolation == CurveSystemManager.interpolation &&
 
191
                use_parents == CurveSystemManager.use_parents &&
 
192
                use_smooth == CurveSystemManager.use_smooth &&
 
193
                triangle_method == CurveSystemManager.triangle_method &&
 
194
                resolution == CurveSystemManager.resolution &&
 
195
                use_curves == CurveSystemManager.use_curves &&
 
196
                use_joined == CurveSystemManager.use_joined &&
 
197
                segments == CurveSystemManager.segments);
 
198
}
 
199
 
 
200
void CurveSystemManager::tag_update(Scene *scene)
 
201
{
 
202
        need_update = true;
 
203
}
 
204
 
 
205
void CurveSystemManager::tag_update_mesh()
 
206
{
 
207
        need_mesh_update = true;
 
208
}
 
209
CCL_NAMESPACE_END
 
210