Blender V4.3
BasicStrokeShaders.h
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2023 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
5#pragma once
6
12#include <fstream>
13
14#include "Stroke.h"
15#include "StrokeShader.h"
16
17#include "../geometry/Bezier.h"
18#include "../geometry/Geom.h"
19
20extern "C" {
21struct MTex;
22struct bNodeTree;
23}
24
25using namespace std;
26
27namespace Freestyle {
28
29using namespace Geometry;
30
31namespace StrokeShaders {
32
33//
34// Thickness modifiers
35//
37
42 public:
47 ConstantThicknessShader(float thickness)
48 {
49 _thickness = thickness;
50 }
51
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 delimiters.
72 */
74 public:
76 {
77 _thickness = thickness;
78 }
79
81
82 virtual string getName() const
83 {
84 return "ConstantExternThicknessShader";
85 }
86
87 virtual int shade(Stroke &stroke) const;
88
89 private:
90 float _thickness;
91};
92
100 public:
107 IncreasingThicknessShader(float iThicknessMin, float iThicknessMax)
108 {
109 _ThicknessMin = iThicknessMin;
110 _ThicknessMax = iThicknessMax;
111 }
112
115
116 virtual string getName() const
117 {
118 return "IncreasingThicknessShader";
119 }
120
122 virtual int shade(Stroke &stroke) const;
123
124 private:
125 float _ThicknessMin;
126 float _ThicknessMax;
127};
128
134 private:
135 float _ThicknessMin;
136 float _ThicknessMax;
137 float _ratio;
138
139 public:
148 ConstrainedIncreasingThicknessShader(float iThicknessMin, float iThicknessMax, float iRatio)
149
150 {
151 _ThicknessMin = iThicknessMin;
152 _ThicknessMax = iThicknessMax;
153 _ratio = iRatio;
154 }
155
158
159 virtual string getName() const
160 {
161 return "ConstrainedIncreasingThicknessShader";
162 }
163
165 virtual int shade(Stroke &stroke) const;
166};
167
168/* [ Thickness Shader ].
169 * Modifies the thickness in a relative way depending on its length.
170 */
172 private:
173 float _minThickness;
174 float _maxThickness;
175 // We divide the strokes in 4 categories:
176 // l > 300
177 // 100 < l < 300
178 // 50 < l < 100
179 // l < 50
180
181 public:
182 LengthDependingThicknessShader(float iMinThickness, float iMaxThickness)
183 {
184 _minThickness = iMinThickness;
185 _maxThickness = iMaxThickness;
186 }
187
189
190 virtual string getName() const
191 {
192 return "LengthDependingThicknessShader";
193 }
194
195 virtual int shade(Stroke &stroke) const;
196};
197
203 private:
204 float _amplitude;
205 float _scale;
206
207 public:
209
216 ThicknessNoiseShader(float iAmplitude, float iPeriod);
217
218 virtual string getName() const
219 {
220 return "ThicknessNoiseShader";
221 }
222
224 virtual int shade(Stroke &stroke) const;
225};
226
227//
228// Color shaders
229//
231
235 public:
246 ConstantColorShader(float iR, float iG, float iB, float iAlpha = 1.0f)
247 {
248 _color[0] = iR;
249 _color[1] = iG;
250 _color[2] = iB;
251 _color[3] = iAlpha;
252 }
253
254 virtual string getName() const
255 {
256 return "ConstantColorShader";
257 }
258
260 virtual int shade(Stroke &stroke) const;
261
262 private:
263 float _color[4];
264};
265
272 private:
273 float _colorMin[4];
274 float _colorMax[4];
275
276 public:
296 float iGm,
297 float iBm,
298 float iAlpham,
299 float iRM,
300 float iGM,
301 float iBM,
302 float iAlphaM)
303
304 {
305 _colorMin[0] = iRm;
306 _colorMin[1] = iGm;
307 _colorMin[2] = iBm;
308 _colorMin[3] = iAlpham;
309
310 _colorMax[0] = iRM;
311 _colorMax[1] = iGM;
312 _colorMax[2] = iBM;
313 _colorMax[3] = iAlphaM;
314 }
315
316 virtual string getName() const
317 {
318 return "IncreasingColorShader";
319 }
320
322 virtual int shade(Stroke &stroke) const;
323};
324
325/* [ Color Shader ].
326 * Assigns a color to the stroke depending on the material of the shape to which ot belongs to.
327 * (Disney shader)
328 */
330 private:
331 float _coefficient;
332
333 public:
334 MaterialColorShader(float coeff = 1.0f)
335 {
336 _coefficient = coeff;
337 }
338
339 virtual string getName() const
340 {
341 return "MaterialColorShader";
342 }
343
344 virtual int shade(Stroke &stroke) const;
345};
346
351 private:
352 float _amplitude;
353 float _scale;
354
355 public:
357
364 ColorNoiseShader(float iAmplitude, float iPeriod);
365
366 virtual string getName() const
367 {
368 return "ColorNoiseShader";
369 }
370
372 virtual int shade(Stroke &stroke) const;
373};
374
375//
376// Geometry Shaders
377//
379
384 private:
385 float _amount;
386
387 public:
392 BackboneStretcherShader(float iAmount = 2.0f)
393 {
394 _amount = iAmount;
395 }
396
397 virtual string getName() const
398 {
399 return "BackboneStretcherShader";
400 }
401
403 virtual int shade(Stroke &stroke) const;
404};
405
411 private:
412 float _sampling;
413
414 public:
419 SamplingShader(float sampling)
420 {
421 _sampling = sampling;
422 }
423
424 virtual string getName() const
425 {
426 return "SamplingShader";
427 }
428
430 virtual int shade(Stroke &stroke) const;
431};
432
434 private:
435 float _amount;
436
437 public:
438 ExternalContourStretcherShader(float iAmount = 2.0f)
439 {
440 _amount = iAmount;
441 }
442
443 virtual string getName() const
444 {
445 return "ExternalContourStretcherShader";
446 }
447
448 virtual int shade(Stroke &stroke) const;
449};
450
451// Bezier curve stroke shader
458 private:
459 float _error;
460
461 public:
468 {
469 _error = error;
470 }
471
472 virtual string getName() const
473 {
474 return "BezierCurveShader";
475 }
476
478 virtual int shade(Stroke &stroke) const;
479};
480
488 private:
489 float _error;
490
491 public:
499 {
500 _error = iError;
501 }
502
503 virtual string getName() const
504 {
505 return "PolygonalizationShader";
506 }
507
509 virtual int shade(Stroke &stroke) const;
510};
511
519 private:
520 float _offset;
521
522 public:
529 GuidingLinesShader(float iOffset)
530 {
531 _offset = iOffset;
532 }
533
534 virtual string getName() const
535 {
536 return "GuidingLinesShader";
537 }
538
540 virtual int shade(Stroke &stroke) const;
541};
542
547 public:
552 TipRemoverShader(real tipLength);
553
555 virtual ~TipRemoverShader() {}
556
558 virtual string getName() const
559 {
560 return "TipRemoverShader";
561 }
562
563 virtual int shade(Stroke &stroke) const;
564
565 protected:
567};
568
575 private:
576 MTex *_mtex;
577 bNodeTree *_nodeTree;
578
579 public:
585 {
586 _mtex = mtex;
587 _nodeTree = nullptr;
588 }
589
595 {
596 _nodeTree = nodetree;
597 _mtex = nullptr;
598 }
599
600 virtual string getName() const
601 {
602 return "BlenderTextureShader";
603 }
604
606 virtual int shade(Stroke &stroke) const;
607};
608
615 private:
616 float _step;
617
618 public:
624 {
625 _step = step;
626 }
627
628 virtual string getName() const
629 {
630 return "StrokeTextureStepShader";
631 }
632
634 virtual int shade(Stroke &stroke) const;
635};
636
637} // end of namespace StrokeShaders
638
639} /* namespace Freestyle */
Class to define a Bezier curve of order 4.
Vectors and Matrices (useful type definitions)
Class defining StrokeShader.
Classes to define a stroke.
virtual int shade(Stroke &stroke) const
! Bezier curve stroke shader
virtual int shade(Stroke &stroke) const
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)
virtual int shade(Stroke &stroke) const
virtual int shade(Stroke &stroke) const
static void error(const char *str)
inherits from class Rep
Definition AppCanvas.cpp:20
double real
Definition Precision.h:14