IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Lazarus Pascal Discussion :

Génération de texture aléatoire : algorithme "Diamond square"


Sujet :

Lazarus Pascal

  1. #1
    Expert confirmé
    Avatar de BeanzMaster
    Homme Profil pro
    Amateur Passionné
    Inscrit en
    Septembre 2015
    Messages
    1 899
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Suisse

    Informations professionnelles :
    Activité : Amateur Passionné
    Secteur : Tourisme - Loisirs

    Informations forums :
    Inscription : Septembre 2015
    Messages : 1 899
    Points : 4 346
    Points
    4 346
    Billets dans le blog
    2
    Par défaut Génération de texture aléatoire : algorithme "Diamond square"
    Salut à tous, pour une petite application de démonstration pour BZScene, je me suis intéressé à l'algorithme "diamant carré".

    J'ai trouvé plusieurs documentations sur le sujet :

    https://fr.wikipedia.org/wiki/Algorithme_Diamant-Carré
    https://yahiko.developpez.com/tutoriels/heightmap/
    https://hiko-seijuro.developpez.com/...iamond-square/
    https://stackoverflow.com/questions/...uare-algorithm
    https://learn.64bitdragon.com/articl...uare-algorithm

    L'algorithme en lui même n'est pas très compliqué. Il est dit que l'on doit utiliser une matrice carrée de taille 2n + 1.

    Ma question. Comment adapter, modifier l'algorithme pour qu'il accepte une matrice carrée de taille 2n ?

    J'ai essayé, j'ai vue, je suis vaincu. Je n'arrive pas à trouver le petit truc à ajouter (ou soustraire) aux variables.

    Voici mon code pour une matrice de taille 2n + 1 :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
    unit uMainForm;
     
    {$mode objfpc}{$H+}
     
    interface
     
    uses
      Classes, SysUtils, Forms, Controls, Graphics, Dialogs, ExtCtrls, StdCtrls,
      BZColors, BZGraphic, BZBitmap;
     
    type
     
      { TBZBitmapRenderFiltersHelper }
     
      TBZBitmapRenderFiltersHelper = class helper for TBZBitmapRenderFilters
      public    
        procedure DiamondSquare(Const RangeOffset : Integer = 64; Const FallOff : Single = 0.8);
      end;
     
      { TForm1 }
     
      TForm1 = class(TForm)
        pnlView: TPanel;
        Button1: TButton;
        Button2: TButton;
        procedure FormCreate(Sender: TObject);
        procedure FormClose(Sender: TObject; var CloseAction: TCloseAction);
        procedure pnlViewPaint(Sender: TObject);
     
        procedure Button2Click(Sender: TObject);
      private
      protected
        FTexture : TBZBitmap;
      public
     
      end;
     
    var
      Form1: TForm1;
     
    implementation
     
    {$R *.lfm}
     
    uses BZMath, BZTypesHelpers;
     
    { TForm1 }
     
    procedure TForm1.FormCreate(Sender: TObject);
    begin
      FTexture := TBZBitmap.Create(512,512);
    end;
     
    procedure TForm1.FormClose(Sender: TObject; var CloseAction: TCloseAction);
    begin
      FreeAndNil(FTexture);
    end;
     
    procedure TForm1.pnlViewPaint(Sender: TObject);
    begin
      if Assigned(FTexture) then FTexture.DrawToCanvas(pnlView.Canvas, pnlView.ClientRect);
    end;
     
    procedure TForm1.Button2Click(Sender: TObject);
    begin
      FTexture.RenderFilter.DiamondSquare();
      pnlView.Invalidate;
    end;
     
    { TBZBitmapRenderFiltersHelper }
     
    { https://fr.wikipedia.org/wiki/Algorithme_Diamant-Carré
      https://yahiko.developpez.com/tutoriels/heightmap/
      https://hiko-seijuro.developpez.com/articles/diamond-square/
      https://stackoverflow.com/questions/2755750/diamond-square-algorithm
      https://learn.64bitdragon.com/articles/computer-science/procedural-generation/the-diamond-square-algorithm }
    procedure TBZBitmapRenderFiltersHelper.DiamondSquare(Const RangeOffset: Integer; Const FallOff: Single);
    Var
      TileSize, RandValue, rand, HalfSize : Integer;
      xx, yy, xmax, ymax : integer;
      AColor, AColorSum : TBZColorVector;
      NeedResize : Boolean;
      DstColor : TBZColor;
    begin
      // Ajustement des dimensions du bitmap si elles ne sont pas de l'ordre de 2n + 1
      NeedResize := False;
      xMax := OwnerBitmap.Width;
      yMax := OwnerBitmap.Height;
      if xMax.IsPowerOfTwo then
      begin
        xMax := xMax + 1;
        NeedResize := True;
      end;
      if yMax.IsPowerOfTwo then
      begin
        yMax := yMax + 1;
        NeedResize := True;
      end;
      if NeedResize then OwnerBitmap.SetSize(xMax, yMax);
     
      OwnerBitmap.Clear(clrBlack);
      Randomize;
      xmax := OwnerBitmap.MaxWidth;//((x2-x1) div 2)-1;
      ymax := OwnerBitmap.MaxHeight;//((y2-y1) div 2)-1;
     
      randValue := random(256);
      DstColor.Create(RandValue, RandValue, RandValue);
      OwnerBitmap.setPixel(0,0, DstColor);
      //randValue := random(MaxValue);
      //RndColor.Create(RandValue, RandValue, RandValue);
      OwnerBitmap.setPixel(xmax,0, DstColor);
      //randValue := random(MaxValue);
      //RndColor.Create(RandValue, RandValue, RandValue);
      OwnerBitmap.setPixel(0,ymax, DstColor);
      //randValue := random(MaxValue);
      //RndColor.Create(RandValue, RandValue, RandValue);
      OwnerBitmap.setPixel(xmax,ymax, DstColor);
     
      TileSize := xmax;
      RandValue := RangeOffset;
      While TileSize > 1 do
      begin
        HalfSize :=  TileSize div 2; //((TileSize + 1) div 2) - 1;
     
        // Diamond
        xx := 0;
        While (xx < OwnerBitmap.Width) do
        begin
          yy := 0;
          While (yy < OwnerBitmap.Height) do
          begin
            AColorSum := ClrTransparent.AsColorVector;
     
            AColor := OwnerBitmap.getPixel(xx, yy).AsColorVector;
            AColorSum :=  AColorSum + AColor;
     
            AColor := OwnerBitmap.getPixel(xx + TileSize, yy).AsColorVector;
            AColorSum :=  AColorSum + AColor;
     
            AColor := OwnerBitmap.getPixel(xx, yy + TileSize).AsColorVector;
            AColorSum :=  AColorSum + AColor;
     
            AColor := OwnerBitmap.getPixel(xx + TileSize, yy + TileSize).AsColorVector;
            AColorSum :=  AColorSum + AColor;
     
            AColorSum :=  AColorSum * 0.25;
     
            Rand := Integer.RandomRange(-RandValue, RandValue);
            AColor.Create(Rand * _FloatColorRatio);
            AColorSum :=  AColorSum + AColor;
     
            DstColor.Create(AColorSum);
            OwnerBitmap.setPixel(xx + HalfSize, yy + HalfSize, DstColor);
     
            yy := yy + TileSize;
          end;
          xx := xx + TileSize;
        end;
     
        // Square
        xx := 0;
        While (xx < OwnerBitmap.Width) do
        begin
          yy := (xx + HalfSize) mod TileSize;
          While (yy < OwnerBitmap.Height) do
          begin
            AColorSum := ClrTransparent.AsColorVector;
     
            AColor := OwnerBitmap.getPixel((xx - halfSize + xmax) mod xmax, yy).AsColorVector;
            AColorSum :=  AColorSum + AColor;
     
            AColor := OwnerBitmap.getPixel((xx + halfSize) mod xmax, yy).AsColorVector;
            AColorSum :=  AColorSum + AColor;
     
            AColor := OwnerBitmap.getPixel(xx, (yy + halfSize) mod ymax).AsColorVector;
            AColorSum :=  AColorSum + AColor;
     
            AColor := OwnerBitmap.getPixel(xx, (yy - halfSize + ymax) mod ymax).AsColorVector;
            AColorSum :=  AColorSum + AColor;
     
            AColorSum :=  AColorSum * 0.25;
     
            Rand := Integer.RandomRange(-RandValue, RandValue);
            AColor.Create(Rand * _FloatColorRatio);
            AColorSum :=  AColorSum + AColor;
     
            DstColor.Create(AColorSum);
            OwnerBitmap.setPixel(xx, yy, DstColor);
     
            if (xx = 0) then OwnerBitmap.setPixel(xmax, yy, DstColor);
            if (yy = 0) then OwnerBitmap.setPixel(xx, ymax, DstColor);
     
            yy := yy + TileSize;
          end;
          xx := xx + HalfSize;
        end;
     
        //RandValue := (RandValue div 2) + 1;
        Randvalue := RandValue - Round((RandValue * 0.5) * FallOff);  
        TileSize := TileSize div 2;
      end;
    end;
     
    end.
    Résultat :

    Nom : 2020-07-19_121057.jpg
Affichages : 510
Taille : 38,7 Ko

    Merci d'avance

    A+

    Jérôme
    • "L'Homme devrait mettre autant d'ardeur à simplifier sa vie qu'il met à la compliquer" - Henri Bergson
    • "Bien des livres auraient été plus clairs s'ils n'avaient pas voulu être si clairs" - Emmanuel Kant
    • "La simplicité est la sophistication suprême" - Léonard De Vinci
    • "Ce qui est facile à comprendre ou à faire pour toi, ne l'est pas forcément pour l'autre." - Mon pèrei

    Mes projets sur Github - Blog - Site DVP

  2. #2
    Membre éprouvé Avatar de der§en
    Homme Profil pro
    Chambord
    Inscrit en
    Septembre 2005
    Messages
    765
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Loir et Cher (Centre)

    Informations professionnelles :
    Activité : Chambord
    Secteur : Transports

    Informations forums :
    Inscription : Septembre 2005
    Messages : 765
    Points : 959
    Points
    959
    Par défaut
    Laisse-moi le temps d'analyser ton code, car je suis sur un truc un peu similaire mais pour générer des mondes aléatoires, tenant dans une matrice avec un ration de 2 largeur pour une hauteur.

    ET pour que la partie gauche colle parfaitement a la partie droite.

    J'ai une routine (avec basiquement un modulo) par contre en ce qui concerne les pôles, j'ai un autre calcul plus tortueux mais qui est cohérent sauf que j'e n'ai pas réussi a virer le - 1 dans le sens de la hauteur.

  3. #3
    Expert confirmé
    Avatar de BeanzMaster
    Homme Profil pro
    Amateur Passionné
    Inscrit en
    Septembre 2015
    Messages
    1 899
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Suisse

    Informations professionnelles :
    Activité : Amateur Passionné
    Secteur : Tourisme - Loisirs

    Informations forums :
    Inscription : Septembre 2015
    Messages : 1 899
    Points : 4 346
    Points
    4 346
    Billets dans le blog
    2
    Par défaut
    Salut merci, en attendant j'ai trouvé ça sur SO

    A+
    • "L'Homme devrait mettre autant d'ardeur à simplifier sa vie qu'il met à la compliquer" - Henri Bergson
    • "Bien des livres auraient été plus clairs s'ils n'avaient pas voulu être si clairs" - Emmanuel Kant
    • "La simplicité est la sophistication suprême" - Léonard De Vinci
    • "Ce qui est facile à comprendre ou à faire pour toi, ne l'est pas forcément pour l'autre." - Mon pèrei

    Mes projets sur Github - Blog - Site DVP

  4. #4
    Membre éprouvé Avatar de der§en
    Homme Profil pro
    Chambord
    Inscrit en
    Septembre 2005
    Messages
    765
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Loir et Cher (Centre)

    Informations professionnelles :
    Activité : Chambord
    Secteur : Transports

    Informations forums :
    Inscription : Septembre 2005
    Messages : 765
    Points : 959
    Points
    959
    Par défaut
    Voici ma routine spécifique pour contrôler la position dans mon algo Diamant-carré:

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
     
      function ControlePosition(const PT: TPoint): TPoint;
      begin
        Result := PT;
     
     
        if (PT.x < 0) or (PT.x >= TAILLEX) or (PT.y < 0) or (PT.y > TAILLEY) then
        begin
          // Contrôle de la latitude
          if Result.y < 0 then
          begin
            Result.y := Abs(Result.y);
            Result.x := Result.x + MILIEUX;
          end
          else if Result.y > TAILLEY then
          begin
            Result.y :=  TAILLEY - (Result.y - TAILLEY);
            Result.x := Result.x + MILIEUX;
          end;
     
     
          // Contrôle de la longitude.
          Result.x := (TAILLEX + Result.x) mod TAILLEX;
        end;
      end;

  5. #5
    Expert confirmé
    Avatar de BeanzMaster
    Homme Profil pro
    Amateur Passionné
    Inscrit en
    Septembre 2015
    Messages
    1 899
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Suisse

    Informations professionnelles :
    Activité : Amateur Passionné
    Secteur : Tourisme - Loisirs

    Informations forums :
    Inscription : Septembre 2015
    Messages : 1 899
    Points : 4 346
    Points
    4 346
    Billets dans le blog
    2
    Par défaut
    Yep,

    j'ai retranscrit le code du lien précédent. Son algorithme est astucieux, pas évident à se le représenter en tête. En gros il double virtuellement la taille des tuiles et prend par pas de 2 les valeurs. Ce qui rend que c'est possible le scrolling, c'est la génération "pseudo" aléatoire. Il serait d'ailleurs, assez facile je pense d'utiliser des algorithmes de bruit tel que perlin, simplex, value etc... pour générer des textures infinie.

    Voila le résultat de l'algo. (Désolé pour la résolution )


    Et voici le code complet de l'application. La seule partie que j'ai viré c'est justement la méthode de génération aléatoire (en effet, le code que j'ai retranscrit ne fonctionne pas, il retourne toujours le même résultat. Bref pas bien grave). Je l'ai donc remplacé par la mienne, provenant de mon unité BZNoiseGenerator.pas (que je dois d'ailleurs peaufiner)

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
    unit uMainForm;
     
    {$mode objfpc}{$H+}
     
    interface
     
    uses
      Classes, SysUtils, Forms, Controls, Graphics, Dialogs, ExtCtrls, StdCtrls,
      BZColors, BZGraphic, BZBitmap;
     
    Const
      { Nombre aléatoire premier pour l'axe des X }
      cX_PRIME = 1619;
      { Nombre aléatoire premier pour l'axe des Y }
      cY_PRIME = 31337;
      { Nombre aléatoire premier pour l'axe des Z }
      cZ_PRIME = 6971;
      { Nombre aléatoire premier pour l'axe des W }
      cW_PRIME = 1013;
      { Nombre aléatoire }
      cNOISE_SEED = 4679;
     
    type
     
      { TBZBitmapRenderFiltersHelper }
     
      TBZBitmapRenderFiltersHelper = class helper for TBZBitmapRenderFilters
      public
        procedure Plasma(Const MaxValue : Byte = 255; Const MapPalette : Boolean = False);
        procedure DiamondSquare(Const Seed : Longint = 123456; Const Roughtness : Integer = 64; Const FallOff : Single = 0.36);
     
        procedure InfiniteDiamondSquare(MoveX, MoveY : Integer; Const Iterations : Byte = 7; Const FallOff : Single = 0.36; Const Seed : Int64 = 1337);
      end;
     
      { TMainForm }
     
      TMainForm = class(TForm)
        pnlView: TPanel;
        Button1: TButton;
        Button2: TButton;
        sbRoughness: TScrollBar;
        sbFallOff: TScrollBar;
        sbMoveX: TScrollBar;
        sbMoveY: TScrollBar;
        chkDSInfinite: TCheckBox;
        chkBlur: TCheckBox;
        Label1: TLabel;
        Label2: TLabel;
        lblRoughness: TLabel;
        lblFallOff: TLabel;
        procedure FormCreate(Sender: TObject);
        procedure FormClose(Sender: TObject; var CloseAction: TCloseAction);
        procedure pnlViewPaint(Sender: TObject);
        procedure Button1Click(Sender: TObject);
        procedure Button2Click(Sender: TObject);
        procedure sbRoughnessChange(Sender: TObject);
        procedure sbMoveXChange(Sender: TObject);
        procedure sbFallOffChange(Sender: TObject);
      private
      protected
        FTexture : TBZBitmap;
        FMoveX, FMoveY : Integer;
      public
     
      end;
     
    var
      MainForm: TMainForm;
     
    implementation
     
    {$R *.lfm}
     
    uses Math, BZMath, BZArrayClasses, BZLogger,  BZTypesHelpers;
     
    { TMainForm }
     
    procedure TMainForm.FormCreate(Sender: TObject);
    begin
      FTexture := TBZBitmap.Create(512,512);
      FMoveX := 0;
      FMoveY := 0;
    end;
     
    procedure TMainForm.FormClose(Sender: TObject; var CloseAction: TCloseAction);
    begin
      FreeAndNil(FTexture);
    end;
     
    procedure TMainForm.pnlViewPaint(Sender: TObject);
    begin
      if Assigned(FTexture) then FTexture.DrawToCanvas(pnlView.Canvas, pnlView.ClientRect);
    end;
     
    procedure TMainForm.Button1Click(Sender: TObject);
    begin
      FTexture.RenderFilter.Plasma();
      pnlView.Invalidate;
    end;
     
    procedure TMainForm.Button2Click(Sender: TObject);
    begin
      if chkDSInfinite.Checked then
      begin
        FMoveX := sbMoveX.Position;
        FMoveY := sbMoveY.Position;
        FTexture.RenderFilter.InfiniteDiamondSquare(FMoveX, FMoveY, min(sbRoughNess.Position,24), (sbFallOff.Position / 100));
      end
      else
        FTexture.RenderFilter.DiamondSquare(123456, sbRoughness.Position, (sbFallOff.Position / 100));
     
      if chkBlur.Checked then FTexture.BlurFilter.BoxBlur(2);
     
      pnlView.Invalidate;
    end;
     
    procedure TMainForm.sbRoughnessChange(Sender: TObject);
    begin
      lblRoughness.Caption := sbRoughness.Position.ToString;
      Button2Click(self);
    end;
     
    procedure TMainForm.sbMoveXChange(Sender: TObject);
    begin
      Button2Click(self);
    end;
     
    procedure TMainForm.sbFallOffChange(Sender: TObject);
    Var
     d : Single;
    begin
      d := sbFallOff.Position / 100;
      lblFallOff.Caption := d.ToString(2);
      Button2Click(self);
    end;
     
    { TBZBitmapRenderFiltersHelper }
     
    procedure TBZBitmapRenderFiltersHelper.Plasma(Const MaxValue: Byte; Const MapPalette: Boolean);
    Var
       Level : Integer;
       xmax, ymax, randValue :integer;
       RndColor : TBZColor;
     
      function adjust(xa,ya,x,y,xb,yb:integer): TBZColor;
      var
        rand : Integer;
        SrcColorA, SrcColorB, DstColor : TBZColor;
      begin
         rand := random(MaxValue) shr level;
         if (random(2)=0) then rand := -rand;
         SrcColorA := OwnerBitmap.getPixel(xa,ya);
         SrcColorB := OwnerBitmap.getPixel(xb,yb);
         DstColor := SrcColorA.Average(SrcColorB);
     
         DstColor.Red := ClampByte(DstColor.Red + Rand);
         DstColor.Green := ClampByte(DstColor.Green + Rand);
         DstColor.Blue := ClampByte(DstColor.Blue + Rand);
     
         OwnerBitmap.setPixel(X,Y, DstColor);
         result := DstColor;
      end;
     
      procedure Divide(x1,y1,x2,y2:Integer);
      var
        x, y, sr, sg,sb, sa : integer;
        AColor, DstColor : TBZColor;
      begin
         //Level :=0;
         sr := 0;
         sg := 0;
         sb := 0;
         sa := 0;
         if ((x2-x1<2) and (y2-y1<2)) then exit;
     
         inc(level);
         x:=((x1+x2) shr 1);
         y:=((y1+y2) shr 1);
     
         AColor := OwnerBitmap.getPixel(x,y1);
         if (AColor = clrBlack) or (AColor = clrTransparent) then AColor := adjust(x1,y1,x,y1,x2,y1);
     
         sr := AColor.Red;
         sg := AColor.Green;
         sb := AColor.Blue;
         sa := AColor.Alpha;
     
         AColor := OwnerBitmap.getPixel(x2,y);
         if (AColor = clrBlack) or (AColor = clrTransparent) then AColor := adjust(x2,y1,x2,y,x2,y2);
     
         sr := sr + AColor.Red;
         sg := sg + AColor.Green;
         sb := sb + AColor.Blue;
         sa := sa + AColor.Alpha;
     
         AColor := OwnerBitmap.getPixel(x,y2);
         if (AColor = clrBlack) or (AColor = clrTransparent) then AColor := adjust(x1,y2,x,y2,x2,y2);
     
         sr := sr + AColor.Red;
         sg := sg + AColor.Green;
         sb := sb + AColor.Blue;
         sa := sa + AColor.Alpha;
     
         AColor := OwnerBitmap.getPixel(x1,y);
         if (AColor = clrBlack) or (AColor = clrTransparent) then AColor := adjust(x1,y1,x1,y,x1,y2);
     
         sr := sr + AColor.Red;
         sg := sg + AColor.Green;
         sb := sb + AColor.Blue;
         sa := sa + AColor.Alpha;
     
         AColor := OwnerBitmap.getPixel(x,y);
         if (AColor = clrBlack) or (AColor = clrTransparent) then
         begin
           sr := sr + 2;
           sg := sg + 2;
           sb := sb + 2;
           sa := sa + 2;
           DstColor.Create((sr shr 2), (sg shr 2), (sb shr 2), (sa shr 2));
           OwnerBitmap.setPixel(x,y, DstColor);
         end;
     
         Divide(x1,y1,x,y);
         Divide(x,y1,x2,y);
         Divide(x,y,x2,y2);
         Divide(x1,y,x,y2);
         dec(level)
      end;
     
    begin
       OwnerBitmap.Clear(clrBlack);
       Randomize;
       xmax := OwnerBitmap.MaxWidth;//((x2-x1) div 2)-1;
       ymax := OwnerBitmap.MaxHeight;//((y2-y1) div 2)-1;
     
       randValue := random(MaxValue);
       RndColor.Create(RandValue, RandValue, RandValue);
       OwnerBitmap.setPixel(0,0, RndColor);
       //randValue := random(MaxValue);
       //RndColor.Create(RandValue, RandValue, RandValue);
       OwnerBitmap.setPixel(xmax,0, RndColor);
       //randValue := random(MaxValue);
       //RndColor.Create(RandValue, RandValue, RandValue);
       OwnerBitmap.setPixel(0,ymax, RndColor);
       //randValue := random(MaxValue);
       //RndColor.Create(RandValue, RandValue, RandValue);
       OwnerBitmap.setPixel(xmax,ymax, RndColor);
     
       level := 0;
       divide(0, 0, xmax, ymax);
    end;
     
     
    { https://fr.wikipedia.org/wiki/Algorithme_Diamant-Carré
      https://yahiko.developpez.com/tutoriels/heightmap/
      https://hiko-seijuro.developpez.com/articles/diamond-square/
      https://stackoverflow.com/questions/2755750/diamond-square-algorithm
      https://learn.64bitdragon.com/articles/computer-science/procedural-generation/the-diamond-square-algorithm }
    procedure TBZBitmapRenderFiltersHelper.DiamondSquare(Const Seed: Longint; Const Roughtness: Integer; Const FallOff: Single);
    Var
      TileSize, TileSizeW, TileSizeH, RandValue, rand, HalfSize : Integer;
      xx, yy, xmax, ymax : integer;
      AColor, AColorSum : TBZColorVector;
      NeedResize : Boolean;
      DstColor : TBZColor;
    begin
       // Ajustement des dimensions du bitmap si elles ne sont pas de l'ordre de 2n + 1
      NeedResize := False;
      xMax := OwnerBitmap.Width;
      yMax := OwnerBitmap.Height;
      if xMax.IsPowerOfTwo then
      begin
        xMax := xMax + 1;
        NeedResize := True;
      end;
      if yMax.IsPowerOfTwo then
      begin
        yMax := yMax + 1;
        NeedResize := True;
      end;
      if NeedResize then OwnerBitmap.SetSize(xMax, yMax);
     
      OwnerBitmap.Clear(clrBlack);
      //Randomize;
      RandSeed := Seed;
     
      xmax := OwnerBitmap.MaxWidth;//((x2-x1) div 2)-1;
      ymax := OwnerBitmap.MaxHeight;//((y2-y1) div 2)-1;
     
      randValue := random(256);
      DstColor.Create(RandValue, RandValue, RandValue);
      OwnerBitmap.setPixel(0,0, DstColor);
      randValue := random(256);
      DstColor.Create(RandValue, RandValue, RandValue);
      OwnerBitmap.setPixel(xmax,0, DstColor);
      randValue := random(256);
      DstColor.Create(RandValue, RandValue, RandValue);
      OwnerBitmap.setPixel(0,ymax, DstColor);
      randValue := random(256);
      DstColor.Create(RandValue, RandValue, RandValue);
      OwnerBitmap.setPixel(xmax,ymax, DstColor);
     
      TileSizeW := xmax;
      TileSizeH := ymax;
      TileSize := TileSizeW;
      TileSize:= Max(TileSizeW, TileSizeH);
      RandValue := Roughtness;
      While TileSize > 1 do
      begin
        HalfSize :=  TileSize div 2; //((TileSize + 1) div 2) - 1;
     
        // Square
        xx := 0;
        While (xx < OwnerBitmap.Width) do
        begin
          yy := 0;
          While (yy < OwnerBitmap.Height) do
          begin
            AColorSum := ClrTransparent.AsColorVector;
     
            AColor := OwnerBitmap.getPixel(xx, yy).AsColorVector;
            AColorSum :=  AColorSum + AColor;
     
            AColor := OwnerBitmap.getPixel(xx + TileSize, yy).AsColorVector;
            AColorSum :=  AColorSum + AColor;
     
            AColor := OwnerBitmap.getPixel(xx, yy + TileSize).AsColorVector;
            AColorSum :=  AColorSum + AColor;
     
            AColor := OwnerBitmap.getPixel(xx + TileSize, yy + TileSize).AsColorVector;
            AColorSum :=  AColorSum + AColor;
     
            AColorSum :=  AColorSum * 0.25;
     
            Rand := Integer.RandomRange(-RandValue, RandValue);
            AColor.Create(Rand * _FloatColorRatio);
            AColorSum :=  AColorSum + AColor;
     
            DstColor.Create(AColorSum);
            OwnerBitmap.setPixel(xx + HalfSize, yy + HalfSize, DstColor);
     
     
            yy := yy + TileSize;
          end;
          xx := xx + TileSize;
        end;
     
        // Diamond
        xx := 0;
        While (xx < OwnerBitmap.Width) do
        begin
          yy := (xx + HalfSize) mod TileSize;
     
          While (yy < OwnerBitmap.Height) do
          begin
            AColorSum := ClrTransparent.AsColorVector;
     
            AColor := OwnerBitmap.getPixel((xx - halfSize + xmax) mod xmax, yy).AsColorVector;
            AColorSum :=  AColorSum + AColor;
     
            AColor := OwnerBitmap.getPixel((xx + halfSize) mod xmax, yy).AsColorVector;
            AColorSum :=  AColorSum + AColor;
     
            AColor := OwnerBitmap.getPixel(xx, (yy + halfSize) mod ymax).AsColorVector;
            AColorSum :=  AColorSum + AColor;
     
            AColor := OwnerBitmap.getPixel(xx, (yy - halfSize + ymax) mod ymax).AsColorVector;
            AColorSum :=  AColorSum + AColor;
     
            AColorSum :=  AColorSum * 0.25;
     
            Rand := Integer.RandomRange(-RandValue, RandValue);
            AColor.Create(Rand * _FloatColorRatio);
            AColorSum :=  AColorSum + AColor;
     
            DstColor.Create(AColorSum);
            OwnerBitmap.setPixel(xx, yy, DstColor);
     
            if (xx = 0) then OwnerBitmap.setPixel(xmax, yy, DstColor);
            if (yy = 0) then OwnerBitmap.setPixel(xx, ymax, DstColor);
     
            yy := yy + TileSize;
          end;
          xx := xx + HalfSize;
        end;
     
        //RandValue := (RandValue div 2) + 1;
        Randvalue := RandValue - Round((RandValue * 0.5) * FallOff);
        TileSize := TileSize div 2;
      end;
    end;
     
    procedure TBZBitmapRenderFiltersHelper.InfiniteDiamondSquare(MoveX, MoveY: Integer; Const Iterations: Byte; Const FallOff: Single; Const Seed: Int64);
    Var
     DSMap : TBZSingle2DMap;
     
      function getDiamondSquareMap : TBZSingle2DMap;
      Var
        MaxDeviation : Single;
        ResultMap : TBZSingle2DMap;
        ix, iy : integer;
     
        function ComputeMaxDeviation(Iters : Byte) : Single;
        Var
          Dev : Single;
        begin
          dev := 0.5 / (iters+1);
          if (iters <= 0) then Result := dev
          else result := ComputeMaxDeviation(iters-1) + dev;
        end;
     
        Function RandUniform3D(x,y,z : Double): Double;
        Var
          n : Integer;
        begin
          n := Round(cX_PRIME * x + cY_PRIME * y + cZ_PRIME * z + cNOISE_SEED * Seed) and $7fffffff;
          n := (n shr 13) xor n;
          Result := 1.0 - (((n * (n * n * 60493 + 19990303) + 1376312589) and $7fffffff) / 1073741824.0);
        end;
     
        //function PseudoRandomHash(x, y : Integer; Iters : Byte): Single;
        //var
        //  Hash, ite, vx, vy, rem, h : Int64;
        //begin
        //  vx := x and $FFF;
        //  vy := y and $FFF;
        //  ite := Iters and $FF;
        //  Hash := (ite shl 24);
        //  Hash := Hash or (vy shl 12);
        //  Hash := Hash or vx;
        //  rem := Hash and 3;
        //  h := Hash;
        //
        //  Case rem of
        //    1:
        //    begin
        //      Hash := Hash + h;
        //      Hash := round(Math.intpower(Hash, (Hash shl 20)));
        //      Hash := Hash + (Hash shr 2);
        //    end;
        //    2:
        //    begin
        //      Hash := Hash + h;
        //      Hash := round(Math.intpower(Hash, (Hash shl 22)));
        //      Hash := Hash + (Hash shr 34);
        //    end;
        //    3:
        //    begin
        //      Hash := Hash + h;
        //      hash := round(Math.intpower(Hash, (Hash shl 32)));
        //      hash := round(Math.intpower(Hash, (h shl 36)));
        //      Hash := Hash + (Hash shr 22);
        //    end;
        //  end;
        //
        //  Hash := round(Math.intpower(Hash, (Hash shl 6)));
        //  Hash := Hash + (Hash shr 10);
        //  Hash := round(Math.intpower(Hash, (Hash shl 8)));
        //  Hash := Hash + (Hash shr 34);
        //  hash := round(Math.intpower(Hash, (Hash shl 50)));
        //  Hash := Hash + (Hash shr 12);
        //
        //  Result := (Hash and $FFFF) / $FFFF;
        //  GlobalLogger.LogStatus('PRH = ' + Result.ToString);
        //end;
     
        function DisplaceMap(Iter : Byte; x, y : Integer) : Single;
        begin
          //Result := (((PseudoRandomHash(Iter,x,y) - 0.5) * 2)) / (Iter + 1);
          //Result := ((RandUniform3D(x, y, Iter) - 0.5) * 2) / (Iter + 1);
          Result := ((RandUniform3D(x, y, Iter) - 0.5) * FallOff) / (Iter + 1);
        end;
     
        function ComputeDiamondSquareMap(x0, y0, x1, y1 : Integer; Iter : Byte) : TBZSingle2DMap;
        Var
          UpperMap, CurrentMap, FinalMap : TBZSingle2DMap;
          FinalWidth, FinalHeight : Integer;
          ux0, uy0, ux1, uy1, uw, uh, cw, ch, cx0, cy0, xoff, yoff, j, k : Integer;
     
        begin
          if (x1 < x0) then exit;
          if (y1 < y0) then exit;
          FinalWidth  := x1 - x0;
          FinalHeight := y1 - y0;
          FinalMap := TBZSingle2DMap.Create(FinalWidth, FinalHeight);
     
          if (Iter = 0) then
          begin
            for j := 0 to (FinalWidth-1) do
            begin
              for k := 0 to (FinalHeight-1) do
              begin
                FinalMap.Items[j,k] :=  DisplaceMap(Iter, x0 + j, y0 + k) ;
              end;
            end;
            Result := FinalMap;
            Exit;
          end;
     
          ux0 := Math.floor(x0 * 0.5) - 1;
          uy0 := Math.floor(y0 * 0.5) - 1;
          ux1 := Math.ceil(x1 * 0.5) + 1;
          uy1 := Math.ceil(y1 * 0.5) + 1;
     
          UpperMap := ComputeDiamondSquareMap(ux0, uy0, ux1, uy1, Iter - 1);
     
          uw := ux1 - ux0;
          uh := uy1 - uy0;
     
          cx0 := ux0 + ux0; //ux0 * 2;
          cy0 := uy0 + uy0; //uy0 * 2;
     
          cw := (uw + uw) - 1; //uw * 2 -1;
          ch := (uh + uh) - 1; //uh * 2 -1;
     
          CurrentMap := TBZSingle2DMap.Create(cw,ch);
     
          for j := 0 to (uw - 1) do
          begin
            for k := 0 to (uh - 1) do
            begin
              CurrentMap.Items[j + j, k + k] := UpperMap.Items[j, k];
            end;
          end;
     
          FreeAndNil(UpperMap);
          xoff := x0 - cx0;
          yoff := y0 - cy0;
     
          j := 1;
          While (j < (cw-1)) do
          begin
            k := 1;
            While (k < (ch - 1)) do
            begin
              CurrentMap.Items[j, k] := ((CurrentMap.Items[j - 1, k - 1] +
                                          CurrentMap.Items[j - 1, k + 1] +
                                          CurrentMap.Items[j + 1, k - 1] +
                                          CurrentMap.Items[j + 1, k + 1]) * 0.25) +
                                          DisplaceMap(Iter, cx0 + j, cy0 + k);
              k := k + 2;
            end;
            j := j + 2;
          end;
     
          j := 1;
          While (j < (cw-1)) do
          begin
            k := 2;
            While (k < (ch - 1)) do
            begin
              CurrentMap.Items[j, k] := ((CurrentMap.Items[j - 1, k] +
                                          CurrentMap.Items[j + 1, k] +
                                          CurrentMap.Items[j, k - 1] +
                                          CurrentMap.Items[j, k + 1]) * 0.25) +
                                          DisplaceMap(Iter, cx0 + j, cy0 + k);
              k := k + 2;
            end;
            j := j + 2;
          end;
     
          j := 2;
          While (j < (cw-1)) do
          begin
            k := 1;
            While (k < (ch - 1)) do
            begin
              CurrentMap.Items[j, k] := ((CurrentMap.Items[j - 1, k] +
                                          CurrentMap.Items[j + 1, k] +
                                          CurrentMap.Items[j, k - 1] +
                                          CurrentMap.Items[j, k + 1]) * 0.25) +
                                          DisplaceMap(Iter, cx0 + j, cy0 + k);
              k := k + 2;
            end;
            j := j + 2;
          end;
     
          for j := 0 to (FinalWidth - 1) do
          begin
            for k := 0 to (FinalHeight - 1) do
            begin
              FinalMap.Items[j, k] := CurrentMap.Items[j + xoff, k + yoff];
            end;
          end;
     
          FreeAndNil(CurrentMap);
          Result := FinalMap;
        end;
     
      begin
        ResultMap := ComputeDiamondSquareMap(MoveX, MoveY, MoveX + OwnerBitmap.Width, MoveY + OwnerBitmap.Height, Iterations);
     
        MaxDeviation := 1/ComputeMaxDeviation(Iterations);
     
        for ix := 0 to OwnerBitmap.MaxWidth do
        begin
          for iy := 0 to OwnerBitmap.MaxHeight do
          begin
            ResultMap.Items[ix, iy] := ResultMap.Items[ix, iy] * MaxDeviation;
            ResultMap.Items[ix, iy] := Clamp(((ResultMap.Items[ix, iy] + 1) * 0.5), -1.0, 1.0);
          end;
        end;
     
        Result := ResultMap;
      end;
     
      procedure RenderMap(Map : TBZSingle2DMap);
      Var
        ix, iy : Integer;
        lum : Byte;
        f : Single;
        DstColor : TBZColor;
      begin
        for ix := 0 to OwnerBitmap.MaxWidth do
        begin
          for iy := 0 to OwnerBitmap.MaxHeight do
          begin
             f := Map.Items[ix, iy];
             //GlobalLogger.LogStatus('f = ' + f.ToString);
             f := RangeMap(f,-1.0,1.0,0,255);
             lum := Round(f);
             DstColor.Create(lum, lum, lum);
             OwnerBitmap.setPixel(ix, iy, DstColor);
          end;
        end;
      end;
     
    begin
      DSMap := getDiamondSquareMap;
      if Assigned(DSMap) then
      begin
        RenderMap(DSMap);
        FreeAndNil(DSMap);
      end;
    end;
     
    end.
    Ceci étant fait j'aimerai quand même trouver la solution à ma petite question (je crois avoir une idée, de comment )

    A+

    Jérôme
    • "L'Homme devrait mettre autant d'ardeur à simplifier sa vie qu'il met à la compliquer" - Henri Bergson
    • "Bien des livres auraient été plus clairs s'ils n'avaient pas voulu être si clairs" - Emmanuel Kant
    • "La simplicité est la sophistication suprême" - Léonard De Vinci
    • "Ce qui est facile à comprendre ou à faire pour toi, ne l'est pas forcément pour l'autre." - Mon pèrei

    Mes projets sur Github - Blog - Site DVP

  6. #6
    Expert confirmé
    Avatar de BeanzMaster
    Homme Profil pro
    Amateur Passionné
    Inscrit en
    Septembre 2015
    Messages
    1 899
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Suisse

    Informations professionnelles :
    Activité : Amateur Passionné
    Secteur : Tourisme - Loisirs

    Informations forums :
    Inscription : Septembre 2015
    Messages : 1 899
    Points : 4 346
    Points
    4 346
    Billets dans le blog
    2
    Par défaut
    Citation Envoyé par der§en Voir le message
    Voici ma routine spécifique pour contrôler la position dans mon algo Diamant-carré:
    Ok, merci, je vais jeter un oeil
    • "L'Homme devrait mettre autant d'ardeur à simplifier sa vie qu'il met à la compliquer" - Henri Bergson
    • "Bien des livres auraient été plus clairs s'ils n'avaient pas voulu être si clairs" - Emmanuel Kant
    • "La simplicité est la sophistication suprême" - Léonard De Vinci
    • "Ce qui est facile à comprendre ou à faire pour toi, ne l'est pas forcément pour l'autre." - Mon pèrei

    Mes projets sur Github - Blog - Site DVP

  7. #7
    Membre éprouvé Avatar de der§en
    Homme Profil pro
    Chambord
    Inscrit en
    Septembre 2005
    Messages
    765
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Loir et Cher (Centre)

    Informations professionnelles :
    Activité : Chambord
    Secteur : Transports

    Informations forums :
    Inscription : Septembre 2005
    Messages : 765
    Points : 959
    Points
    959
    Par défaut
    Dans ta vidéo, il me semble voir des artefacts.

  8. #8
    Expert confirmé
    Avatar de BeanzMaster
    Homme Profil pro
    Amateur Passionné
    Inscrit en
    Septembre 2015
    Messages
    1 899
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Suisse

    Informations professionnelles :
    Activité : Amateur Passionné
    Secteur : Tourisme - Loisirs

    Informations forums :
    Inscription : Septembre 2015
    Messages : 1 899
    Points : 4 346
    Points
    4 346
    Billets dans le blog
    2
    Par défaut
    Citation Envoyé par der§en Voir le message
    Dans ta vidéo, il me semble voir des artefacts.
    Surement a cause de la vitesse de déplacement et peut-être de la compression video.

    Ci-Joint l’exécutable pour Windows 64 bits pour tester
    Fichiers attachés Fichiers attachés
    • "L'Homme devrait mettre autant d'ardeur à simplifier sa vie qu'il met à la compliquer" - Henri Bergson
    • "Bien des livres auraient été plus clairs s'ils n'avaient pas voulu être si clairs" - Emmanuel Kant
    • "La simplicité est la sophistication suprême" - Léonard De Vinci
    • "Ce qui est facile à comprendre ou à faire pour toi, ne l'est pas forcément pour l'autre." - Mon pèrei

    Mes projets sur Github - Blog - Site DVP

  9. #9
    Membre éprouvé Avatar de der§en
    Homme Profil pro
    Chambord
    Inscrit en
    Septembre 2005
    Messages
    765
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Loir et Cher (Centre)

    Informations professionnelles :
    Activité : Chambord
    Secteur : Transports

    Informations forums :
    Inscription : Septembre 2005
    Messages : 765
    Points : 959
    Points
    959
    Par défaut
    Sinon, dans le paquet GLSCeneLCL, tu trouves plusieurs exemples d'utilisation du diamant-carré dans : GLSceneLCL -> Example -> terrain -> LandscapePackage : https://sourceforge.net/p/glscene/co...dscapePackage/

  10. #10
    Membre éprouvé Avatar de der§en
    Homme Profil pro
    Chambord
    Inscrit en
    Septembre 2005
    Messages
    765
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Loir et Cher (Centre)

    Informations professionnelles :
    Activité : Chambord
    Secteur : Transports

    Informations forums :
    Inscription : Septembre 2005
    Messages : 765
    Points : 959
    Points
    959
    Par défaut
    Sinon, en son temps, j'avais commit cela : http://antre.dergen.fr/generateur-de-textures/ si cela peux t'aider...

  11. #11
    Expert confirmé
    Avatar de BeanzMaster
    Homme Profil pro
    Amateur Passionné
    Inscrit en
    Septembre 2015
    Messages
    1 899
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Suisse

    Informations professionnelles :
    Activité : Amateur Passionné
    Secteur : Tourisme - Loisirs

    Informations forums :
    Inscription : Septembre 2015
    Messages : 1 899
    Points : 4 346
    Points
    4 346
    Billets dans le blog
    2
    Par défaut
    Citation Envoyé par der§en Voir le message
    Sinon, dans le paquet GLSCeneLCL, tu trouves plusieurs exemples d'utilisation du diamant-carré dans : GLSceneLCL -> Example -> terrain -> LandscapePackage : https://sourceforge.net/p/glscene/co...dscapePackage/
    A ben je les avait oublié ceux-la

    Citation Envoyé par der§en Voir le message
    Sinon, en son temps, j'avais commit cela : http://antre.dergen.fr/generateur-de-textures/ si cela peux t'aider...
    Ok, je vais jeter un oeil.

    Merci
    • "L'Homme devrait mettre autant d'ardeur à simplifier sa vie qu'il met à la compliquer" - Henri Bergson
    • "Bien des livres auraient été plus clairs s'ils n'avaient pas voulu être si clairs" - Emmanuel Kant
    • "La simplicité est la sophistication suprême" - Léonard De Vinci
    • "Ce qui est facile à comprendre ou à faire pour toi, ne l'est pas forcément pour l'autre." - Mon pèrei

    Mes projets sur Github - Blog - Site DVP

  12. #12
    Expert confirmé

    Homme Profil pro
    Directeur de projet
    Inscrit en
    Mai 2013
    Messages
    1 330
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Yvelines (Île de France)

    Informations professionnelles :
    Activité : Directeur de projet
    Secteur : Service public

    Informations forums :
    Inscription : Mai 2013
    Messages : 1 330
    Points : 4 148
    Points
    4 148
    Par défaut Modulo
    Bonjour Jérôme,

    Citation Envoyé par BeanzMaster Voir le message
    Ma question. Comment adapter, modifier l'algorithme pour qu'il accepte une matrice carrée de taille 2n ?
    Travailler avec des carrés de 2n peut se simplifier en considérant que le carré est une sphère (oui c'est tordu surtout dans les coins ).

    En appliquant systématiquement un modulo 2n (c'est à dire un simple and 2n-1), l'algorithme pour des carrés 2n + 1 fonctionne avec très peu de modifications :
    • les quatre points d'initialisation deviennent un seul.
    • les contrôles aux limites disparaissent (le modulo ramène toujours dans les limites si on évite les soustractions : a - u remplacée classiquement par (a + 2n - u) and (2n-1) ).
    • les moyennes sont toujours sur 4 points (adieu les divisions)
    • Il y a quand même un effet qui peut être indésirable : le relief boucle, il y a continuité entre droite et gauche, haut et bas. Mais cet effet peut aussi être recherché.


    Cela fonctionne aussi pour des rectangles dont les cotés sont 2^n et 2^m mais au prix de modifications du code d'origine (création de variables pour chacun des axes).

    Salutations
    Ever tried. Ever failed. No matter. Try Again. Fail again. Fail better. (Samuel Beckett)

  13. #13
    Membre éprouvé Avatar de der§en
    Homme Profil pro
    Chambord
    Inscrit en
    Septembre 2005
    Messages
    765
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Loir et Cher (Centre)

    Informations professionnelles :
    Activité : Chambord
    Secteur : Transports

    Informations forums :
    Inscription : Septembre 2005
    Messages : 765
    Points : 959
    Points
    959
    Par défaut
    Si tu pars sur une logique de sphère, alors, je pense que ma routine CONTROLEPOSITION est le bonne algo avec un modulo pour les longitudes et un décalage de 180 degrés pour les latitudes (pour prendre la bonne position de l’autre côté du pôle).

  14. #14
    Expert confirmé

    Homme Profil pro
    Directeur de projet
    Inscrit en
    Mai 2013
    Messages
    1 330
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Yvelines (Île de France)

    Informations professionnelles :
    Activité : Directeur de projet
    Secteur : Service public

    Informations forums :
    Inscription : Mai 2013
    Messages : 1 330
    Points : 4 148
    Points
    4 148
    Par défaut
    Bonjour DerGen,

    Citation Envoyé par der§en Voir le message
    Si tu pars sur une logique de sphère, alors, je pense que ma routine CONTROLEPOSITION est le bonne algo avec un modulo pour les longitudes et un décalage de 180 degrés pour les latitudes (pour prendre la bonne position de l’autre côté du pôle).
    Le problème est que ma "sphère" ressemble plutôt à ça :
    Nom : Cube sphérique.png
Affichages : 393
Taille : 159,6 Ko

    C'est plutôt rapide mais cela ne respecte pas les projections d'un plan sur une sphère comme tu le souhaites.

    Salut
    Ever tried. Ever failed. No matter. Try Again. Fail again. Fail better. (Samuel Beckett)

Discussions similaires

  1. Algorithme Diamond Square
    Par mazertys17 dans le forum Général Java
    Réponses: 26
    Dernier message: 29/07/2016, 22h37
  2. Algorithme Diamond Square
    Par mazertys17 dans le forum Général Java
    Réponses: 0
    Dernier message: 09/07/2016, 15h57
  3. Algorithme de génération de textures.
    Par Disciple195 dans le forum SDL
    Réponses: 2
    Dernier message: 18/06/2007, 20h16
  4. recherche algo de génération de nombre aléatoire
    Par Pascale38 dans le forum MFC
    Réponses: 2
    Dernier message: 26/01/2004, 14h20

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo