Blender  V3.3
BasicStrokeShaders.h
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2 
3 #pragma once
4 
10 #include <fstream>
11 
12 #include "Stroke.h"
13 #include "StrokeShader.h"
14 
15 #include "../geometry/Bezier.h"
16 #include "../geometry/Geom.h"
17 
18 extern "C" {
19 struct MTex;
20 struct bNodeTree;
21 }
22 
23 using namespace std;
24 
25 namespace Freestyle {
26 
27 using namespace Geometry;
28 
29 namespace StrokeShaders {
30 
31 //
32 // Thickness modifiers
33 //
35 
40  public:
45  ConstantThicknessShader(float thickness)
46  {
47  _thickness = thickness;
48  }
49 
52  {
53  }
54 
56  virtual string getName() const
57  {
58  return "ConstantThicknessShader";
59  }
60 
62  virtual int shade(Stroke &stroke) const;
63 
64  private:
65  float _thickness;
66 };
67 
68 /* [ Thickness Shader ].
69  * Assigns an absolute constant external thickness to every vertices of the Stroke. The external
70  * thickness of a point is its thickness from the point to the strip border in the direction
71  * pointing outside the object the Stroke delimitates.
72  */
74  public:
76  {
77  _thickness = thickness;
78  }
79 
81  {
82  }
83 
84  virtual string getName() const
85  {
86  return "ConstantExternThicknessShader";
87  }
88 
89  virtual int shade(Stroke &stroke) const;
90 
91  private:
92  float _thickness;
93 };
94 
102  public:
109  IncreasingThicknessShader(float iThicknessMin, float iThicknessMax)
110  {
111  _ThicknessMin = iThicknessMin;
112  _ThicknessMax = iThicknessMax;
113  }
114 
117  {
118  }
119 
120  virtual string getName() const
121  {
122  return "IncreasingThicknessShader";
123  }
124 
126  virtual int shade(Stroke &stroke) const;
127 
128  private:
129  float _ThicknessMin;
130  float _ThicknessMax;
131 };
132 
138  private:
139  float _ThicknessMin;
140  float _ThicknessMax;
141  float _ratio;
142 
143  public:
152  ConstrainedIncreasingThicknessShader(float iThicknessMin, float iThicknessMax, float iRatio)
153 
154  {
155  _ThicknessMin = iThicknessMin;
156  _ThicknessMax = iThicknessMax;
157  _ratio = iRatio;
158  }
159 
162  {
163  }
164 
165  virtual string getName() const
166  {
167  return "ConstrainedIncreasingThicknessShader";
168  }
169 
171  virtual int shade(Stroke &stroke) const;
172 };
173 
174 /* [ Thickness Shader ].
175  * Modifies the thickness in a relative way depending on its length.
176  */
178  private:
179  float _minThickness;
180  float _maxThickness;
181  // We divide the strokes in 4 categories:
182  // l > 300
183  // 100 < l < 300
184  // 50 < l < 100
185  // l < 50
186 
187  public:
188  LengthDependingThicknessShader(float iMinThickness, float iMaxThickness)
189  {
190  _minThickness = iMinThickness;
191  _maxThickness = iMaxThickness;
192  }
193 
195  {
196  }
197 
198  virtual string getName() const
199  {
200  return "LengthDependingThicknessShader";
201  }
202 
203  virtual int shade(Stroke &stroke) const;
204 };
205 
211  private:
212  float _amplitude;
213  float _scale;
214 
215  public:
217 
224  ThicknessNoiseShader(float iAmplitude, float iPeriod);
225 
226  virtual string getName() const
227  {
228  return "ThicknessNoiseShader";
229  }
230 
232  virtual int shade(Stroke &stroke) const;
233 };
234 
235 //
236 // Color shaders
237 //
239 
243  public:
254  ConstantColorShader(float iR, float iG, float iB, float iAlpha = 1.0f)
255  {
256  _color[0] = iR;
257  _color[1] = iG;
258  _color[2] = iB;
259  _color[3] = iAlpha;
260  }
261 
262  virtual string getName() const
263  {
264  return "ConstantColorShader";
265  }
266 
268  virtual int shade(Stroke &stroke) const;
269 
270  private:
271  float _color[4];
272 };
273 
280  private:
281  float _colorMin[4];
282  float _colorMax[4];
283 
284  public:
304  float iGm,
305  float iBm,
306  float iAlpham,
307  float iRM,
308  float iGM,
309  float iBM,
310  float iAlphaM)
311 
312  {
313  _colorMin[0] = iRm;
314  _colorMin[1] = iGm;
315  _colorMin[2] = iBm;
316  _colorMin[3] = iAlpham;
317 
318  _colorMax[0] = iRM;
319  _colorMax[1] = iGM;
320  _colorMax[2] = iBM;
321  _colorMax[3] = iAlphaM;
322  }
323 
324  virtual string getName() const
325  {
326  return "IncreasingColorShader";
327  }
328 
330  virtual int shade(Stroke &stroke) const;
331 };
332 
333 /* [ Color Shader ].
334  * Assigns a color to the stroke depending on the material of the shape to which ot belongs to.
335  * (Disney shader)
336  */
338  private:
339  float _coefficient;
340 
341  public:
342  MaterialColorShader(float coeff = 1.0f)
343  {
344  _coefficient = coeff;
345  }
346 
347  virtual string getName() const
348  {
349  return "MaterialColorShader";
350  }
351 
352  virtual int shade(Stroke &stroke) const;
353 };
354 
359  private:
360  float _amplitude;
361  float _scale;
362 
363  public:
365 
372  ColorNoiseShader(float iAmplitude, float iPeriod);
373 
374  virtual string getName() const
375  {
376  return "ColorNoiseShader";
377  }
378 
380  virtual int shade(Stroke &stroke) const;
381 };
382 
383 //
384 // Geometry Shaders
385 //
387 
392  private:
393  float _amount;
394 
395  public:
400  BackboneStretcherShader(float iAmount = 2.0f)
401  {
402  _amount = iAmount;
403  }
404 
405  virtual string getName() const
406  {
407  return "BackboneStretcherShader";
408  }
409 
411  virtual int shade(Stroke &stroke) const;
412 };
413 
418 class SamplingShader : public StrokeShader {
419  private:
420  float _sampling;
421 
422  public:
427  SamplingShader(float sampling)
428  {
429  _sampling = sampling;
430  }
431 
432  virtual string getName() const
433  {
434  return "SamplingShader";
435  }
436 
438  virtual int shade(Stroke &stroke) const;
439 };
440 
442  private:
443  float _amount;
444 
445  public:
446  ExternalContourStretcherShader(float iAmount = 2.0f)
447  {
448  _amount = iAmount;
449  }
450 
451  virtual string getName() const
452  {
453  return "ExternalContourStretcherShader";
454  }
455 
456  virtual int shade(Stroke &stroke) const;
457 };
458 
459 // Bezier curve stroke shader
466  private:
467  float _error;
468 
469  public:
476  {
477  _error = error;
478  }
479 
480  virtual string getName() const
481  {
482  return "BezierCurveShader";
483  }
484 
486  virtual int shade(Stroke &stroke) const;
487 };
488 
496  private:
497  float _error;
498 
499  public:
507  {
508  _error = iError;
509  }
510 
511  virtual string getName() const
512  {
513  return "PolygonalizationShader";
514  }
515 
517  virtual int shade(Stroke &stroke) const;
518 };
519 
527  private:
528  float _offset;
529 
530  public:
537  GuidingLinesShader(float iOffset)
538  {
539  _offset = iOffset;
540  }
541 
542  virtual string getName() const
543  {
544  return "GuidingLinesShader";
545  }
546 
548  virtual int shade(Stroke &stroke) const;
549 };
550 
555  public:
560  TipRemoverShader(real tipLength);
561 
564  {
565  }
566 
568  virtual string getName() const
569  {
570  return "TipRemoverShader";
571  }
572 
573  virtual int shade(Stroke &stroke) const;
574 
575  protected:
577 };
578 
584  private:
585  MTex *_mtex;
586  bNodeTree *_nodeTree;
587 
588  public:
594  {
595  _mtex = mtex;
596  _nodeTree = NULL;
597  }
598 
604  {
605  _nodeTree = nodetree;
606  _mtex = NULL;
607  }
608 
609  virtual string getName() const
610  {
611  return "BlenderTextureShader";
612  }
613 
615  virtual int shade(Stroke &stroke) const;
616 };
617 
623  private:
624  float _step;
625 
626  public:
632  {
633  _step = step;
634  }
635 
636  virtual string getName() const
637  {
638  return "StrokeTextureStepShader";
639  }
640 
642  virtual int shade(Stroke &stroke) const;
643 };
644 
645 } // end of namespace StrokeShaders
646 
647 } /* 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:51
inherits from class Rep
Definition: AppCanvas.cpp:18
double real
Definition: Precision.h:12