Skip to content
This repository has been archived by the owner on Oct 3, 2022. It is now read-only.

Header-only, non-allocating, GPU compute friendly C++ implementation of OpenSimplex.

License

Notifications You must be signed in to change notification settings

jonathonracz/OpenSimplexCPP

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

26 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

OpenSimplexCPP

This is a header-only, dependency-free, GPU compute ready implementation of OpenSimplex Noise derived from Stephen M. Cameron's C port of Kurt Spencer's Java implementation.

The goal is to produce an OpenSimplex implementation that does not perform any dynamic allocation and has no dependencies on standard headers outside fixed-width types. This not only makes it portable across operating systems but enables it to run in most GPU compute environments (CUDA, Metal, OpenCL C++).

As always, issues and pull requests are welcome.

Usage

In your CPU code, compute a seeded context:

#include <OpenSimplex/OpenSimplex.h>

...

struct Uniforms
{
    ...
    OpenSimplex::Context ctx;
};

Uniforms uniforms;
OpenSimplex::Seed::computeContextForSeed(uniforms.ctx, 42);
// Upload Uniforms to GPU

Add the OpenSimplex::Context object to your uniform buffer (take note that it's 512 bytes).

In your shader, use the OpenSimplex::Context to compute per-fragment noise (note this example is in Metal - other languages will be very similar):

using namespace metal;

#include "OpenSimplex/OpenSimplex.h"

kernel void kernelMain(texture2d<half, access::write> output [[texture0]],
                    constant Uniforms& uniforms [[buffer0]],
                    simd::uint2 gid [[thread_position_in_grid]])
{
    float value = OpenSimplex::Noise::noise2(uniforms.context, gid.x, gid.y);

    output.write(half4(value, value, value, 1.0f), gid);
}

Screenshot

About

Header-only, non-allocating, GPU compute friendly C++ implementation of OpenSimplex.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published