Giter VIP home page Giter VIP logo

fastnoise-simd's People

Contributors

jackmott avatar stolk avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

fastnoise-simd's Issues

Artefacts in noise values.

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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.