Blender  V2.93
BasicStrokeShaders.h
Go to the documentation of this file.
1 /*
2  * This program is free software; you can redistribute it and/or
3  * modify it under the terms of the GNU General Public License
4  * as published by the Free Software Foundation; either version 2
5  * of the License, or (at your option) any later version.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * along with this program; if not, write to the Free Software Foundation,
14  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
15  */
16 
17 #pragma once
18 
24 #include <fstream>
25 
26 #include "Stroke.h"
27 #include "StrokeShader.h"
28 
29 #include "../geometry/Bezier.h"
30 #include "../geometry/Geom.h"
31 
32 extern "C" {
33 struct MTex;
34 struct bNodeTree;
35 }
36 
37 using namespace std;
38 
39 namespace Freestyle {
40 
41 using namespace Geometry;
42 
43 namespace StrokeShaders {
44 
45 //
46 // Thickness modifiers
47 //
49 
54  public:
59  ConstantThicknessShader(float thickness)
60  {
61  _thickness = thickness;
62  }
63 
66  {
67  }
68 
70  virtual string getName() const
71  {
72  return "ConstantThicknessShader";
73  }
74 
76  virtual int shade(Stroke &stroke) const;
77 
78  private:
79  float _thickness;
80 };
81 
82 /* [ Thickness Shader ].
83  * Assigns an absolute constant external thickness to every vertices of the Stroke. The external
84  * thickness of a point is its thickness from the point to the strip border in the direction
85  * pointing outside the object the Stroke delimitates.
86  */
88  public:
90  {
91  _thickness = thickness;
92  }
93 
95  {
96  }
97 
98  virtual string getName() const
99  {
100  return "ConstantExternThicknessShader";
101  }
102 
103  virtual int shade(Stroke &stroke) const;
104 
105  private:
106  float _thickness;
107 };
108 
116  public:
123  IncreasingThicknessShader(float iThicknessMin, float iThicknessMax)
124  {
125  _ThicknessMin = iThicknessMin;
126  _ThicknessMax = iThicknessMax;
127  }
128 
131  {
132  }
133 
134  virtual string getName() const
135  {
136  return "IncreasingThicknessShader";
137  }
138 
140  virtual int shade(Stroke &stroke) const;
141 
142  private:
143  float _ThicknessMin;
144  float _ThicknessMax;
145 };
146 
152  private:
153  float _ThicknessMin;
154  float _ThicknessMax;
155  float _ratio;
156 
157  public:
166  ConstrainedIncreasingThicknessShader(float iThicknessMin, float iThicknessMax, float iRatio)
167 
168  {
169  _ThicknessMin = iThicknessMin;
170  _ThicknessMax = iThicknessMax;
171  _ratio = iRatio;
172  }
173 
176  {
177  }
178 
179  virtual string getName() const
180  {
181  return "ConstrainedIncreasingThicknessShader";
182  }
183 
185  virtual int shade(Stroke &stroke) const;
186 };
187 
188 /* [ Thickness Shader ].
189  * Modifies the thickness in a relative way depending on its length.
190  */
192  private:
193  float _minThickness;
194  float _maxThickness;
195  // We divide the strokes in 4 categories:
196  // l > 300
197  // 100 < l < 300
198  // 50 < l < 100
199  // l < 50
200 
201  public:
202  LengthDependingThicknessShader(float iMinThickness, float iMaxThickness)
203  {
204  _minThickness = iMinThickness;
205  _maxThickness = iMaxThickness;
206  }
207 
209  {
210  }
211 
212  virtual string getName() const
213  {
214  return "LengthDependingThicknessShader";
215  }
216 
217  virtual int shade(Stroke &stroke) const;
218 };
219 
225  private:
226  float _amplitude;
227  float _scale;
228 
229  public:
231 
238  ThicknessNoiseShader(float iAmplitude, float iPeriod);
239 
240  virtual string getName() const
241  {
242  return "ThicknessNoiseShader";
243  }
244 
246  virtual int shade(Stroke &stroke) const;
247 };
248 
249 //
250 // Color shaders
251 //
253 
257  public:
268  ConstantColorShader(float iR, float iG, float iB, float iAlpha = 1.0f)
269  {
270  _color[0] = iR;
271  _color[1] = iG;
272  _color[2] = iB;
273  _color[3] = iAlpha;
274  }
275 
276  virtual string getName() const
277  {
278  return "ConstantColorShader";
279  }
280 
282  virtual int shade(Stroke &stroke) const;
283 
284  private:
285  float _color[4];
286 };
287 
294  private:
295  float _colorMin[4];
296  float _colorMax[4];
297 
298  public:
318  float iGm,
319  float iBm,
320  float iAlpham,
321  float iRM,
322  float iGM,
323  float iBM,
324  float iAlphaM)
325 
326  {
327  _colorMin[0] = iRm;
328  _colorMin[1] = iGm;
329  _colorMin[2] = iBm;
330  _colorMin[3] = iAlpham;
331 
332  _colorMax[0] = iRM;
333  _colorMax[1] = iGM;
334  _colorMax[2] = iBM;
335  _colorMax[3] = iAlphaM;
336  }
337 
338  virtual string getName() const
339  {
340  return "IncreasingColorShader";
341  }
342 
344  virtual int shade(Stroke &stroke) const;
345 };
346 
347 /* [ Color Shader ].
348  * Assigns a color to the stroke depending on the material of the shape to which ot belongs to.
349  * (Disney shader)
350  */
352  private:
353  float _coefficient;
354 
355  public:
356  MaterialColorShader(float coeff = 1.0f)
357  {
358  _coefficient = coeff;
359  }
360 
361  virtual string getName() const
362  {
363  return "MaterialColorShader";
364  }
365 
366  virtual int shade(Stroke &stroke) const;
367 };
368 
373  private:
374  float _amplitude;
375  float _scale;
376 
377  public:
379 
386  ColorNoiseShader(float iAmplitude, float iPeriod);
387 
388  virtual string getName() const
389  {
390  return "ColorNoiseShader";
391  }
392 
394  virtual int shade(Stroke &stroke) const;
395 };
396 
397 //
398 // Geometry Shaders
399 //
401 
406  private:
407  float _amount;
408 
409  public:
414  BackboneStretcherShader(float iAmount = 2.0f)
415  {
416  _amount = iAmount;
417  }
418 
419  virtual string getName() const
420  {
421  return "BackboneStretcherShader";
422  }
423 
425  virtual int shade(Stroke &stroke) const;
426 };
427 
432 class SamplingShader : public StrokeShader {
433  private:
434  float _sampling;
435 
436  public:
441  SamplingShader(float sampling)
442  {
443  _sampling = sampling;
444  }
445 
446  virtual string getName() const
447  {
448  return "SamplingShader";
449  }
450 
452  virtual int shade(Stroke &stroke) const;
453 };
454 
456  private:
457  float _amount;
458 
459  public:
460  ExternalContourStretcherShader(float iAmount = 2.0f)
461  {
462  _amount = iAmount;
463  }
464 
465  virtual string getName() const
466  {
467  return "ExternalContourStretcherShader";
468  }
469 
470  virtual int shade(Stroke &stroke) const;
471 };
472 
473 // Bezier curve stroke shader
480  private:
481  float _error;
482 
483  public:
490  {
491  _error = error;
492  }
493 
494  virtual string getName() const
495  {
496  return "BezierCurveShader";
497  }
498 
500  virtual int shade(Stroke &stroke) const;
501 };
502 
510  private:
511  float _error;
512 
513  public:
521  {
522  _error = iError;
523  }
524 
525  virtual string getName() const
526  {
527  return "PolygonalizationShader";
528  }
529 
531  virtual int shade(Stroke &stroke) const;
532 };
533 
541  private:
542  float _offset;
543 
544  public:
551  GuidingLinesShader(float iOffset)
552  {
553  _offset = iOffset;
554  }
555 
556  virtual string getName() const
557  {
558  return "GuidingLinesShader";
559  }
560 
562  virtual int shade(Stroke &stroke) const;
563 };
564 
569  public:
574  TipRemoverShader(real tipLength);
575 
578  {
579  }
580 
582  virtual string getName() const
583  {
584  return "TipRemoverShader";
585  }
586 
587  virtual int shade(Stroke &stroke) const;
588 
589  protected:
591 };
592 
598  private:
599  MTex *_mtex;
600  bNodeTree *_nodeTree;
601 
602  public:
608  {
609  _mtex = mtex;
610  _nodeTree = NULL;
611  }
612 
618  {
619  _nodeTree = nodetree;
620  _mtex = NULL;
621  }
622 
623  virtual string getName() const
624  {
625  return "BlenderTextureShader";
626  }
627 
629  virtual int shade(Stroke &stroke) const;
630 };
631 
637  private:
638  float _step;
639 
640  public:
646  {
647  _step = step;
648  }
649 
650  virtual string getName() const
651  {
652  return "StrokeTextureStepShader";
653  }
654 
656  virtual int shade(Stroke &stroke) const;
657 };
658 
659 } // end of namespace StrokeShaders
660 
661 } /* namespace Freestyle */
Class defining StrokeShader.
Classes to define a stroke.
ConstantColorShader(float iR, float iG, float iB, float iAlpha=1.0f)
ConstrainedIncreasingThicknessShader(float iThicknessMin, float iThicknessMax, float iRatio)
IncreasingColorShader(float iRm, float iGm, float iBm, float iAlpham, float iRM, float iGM, float iBM, float iAlphaM)
IncreasingThicknessShader(float iThicknessMin, float iThicknessMax)
LengthDependingThicknessShader(float iMinThickness, float iMaxThickness)
static void error(const char *str)
Definition: meshlaplacian.c:65
inherits from class Rep
Definition: AppCanvas.cpp:32
double real
Definition: Precision.h:26