FastNoise2 icon indicating copy to clipboard operation
FastNoise2 copied to clipboard

Add strided generators

Open nolankramer opened this issue 1 year ago • 5 comments

This PR adds strided generators, for generating noise corresponding to pre-made spatial points.

nolankramer avatar Mar 21 '25 23:03 nolankramer

I modified FastNoiseCpp11Include test temporarily, and tested with a 4x4 position grid:

0,0: 0 vs 0
1,0: -0.209467 vs 0.125916
2,0: 0.424659 vs -0.209467
3,0: -0.15126 vs -0.220221
0,1: 0.125916 vs 0.424659
1,1: 0.327784 vs 0.000303611
2,1: 0.019688 vs -0.15126
3,1: -0.0671406 vs 0
0,2: -0.220221 vs -0.220221
1,2: 0.22565 vs 0.019688
2,2: 0.305475 vs 0.22565
3,2: 0.0472323 vs 0.305475
0,3: 0.000303611 vs 0.305475
1,3: 0.0469043 vs -0.091646
2,3: -0.091646 vs 0.0472323
3,3: 0.0466066 vs 0.424659

where the left column values are generated with GenUniformGrid2D and the right with GenStridedArray2D. They are indeed different at some indices, and I'm not sure why. Here are the calls:

FastNoise::Generator::Vector2 posArray[size * size];
    for( int y = 0; y < size; y++ )
    {
        for( int x = 0; x < size; x++ )
        {
            posArray[y * size + x].x = (float)x;
            posArray[y * size + x].y = (float)y;
        }
    } 

node->GenUniformGrid2D( noise, 0, 0, size, size, 1.0f, 1337 );
node->GenStridedArray2D( noise2, size * size, posArray, 1337 );

nolankramer avatar Mar 21 '25 23:03 nolankramer

Oh, I see the issue now. Load_f32 is assuming contiguous values, and we need to gather instead of load

nolankramer avatar Mar 22 '25 00:03 nolankramer

I've updated the code to add a FS_Gather_f32, and it is now producing expected results:

256
0,0: 0 vs 0
1,0: -0.209467 vs -0.209467
2,0: 0.424659 vs 0.424659
3,0: -0.15126 vs -0.15126
0,1: 0.125916 vs 0.125916
1,1: 0.327784 vs 0.327784
2,1: 0.019688 vs 0.019688
3,1: -0.0671406 vs -0.0671406
0,2: -0.220221 vs -0.220221
1,2: 0.22565 vs 0.22565
2,2: 0.305475 vs 0.305475
3,2: 0.0472323 vs 0.0472323
0,3: 0.000303611 vs 0.000303611
1,3: 0.0469043 vs 0.0469043
2,3: -0.091646 vs -0.091646
3,3: 0.0466066 vs 0.0466066

I can only test on Win32 with AVX2, and this likely needs to be tested elsewhere

nolankramer avatar Mar 22 '25 01:03 nolankramer

Thanks, I don't think I will pull this into the current main branch. I'm working on the 1.0 release in the NewFastSIMD branch which hopefully can be released soon. So I will look to integrate it into there

Auburn avatar Mar 26 '25 23:03 Auburn

Thanks, I don't think I will pull this into the current main branch. I'm working on the 1.0 release in the NewFastSIMD branch which hopefully can be released soon. So I will look to integrate it into there

SGTM 👍

nolankramer avatar Mar 27 '25 02:03 nolankramer