FastNoise-SIMD icon indicating copy to clipboard operation
FastNoise-SIMD copied to clipboard

Artefacts in noise values.

Open stolk opened this issue 5 years ago • 1 comments

I am seeing artefacts in the noise values.

Am I using the library wrong? I tried clang and gcc, with same results.

image

This is the code:

#include "FastNoise3d.h"

#include <stdlib.h>
#include <assert.h>
#include <stdio.h>

#include <immintrin.h>


#if defined( MSWIN )
#       define ALIGNEDPRE __declspec(align(32))
#       define ALIGNEDPST
#else
#       define ALIGNEDPRE
#       define ALIGNEDPST __attribute__ ((aligned (32)))
#endif


int main(int argc, char* argv[])
{
	if ( argc != 3 )
	{
		fprintf( stderr, "Usage: %s size file.pgm\n", argv[0] );
		exit(1);
	}
	const int sz = atoi( argv[1] );
	const char* oname = argv[2];

	FILE* f = fopen( oname, "wb" );
	assert( f );

	initSIMDSimplex();	// NOTE: I've added the constant initialization to this func.

	uint8_t* im = (uint8_t*)malloc( sz * sz );
	uint8_t* writer = im;
	for (int y=0; y<sz; ++y)
	{
		__m256 y8 = _mm256_set1_ps( y );
		for (int x=0; x<sz; x+=8)
		{
			__m256 x8 = _mm256_setr_ps(0,1,2,3,4,5,6,7);
			x8 = _mm256_add_ps( x8, _mm256_set1_ps(x) );
			__m256 z8 = _mm256_set1_ps(1.0f);
			__m256 v8 = simplexSIMD3d
			(
				_mm256_mul_ps( x8, _mm256_set1_ps(0.01f) ),
				_mm256_mul_ps( y8, _mm256_set1_ps(0.01f) ),
				z8
			);
			ALIGNEDPRE float vals[8] ALIGNEDPST;
			_mm256_store_ps( vals, v8 );
			for ( int i=0; i<8; ++i )
				*writer++ = (uint8_t) ( 127 * ( vals[i] + 1.0f ) );
		}
	}

	fprintf( f, "P5\n%d %d\n255\n", sz, sz );
	fwrite( im, sz*sz, 1, f );

	fclose(f);

	return 0;
}

Note: I've slightly modified the library code (made it C-API, and added constant init to initSIMDSimplex() as I only need that call.

stolk avatar May 08 '20 02:05 stolk

It turns out that it sometimes returns values well outside the -1 .. 1 range?

stolk avatar May 08 '20 02:05 stolk