-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProceduralTextureGenerator.cs
1262 lines (1124 loc) · 52.4 KB
/
ProceduralTextureGenerator.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
-----------------------------------------------------------------------------
This source file is part of mogre-procedural
For the latest info, see http://code.google.com/p/mogre-procedural/
my blog:http://hi.baidu.com/rainssoft
this is overwrite ogre-procedural c++ project using c#, look ogre-procedural c++ source http://code.google.com/p/ogre-procedural/
Copyright (c) 2013-2020 rains soft
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
-----------------------------------------------------------------------------
*/
namespace Mogre_Procedural
{
using System;
using System.Collections.Generic;
using System.Text;
using Mogre;
using Math = Mogre.Math;
//* \addtogroup texturegrp Textures
//Elements for procedural texture creation.
//@{
//
//*
//\brief Create a texture consisting of cells aligned in a grid, or a chessboard.
//\details Cells can be irregular. If considered bump map, they have pyramid form.
//
//Examples:
//
//\b Default (MODE_GRID + PATTERN_BOTH)
//\code{.cpp}
//Procedural::TextureBuffer bufferCellDefault(256);
//Procedural::Cell(&bufferCellDefault).setDensity(4).process();
//\endcode
//\image html texture_cell_default.png
//
//\b MODE_CHESSBOARD + PATTERN_CONE
//\code{.cpp}
//Procedural::TextureBuffer bufferCellChessCone(256);
//Procedural::Cell(&bufferCellChessCone).setDensity(4).setMode(Procedural::Cell::MODE_CHESSBOARD).setPattern(Procedural::Cell::PATTERN_CONE).process();
//\endcode
//\image html texture_cell_chess.png
//
//\b MODE_GRID + PATTERN_CROSS
//\code{.cpp}
//Procedural::TextureBuffer bufferCellGridCross(256);
//Procedural::Cell(&bufferCellGridCross).setDensity(4).setMode(Procedural::Cell::MODE_GRID).setPattern(Procedural::Cell::PATTERN_CROSS).process();
//\endcode
//\image html texture_cell_grid.png
//
//C++ TO C# CONVERTER WARNING: The original type declaration contained unconverted modifiers:
//ORIGINAL LINE: class _ProceduralExport Cell : public TextureProcessing
public class Cell : TextureProcessing
{
//! Mode how to paint cells
public enum CELL_MODE : int
{
MODE_GRID, //!< Paint cells on a grid
MODE_CHESSBOARD //!< Paint cells on a chessboard
}
//! Mode how to construct cells
public enum CELL_PATTERN : int
{
PATTERN_BOTH, //!< PATTERN_CROSS | PATTERN_CONE
PATTERN_CROSS, //!< Construct cells from vertices
PATTERN_CONE //!< Construct cells from cicles
}
private ColourValue mColour = new ColourValue();
private uint mSeed = 0;
private uint mRegularity = 0;
private uint mDensity = 0;
private CELL_MODE mMode;
private CELL_PATTERN mPattern;
// *
// Default constructor.
// \param pBuffer Image buffer where to store the generated image.
//
public Cell(TextureBuffer pBuffer)
: base(pBuffer, "Cell") {
mColour = ColourValue.White;
mRegularity = 128;
mDensity = 8;
mMode = CELL_MODE.MODE_GRID;
mPattern = CELL_PATTERN.PATTERN_BOTH;
mSeed = 5120;
}
// *
// Set the colour of the cell top.
// \param colour New colour of the cell top (default Ogre::ColourValue::White)
//
public Cell setColour(ColourValue colour) {
//
//ORIGINAL LINE: mColour = colour;
mColour = (colour);
return this;
}
// *
// Set the colour of the cell top.
// \param red Red value of the cell top colour [0.0, 1.0] \(default 1.0)
// \param green Green value of the cell top colour [0.0, 1.0] \(default 1.0)
// \param blue Blue value of the cell top colour [0.0, 1.0] \(default 1.0)
// \param alpha %Alpha value of the cell top colour [0.0, 1.0] \(default 1.0)
//
public Cell setColour(float red, float green, float blue) {
return setColour(red, green, blue, 1.0f);
}
//
//ORIGINAL LINE: Cell& setColour(Ogre::float red, Ogre::float green, Ogre::float blue, Ogre::float alpha = 1.0f)
public Cell setColour(float red, float green, float blue, float alpha) {
mColour = new ColourValue(red, green, blue, alpha);
return this;
}
// *
// Set the seed for "random" number generator.
// \param seed Seed value where to set the random number generator (default 5120)
//
public Cell setSeed(uint seed) {
mSeed = seed;
return this;
}
// *
// Set the regularity of texture.
//
// The maximum value of 255 creates identical cells. The minimum 0 creates random forms for each cells.
// \param regularity New value for chaotic cell forms (default 128)
//
public Cell setRegularity(byte regularity) {
mRegularity = regularity;
return this;
}
// *
// Set the density of cells in texture.
//
// At least you have to set number of rows and columns in the grid to 1 or above.
// \param density New number of columns and rows (default 8)
//
public Cell setDensity(uint density) {
mDensity = density;
if (mDensity == 0)
mDensity = 1;
return this;
}
// *
// Set the cell mode of texture.
// \param mode New mode for cell ground (default MODE_GRID)
//
public Cell setMode(CELL_MODE mode) {
mMode = mode;
return this;
}
// *
// Set the cell pattern of texture.
// \param pattern New base of cell construction (default PATTERN_BOTH)
//
public Cell setPattern(CELL_PATTERN pattern) {
mPattern = pattern;
return this;
}
// *
// Run image generation
// \return Pointer to image buffer which has been set in the constructor.
//
public override TextureBuffer process() {
bool cfc;
float coeff = 0f;
RandomNumbers.Seed((int)mSeed);
float regularity = mRegularity / 255.0f;
//C++ TO C# CONVERTER TODO TASK: The memory management function 'malloc' has no equivalent in C#:
Vector3[] cellPoints = new Vector3[mDensity * mDensity]; //(Vector3)malloc(sizeof(Vector3) * mDensity * mDensity);
for (int y = 0; y < mDensity; ++y) {
for (int x = 0; x < mDensity; ++x) {
float rand1 = (float)RandomNumbers.NextNumber() / 65536.0f;
float rand2 = (float)RandomNumbers.NextNumber() / 65536.0f;
cellPoints[x + y * mDensity].x = (x + 0.5f + (rand1 - 0.5f) * (1 - regularity)) / mDensity - 1.0f / mBuffer.getWidth();
cellPoints[x + y * mDensity].y = (y + 0.5f + (rand2 - 0.5f) * (1 - regularity)) / mDensity - 1.0f / mBuffer.getHeight();
cellPoints[x + y * mDensity].z = 0;
}
}
for (int y = 0; y < mBuffer.getHeight(); ++y) {
for (int x = 0; x < mBuffer.getWidth(); ++x) {
Vector3 pixelPos = new Vector3();
pixelPos.x = (float)x / (float)mBuffer.getWidth();
pixelPos.y = (float)y / (float)mBuffer.getHeight();
pixelPos.z = 0.0f;
float minDist = 10;
float nextMinDist = minDist;
int xo = x * (int)mDensity / (int)mBuffer.getWidth();
int yo = y * (int)mDensity / (int)mBuffer.getHeight();
for (int v = -1; v < 2; ++v) {
int vo = ((yo + (int)mDensity + v) % (int)mDensity) * (int)mDensity;
for (int u = -1; u < 2; ++u) {
Vector3 cellPos = cellPoints[((xo + mDensity + u) % mDensity) + vo];
if (u == -1 && x * mDensity < mBuffer.getWidth())
cellPos.x -= 1;
if (v == -1 && y * mDensity < mBuffer.getHeight())
cellPos.y -= 1;
if (u == 1 && x * mDensity >= mBuffer.getWidth() * (mDensity - 1))
cellPos.x += 1;
if (v == 1 && y * mDensity >= mBuffer.getHeight() * (mDensity - 1))
cellPos.y += 1;
float norm = (pixelPos - cellPos).Length;//pixelPos.distance(cellPos);
if (norm < minDist) {
nextMinDist = minDist;
minDist = norm;
}
else if (norm < nextMinDist) {
nextMinDist = norm;
}
}
}
switch (mPattern) {
default:
//C++ TO C# CONVERTER TODO TASK: C# does not allow fall-through from a non-empty 'case':
case CELL_PATTERN.PATTERN_BOTH:
minDist = (nextMinDist - minDist) * mDensity;
break;
case CELL_PATTERN.PATTERN_CROSS:
minDist = 2 * nextMinDist * mDensity - 1;
break;
case CELL_PATTERN.PATTERN_CONE:
minDist = 1 - minDist * mDensity;
break;
}
if (minDist < 0)
minDist = 0;
if (minDist > 1)
minDist = 1;
switch (mMode) {
case CELL_MODE.MODE_CHESSBOARD:
cfc = ((xo & 1) ^ (yo & 1)) != 0;
int cfc_int = cfc ? 1 : 0;
coeff = (1 - 2 * cfc_int) / 2.5f;
mBuffer.setRed(x, y, (byte)((cfc_int + coeff * minDist) * mColour.r * 255.0f));
mBuffer.setGreen(x, y, (byte)((cfc_int + coeff * minDist) * mColour.g * 255.0f));
mBuffer.setBlue(x, y, (byte)((cfc_int + coeff * minDist) * mColour.b * 255.0f));
break;
default:
//C++ TO C# CONVERTER TODO TASK: C# does not allow fall-through from a non-empty 'case':
case CELL_MODE.MODE_GRID:
mBuffer.setRed(x, y, (byte)(minDist * mColour.r * 255.0f));
mBuffer.setGreen(x, y, (byte)(minDist * mColour.g * 255.0f));
mBuffer.setBlue(x, y, (byte)(minDist * mColour.b * 255.0f));
break;
}
mBuffer.setAlpha(x, y, mColour.a);
}
}
logMsg("Create cell texture : " + (mDensity).ToString() + "x" + (mDensity).ToString());
return mBuffer;
}
//private Vector3 malloc(long p) {
// throw new NotImplementedException();
//}
}
//*
//\brief Creates a cloud structured image.
//\details Creates a cloud structure from a specified perlin noise on a coloured background.
//
//Example:
//\code{.cpp}
//Procedural::TextureBuffer bufferCloud(256);
//Procedural::Cloud(&bufferCloud).process();
//\endcode
//\image html texture_cloud.png
//
//C++ TO C# CONVERTER WARNING: The original type declaration contained unconverted modifiers:
//ORIGINAL LINE: class _ProceduralExport Cloud : public TextureProcessing
public class Cloud : TextureProcessing
{
private ColourValue mColour = new ColourValue();
private uint mSeed = 0;
// *
// Default constructor.
// \param pBuffer Image buffer where to store the generated image.
//
public Cloud(TextureBuffer pBuffer)
: base(pBuffer, "Cloud") {
mColour = ColourValue.White;
mSeed = 5120;
}
// *
// Set the colour of the background.
// \param colour New colour for background (default Ogre::ColourValue::White)
//
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
public Cloud setColour(ColourValue colour) {
//
//ORIGINAL LINE: mColour = colour;
mColour = (colour);
return this;
}
// *
// Sets the colour of the background
// \param red Red value of background colour [0.0, 1.0] \(default 1.0)
// \param green Green value of background colour [0.0, 1.0] \(default 1.0)
// \param blue Blue value of background colour [0.0, 1.0] \(default 1.0)
// \param alpha %Alpha value of background colour [0.0, 1.0] \(default 1.0)
//
public Cloud setColour(float red, float green, float blue) {
return setColour(red, green, blue, 1.0f);
}
//
//ORIGINAL LINE: Cloud& setColour(Ogre::float red, Ogre::float green, Ogre::float blue, Ogre::float alpha = 1.0f)
public Cloud setColour(float red, float green, float blue, float alpha) {
mColour = new ColourValue(red, green, blue, alpha);
return this;
}
// *
// Set the seed for "random" number generator.
// \param seed Seed value where to set the random number generator (default 5120)
//
public Cloud setSeed(uint seed) {
mSeed = seed;
return this;
}
// *
// Run image generation
// \return Pointer to image buffer which has been set in the constructor.
//
public override TextureBuffer process() {
RandomNumbers.Seed((int)mSeed);
int r = RandomNumbers.NextNumber();
PerlinNoise noise = new PerlinNoise(8, 0.5f, 1.0f / 32.0f, 1.0f);
float filterLevel = 0.7f;
float preserveLevel = 0.3f;
for (int y = 0; y < mBuffer.getHeight(); y++) {
for (int x = 0; x < mBuffer.getWidth(); x++) {
float noiseVal = System.Math.Max(0.0f, System.Math.Min(1.0f, noise.function2D(x + r, y + r) * 0.5f + 0.5f));
mBuffer.setRed(x, y, (byte)System.Math.Min(preserveLevel * mColour.r * 255.0f + filterLevel * mColour.r * 255.0f * noiseVal, 255.0f));
mBuffer.setGreen(x, y, (byte)System.Math.Min(preserveLevel * mColour.g * 255.0f + filterLevel * mColour.g * 255.0f * noiseVal, 255.0f));
mBuffer.setBlue(x, y, (byte)System.Math.Min(preserveLevel * mColour.b * 255.0f + filterLevel * mColour.b * 255.0f * noiseVal, 255.0f));
mBuffer.setAlpha(x, y, mColour.a);
}
}
Utils.log("Create cloud texture");
return mBuffer;
}
}
//*
//\brief Fills full image with given colour gradients.
//\details Each corner of the image has unique color.
//
//Example:
//\code{.cpp}
//Procedural::TextureBuffer bufferGradient(256);
//Procedural::Gradient(&bufferGradient).setColours(Ogre::ColourValue::Black, Ogre::ColourValue::Red, Ogre::ColourValue::Green, Ogre::ColourValue::Blue).process();
//\endcode
//\image html texture_gradient.png
//
//C++ TO C# CONVERTER WARNING: The original type declaration contained unconverted modifiers:
//ORIGINAL LINE: class _ProceduralExport Gradient : public TextureProcessing
public class Gradient : TextureProcessing
{
private ColourValue mColourA = new ColourValue();
private ColourValue mColourB = new ColourValue();
private ColourValue mColourC = new ColourValue();
private ColourValue mColourD = new ColourValue();
// *
// Default constructor.
// \param pBuffer Image buffer where to store the generated image.
//
public Gradient(TextureBuffer pBuffer)
: base(pBuffer, "Gradient") {
mColourA = ColourValue.Blue;
mColourB = ColourValue.Green;
mColourC = ColourValue.Red;
mColourD = new ColourValue(0.0f, 1.0f, 1.0f);
}
// *
// Set the colour in the top left corner of the image.
// \param colour New colour in the top left corner for processing (default Ogre::ColourValue::Blue)
//
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
public Gradient setColourA(ColourValue colour) {
//
//ORIGINAL LINE: mColourA = colour;
mColourA = (colour);
return this;
}
// *
// Set the colour in the top left corner of the image.
// \param red Red value of new colour in the top left corner [0.0, 1.0] \(default 0.0)
// \param green Green value of new colour in the top left corner [0.0, 1.0] \(default 0.0)
// \param blue Blue value of new colour in the top left corner [0.0, 1.0] \(default 1.0)
// \param alpha %Alpha value of new colour in the top left corner [0.0, 1.0] \(default 1.0)
//
public Gradient setColourA(float red, float green, float blue) {
return setColourA(red, green, blue, 1.0f);
}
//
//ORIGINAL LINE: Gradient& setColourA(Ogre::float red, Ogre::float green, Ogre::float blue, Ogre::float alpha = 1.0f)
public Gradient setColourA(float red, float green, float blue, float alpha) {
mColourA = new ColourValue(red, green, blue, alpha);
return this;
}
// *
// Set the colour in the top right corner of the image.
// \param colour New colour in the top right corner for processing (default Ogre::ColourValue::Green)
//
public Gradient setColourB(ColourValue colour) {
//
//ORIGINAL LINE: mColourB = colour;
mColourB = (colour);
return this;
}
// *
// Set the colour in the top right corner of the image.
// \param red Red value of new colour in the top right corner [0.0, 1.0] \(default 0.0)
// \param green Green value of new colour in the top right corner [0.0, 1.0] \(default 1.0)
// \param blue Blue value of new colour in the top right corner [0.0, 1.0] \(default 0.0)
// \param alpha %Alpha value of new colour in the top right corner [0.0, 1.0] \(default 1.0)
//
public Gradient setColourB(float red, float green, float blue) {
return setColourB(red, green, blue, 1.0f);
}
//
//ORIGINAL LINE: Gradient& setColourB(Ogre::float red, Ogre::float green, Ogre::float blue, Ogre::float alpha = 1.0f)
public Gradient setColourB(float red, float green, float blue, float alpha) {
mColourB = new ColourValue(red, green, blue, alpha);
return this;
}
// *
// Set the colour in the bottom left corner of the image.
// \param colour New colour in the bottom left corner for processing (default Ogre::ColourValue::Red)
//
public Gradient setColourC(ColourValue colour) {
//
//ORIGINAL LINE: mColourC = colour;
mColourC = (colour);
return this;
}
// *
// Set the colour in the bottom left corner of the image.
// \param red Red value of new colour in the bottom left corner [0.0, 1.0] \(default 1.0)
// \param green Green value of new colour in the bottom left corner [0.0, 1.0] \(default 0.0)
// \param blue Blue value of new colour in the bottom left corner [0.0, 1.0] \(default 0.0)
// \param alpha %Alpha value of new colour in the bottom left corner [0.0, 1.0] \(default 1.0)
//
public Gradient setColourC(float red, float green, float blue) {
return setColourC(red, green, blue, 1.0f);
}
//
//ORIGINAL LINE: Gradient& setColourC(Ogre::float red, Ogre::float green, Ogre::float blue, Ogre::float alpha = 1.0f)
public Gradient setColourC(float red, float green, float blue, float alpha) {
mColourC = new ColourValue(red, green, blue, alpha);
return this;
}
// *
// Set the colour in the bottom right corner of the image.
// \param colour New colour in the bottom right corner for processing (default Ogre::ColourValue(0.0f, 1.0f, 1.0f))
//
public Gradient setColourD(ColourValue colour) {
//
//ORIGINAL LINE: mColourD = colour;
mColourD = (colour);
return this;
}
// *
// Set the colour in the bottom right corner of the image.
// \param red Red value of new colour in the bottom right corner [0.0, 1.0] \(default 0.0)
// \param green Green value of new colour in the bottom right corner [0.0, 1.0] \(default 1.0)
// \param blue Blue value of new colour in the bottom right corner [0.0, 1.0] \(default 1.0)
// \param alpha %Alpha value of new colour in the bottom right corner [0.0, 1.0] \(default 1.0)
//
public Gradient setColourD(float red, float green, float blue) {
return setColourD(red, green, blue, 1.0f);
}
//
//ORIGINAL LINE: Gradient& setColourD(Ogre::float red, Ogre::float green, Ogre::float blue, Ogre::float alpha = 1.0f)
public Gradient setColourD(float red, float green, float blue, float alpha) {
mColourD = new ColourValue(red, green, blue, alpha);
return this;
}
// *
// Sets the colours of the image corners.
// \param colourA New colour in the top left corner (default Ogre::ColourValue::Blue)
// \param colourB New colour in the top right corner (default Ogre::ColourValue::Green)
// \param colourC New colour in the bottom left corner (default Ogre::ColourValue::Red)
// \param colourD New colour in the bottom right corner (default Ogre::ColourValue(0.0f, 1.0f, 1.0f))
//
public Gradient setColours(ColourValue colourA, ColourValue colourB, ColourValue colourC, ColourValue colourD) {
//
//ORIGINAL LINE: mColourA = colourA;
mColourA = (colourA);
//
//ORIGINAL LINE: mColourB = colourB;
mColourB = (colourB);
//
//ORIGINAL LINE: mColourC = colourC;
mColourC = (colourC);
//
//ORIGINAL LINE: mColourD = colourD;
mColourD = (colourD);
return this;
}
// *
// Run image generation
// \return Pointer to image buffer which has been set in the constructor.
//
public override TextureBuffer process() {
float finv_WH = 1.0f / (float)(mBuffer.getWidth() * mBuffer.getHeight());
for (int y = 0; y < mBuffer.getHeight(); y++) {
for (int x = 0; x < mBuffer.getWidth(); x++) {
float a = (float)((mBuffer.getWidth() - x) * (mBuffer.getHeight() - y)) * finv_WH;
float b = (float)((x) * (mBuffer.getHeight() - y)) * finv_WH;
float c = (float)((mBuffer.getWidth() - x) * (y)) * finv_WH;
float d = (float)((x) * (y)) * finv_WH;
mBuffer.setRed(x, y, (byte)(((mColourA.r * a) + (mColourB.r * b) + (mColourC.r * c) + (mColourD.r * d)) * 255.0f));
mBuffer.setGreen(x, y, (byte)(((mColourA.g * a) + (mColourB.g * b) + (mColourC.g * c) + (mColourD.g * d)) * 255.0f));
mBuffer.setBlue(x, y, (byte)(((mColourA.b * a) + (mColourB.b * b) + (mColourC.b * c) + (mColourD.b * d)) * 255.0f));
mBuffer.setAlpha(x, y, (byte)(((mColourA.a * a) + (mColourB.a * b) + (mColourC.a * c) + (mColourD.a * d)) * 255.0f));
}
}
Utils.log("Create gradient texture");
return mBuffer;
}
}
//*
//\brief Load an image from a resource.
//\details Try to load an image from a resource.
//
//Example:
//\code{.cpp}
//Procedural::TextureBuffer bufferImage(256);
//Procedural::Image(&bufferImage).setFile("red_brick.jpg").process();
//\endcode
//\image html texture_image.png
//
//C++ TO C# CONVERTER WARNING: The original type declaration contained unconverted modifiers:
//ORIGINAL LINE: class _ProceduralExport Image : public TextureProcessing
public class Image : TextureProcessing
{
private string mFile = "";
private string mGroup = "";
// *
// Default constructor.
// \param pBuffer Image buffer where to store the generated image.
//
public Image(TextureBuffer pBuffer)
: base(pBuffer, "Image") {
}
// *
// Set the colour of the background.
// \param filename Name of an image file to load.
// \param groupname Name of the resource group to search for the image
//
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
public Image setFile(string filename) {
return setFile(filename, ResourceGroupManager.DEFAULT_RESOURCE_GROUP_NAME);
}
//
//ORIGINAL LINE: Image& setFile(Ogre::String filename, Ogre::String groupname = Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME)
public Image setFile(string filename, string groupname) {
mFile = filename;
mGroup = groupname;
return this;
}
// *
// Run image generation
// \return Pointer to image buffer which has been set in the constructor.
//
public override TextureBuffer process() {
Mogre.Image img = new Mogre.Image();
img.Load(mFile, mGroup);
if (img.Height < mBuffer.getHeight() || img.Width < mBuffer.getWidth())
return mBuffer;
for (int y = 0; y < mBuffer.getHeight(); y++) {
for (int x = 0; x < mBuffer.getWidth(); x++) {
mBuffer.setPixel(x, y, img.GetColourAt(x, y, 0));
}
}
Utils.log("Create texture from image");
return mBuffer;
}
}
//*
//\brief Creates a labyrinth structured image.
//\details Creates a labyrinth structure from a specified perlin noise on a coloured background.
//
//Example:
//\code{.cpp}
//Procedural::TextureBuffer bufferLabyrinth(256);
//Procedural::Labyrinth(&bufferLabyrinth).process();
//\endcode
//\image html texture_labyrinth.png
//
//C++ TO C# CONVERTER WARNING: The original type declaration contained unconverted modifiers:
//ORIGINAL LINE: class _ProceduralExport Labyrinth : public TextureProcessing
public class Labyrinth : TextureProcessing
{
private ColourValue mColour = new ColourValue();
private uint mSeed = 0;
// *
// Default constructor.
// \param pBuffer Image buffer where to store the generated image.
//
public Labyrinth(TextureBuffer pBuffer)
: base(pBuffer, "Labyrinth") {
mColour = ColourValue.White;
mSeed = 5120;
}
// *
// Set the colour of the background.
// \param colour New colour for background (default Ogre::ColourValue::White)
//
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
public Labyrinth setColour(ColourValue colour) {
//
//ORIGINAL LINE: mColour = colour;
mColour = (colour);
return this;
}
// *
// Sets the colour of the background
// \param red Red value of background colour [0.0, 1.0] \(default 1.0)
// \param green Green value of background colour [0.0, 1.0] \(default 1.0)
// \param blue Blue value of background colour [0.0, 1.0] \(default 1.0)
// \param alpha %Alpha value of background colour [0.0, 1.0] \(default 1.0)
//
public Labyrinth setColour(float red, float green, float blue) {
return setColour(red, green, blue, 1.0f);
}
//
//ORIGINAL LINE: Labyrinth& setColour(Ogre::float red, Ogre::float green, Ogre::float blue, Ogre::float alpha = 1.0f)
public Labyrinth setColour(float red, float green, float blue, float alpha) {
mColour = new ColourValue(red, green, blue, alpha);
return this;
}
// *
// Set the seed for "random" number generator.
// \param seed Seed value where to set the random number generator (default 5120)
//
public Labyrinth setSeed(uint seed) {
mSeed = seed;
return this;
}
// *
// Run image generation
// \return Pointer to image buffer which has been set in the constructor.
//
public override TextureBuffer process() {
RandomNumbers.Seed((int)mSeed);
int r = RandomNumbers.NextNumber();
PerlinNoise noise = new PerlinNoise(1, 0.65f, 1.0f / 16.0f, 1.0f);
float filterLevel = 0.7f;
float preserveLevel = 0.3f;
for (int y = 0; y < mBuffer.getHeight(); y++) {
for (int x = 0; x < mBuffer.getWidth(); x++) {
float noiseVal = System.Math.Min(1.0f, Math.Abs(noise.function2D(x + r, y + r)));
mBuffer.setRed(x, y, (byte)System.Math.Min(preserveLevel * mColour.r * 255.0f + filterLevel * mColour.r * 255.0f * noiseVal, 255.0f));
mBuffer.setGreen(x, y, (byte)System.Math.Min(preserveLevel * mColour.g * 255.0f + filterLevel * mColour.g * 255.0f * noiseVal, 255.0f));
mBuffer.setBlue(x, y, (byte)System.Math.Min(preserveLevel * mColour.b * 255.0f + filterLevel * mColour.b * 255.0f * noiseVal, 255.0f));
mBuffer.setAlpha(x, y, mColour.a);
}
}
Utils.log("Create labyrinth texture");
return mBuffer;
}
}
//*
//\brief Creates a marble structured image.
//\details Creates a marbel structure from a specified perlin noise on a coloured background.
//
//Example:
//\code{.cpp}
//Procedural::TextureBuffer bufferMarble(256);
//Procedural::Marble(&bufferMarble).process();
//\endcode
//\image html texture_marble.png
//
//C++ TO C# CONVERTER WARNING: The original type declaration contained unconverted modifiers:
//ORIGINAL LINE: class _ProceduralExport Marble : public TextureProcessing
public class Marble : TextureProcessing
{
private ColourValue mColour = new ColourValue();
private uint mSeed = 0;
// *
// Default constructor.
// \param pBuffer Image buffer where to store the generated image.
//
public Marble(TextureBuffer pBuffer)
: base(pBuffer, "Marble") {
mColour = ColourValue.White;
mSeed = 5120;
}
// *
// Set the colour of the background.
// \param colour New colour for marble structure (default Ogre::ColourValue::White)
//
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
public Marble setColour(ColourValue colour) {
//
//ORIGINAL LINE: mColour = colour;
mColour = (colour);
return this;
}
// *
// Set the colour of the background.
// \param red Red value of the marble structure colour [0.0, 1.0] \(default 1.0)
// \param green Green value of the marble structure colour [0.0, 1.0] \(default 1.0)
// \param blue Blue valu of the marble structure coloure [0.0, 1.0] \(default 1.0)
// \param alpha %Alpha value of the marble structure colour [0.0, 1.0] \(default 1.0)
//
public Marble setColour(float red, float green, float blue) {
return setColour(red, green, blue, 1.0f);
}
//
//ORIGINAL LINE: Marble& setColour(Ogre::float red, Ogre::float green, Ogre::float blue, Ogre::float alpha = 1.0f)
public Marble setColour(float red, float green, float blue, float alpha) {
mColour = new ColourValue(red, green, blue, alpha);
return this;
}
// *
// Set the seed for "random" number generator.
// \param seed Seed value where to set the random number generator (default 5120)
//
public Marble setSeed(uint seed) {
mSeed = seed;
return this;
}
// *
// Run image generation
// \return Pointer to image buffer which has been set in the constructor.
//
public override TextureBuffer process() {
RandomNumbers.Seed((int)mSeed);
int r = RandomNumbers.NextNumber();
PerlinNoise noise = new PerlinNoise(2, 0.65f, 1.0f / 32.0f, 1.0f);
float xFact = 1.0f / 96.0f;
float yFact = 1.0f / 48.0f;
float filterLevel = 0.7f;
float preserveLevel = 0.3f;
for (int y = 0; y < mBuffer.getHeight(); y++) {
for (int x = 0; x < mBuffer.getWidth(); x++) {
float noiseVal = System.Math.Min(1.0f, Math.Abs(Math.Sin(x * xFact + y * yFact + noise.function2D(x + r, y + r)) * Math.PI));
mBuffer.setRed(x, y, (byte)System.Math.Min(preserveLevel * mColour.r * 255.0f + filterLevel * mColour.r * 255.0f * noiseVal, 255.0f));
mBuffer.setGreen(x, y, (byte)System.Math.Min(preserveLevel * mColour.g * 255.0f + filterLevel * mColour.g * 255.0f * noiseVal, 255.0f));
mBuffer.setBlue(x, y, (byte)System.Math.Min(preserveLevel * mColour.b * 255.0f + filterLevel * mColour.b * 255.0f * noiseVal, 255.0f));
mBuffer.setAlpha(x, y, mColour.a);
}
}
Utils.log("Create marble texture");
return mBuffer;
}
}
//*
//\brief Fills full image with noise in a given colour.
//\details High quality noise with various noise algorithms.
//
//Examples:
//\b White noise (default)
//\code{.cpp}
//Procedural::TextureBuffer bufferNoiseWhite(256);
//Procedural::Noise(&bufferNoiseWhite).setType(Procedural::Noise::NOISE_WHITE).process();
//\endcode
//\image html texture_noise_white.png
//
//\b Perlin noise
//\code{.cpp}
//Procedural::TextureBuffer bufferNoisePerlin(256);
//Procedural::Noise(&bufferNoisePerlin).setType(Procedural::Noise::NOISE_PERLIN).process();
//\endcode
//\image html texture_noise_perlin.png
//
//C++ TO C# CONVERTER WARNING: The original type declaration contained unconverted modifiers:
//ORIGINAL LINE: class _ProceduralExport Noise : public TextureProcessing
public class Noise : TextureProcessing
{
//! Noise generator type
public enum NOISE_TYPE : int
{
NOISE_WHITE, //!< White noise
NOISE_PERLIN //!< Perlin noise
}
private ColourValue mColour = new ColourValue();
private uint mSeed = 0;
private NOISE_TYPE mType;
// *
// Default constructor.
// \param pBuffer Image buffer where to store the generated image.
//
public Noise(TextureBuffer pBuffer)
: base(pBuffer, "Noise") {
mColour = ColourValue.White;
mSeed = 5120;
mType = (int)NOISE_TYPE.NOISE_WHITE;
}
// *
// Set the colour of the noise.
// \param colour New colour of the noise (default Ogre::ColourValue::White)
//
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
public Noise setColour(ColourValue colour) {
//
//ORIGINAL LINE: mColour = colour;
mColour = (colour);
return this;
}
// *
// Set the colour of the noise.
// \param red Red value of the noise colour [0.0, 1.0] \(default 1.0)
// \param green Green value of the noise colour [0.0, 1.0] \(default 1.0)
// \param blue Blue value of the noise colour [0.0, 1.0] \(default 1.0)
// \param alpha %Alpha value of the noise colour [0.0, 1.0] \(default 1.0)
//
public Noise setColour(float red, float green, float blue) {
return setColour(red, green, blue, 1.0f);
}
//
//ORIGINAL LINE: Noise& setColour(Ogre::float red, Ogre::float green, Ogre::float blue, Ogre::float alpha = 1.0f)
public Noise setColour(float red, float green, float blue, float alpha) {
mColour = new ColourValue(red, green, blue, alpha);
return this;
}
// *
// Set the seed for "random" number generator.
// \param seed Seed value where to set the random number generator (default 5120)
//
public Noise setSeed(uint seed) {
mSeed = seed;
return this;
}
// *
// Set the type of noise generation.
// \param type Type of noise generator (default NOISE_WHITE)
//
public Noise setType(NOISE_TYPE @type) {
mType = @type;
return this;
}
// *
// Run image generation
// \return Pointer to image buffer which has been set in the constructor.
//
public override TextureBuffer process() {
NoiseBase noiseGen;
switch (mType) {
case NOISE_TYPE.NOISE_PERLIN:
noiseGen = new PerlinNoise();
break;
default:
//C++ TO C# CONVERTER TODO TASK: C# does not allow fall-through from a non-empty 'case':
case NOISE_TYPE.NOISE_WHITE:
noiseGen = new WhiteNoise(mSeed);
break;
}
byte[] field = noiseGen.field2D(mBuffer.getWidth(), mBuffer.getHeight());
for (int y = 0; y < mBuffer.getHeight(); ++y) {
for (int x = 0; x < mBuffer.getWidth(); ++x) {
float noiseVal = (float)field[y * mBuffer.getWidth() + x];
mBuffer.setRed(x, y, (byte)(noiseVal * mColour.r));
mBuffer.setGreen(x, y, (byte)(noiseVal * mColour.g));
mBuffer.setBlue(x, y, (byte)(noiseVal * mColour.b));
mBuffer.setAlpha(x, y, (byte)(mColour.a * 255.0f));
}
}
field = null;
noiseGen.Dispose();
Utils.log("Create noise texture : " + mType.ToString());//StringConverter.ToString(mType));
return mBuffer;
}
}
//*
//\brief Fills full image with given colour.
//\details Set all pixel to the same color.
//
//Example:
//\code{.cpp}
//Procedural::TextureBuffer bufferSolid(256);
//Procedural::Solid(&bufferSolid).setColour(Ogre::ColourValue(0.0f, 0.5f, 1.0f, 1.0f)).process();
//\endcode
//\image html texture_solid.png
//
//C++ TO C# CONVERTER WARNING: The original type declaration contained unconverted modifiers:
//ORIGINAL LINE: class _ProceduralExport Solid : public TextureProcessing
public class Solid : TextureProcessing
{
private ColourValue mColour = new ColourValue();
// *
// Default constructor.
// \param pBuffer Image buffer where to store the generated image.
//
public Solid(TextureBuffer pBuffer)
: base(pBuffer, "Solid") {
mColour = ColourValue.Black;