• Stars
    star
    566
  • Rank 78,774 (Top 2 %)
  • Language
    C++
  • License
    MIT License
  • Created over 11 years ago
  • Updated almost 3 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Header-only Perlin noise library for modern C++ (C++17/C++20)

siv::PerlinNoise

noise

siv::PerlinNoise is a header-only Perlin noise library for modern C++ (C++17/20).
The implementation is based on Ken Perlin's Improved Noise.

Features

  • 1D / 2D / 3D noise
  • octave noise
  • initial seed
  • (✨ new in v3.0) produce the same output on any platform (except for floating point errors)

License

siv::PerlinNoise is distributed under the MIT license.

Usage

# include <iostream>
# include "PerlinNoise.hpp"

int main()
{
	const siv::PerlinNoise::seed_type seed = 123456u;

	const siv::PerlinNoise perlin{ seed };
	
	for (int y = 0; y < 5; ++y)
	{
		for (int x = 0; x < 5; ++x)
		{
			const double noise = perlin.octave2D_01((x * 0.01), (y * 0.01), 4);
			
			std::cout << noise << '\t';
		}

		std::cout << '\n';
	}
}

API

template <class Float> class BasicPerlinNoise

  • Typedefs
    • using PerlinNoise = BasicPerlinNoise<double>;
    • using state_type = std::array<std::uint8_t, 256>;
    • using value_type = Float;
    • using default_random_engine = std::mt19937;
    • using seed_type = typename default_random_engine::result_type;
  • Constructors
    • constexpr BasicPerlinNoise();
    • BasicPerlinNoise(seed_type seed);
    • BasicPerlinNoise(URBG&& urbg);
  • Reseed
    • void reseed(seed_type seed);
    • void reseed(URBG&& urbg);
  • Serialization
    • constexpr const state_type& serialize() const noexcept;
    • constexpr void deserialize(const state_type& state) noexcept;
  • Noise (The result is in the range [-1, 1])
    • value_type noise1D(value_type x) const noexcept;
    • value_type noise2D(value_type x, value_type y) const noexcept;
    • value_type noise3D(value_type x, value_type y, value_type z) const noexcept;
  • Noise (The result is remapped to the range [0, 1])
    • value_type noise1D_01(value_type x) const noexcept;
    • value_type noise2D_01(value_type x, value_type y) const noexcept;
    • value_type noise3D_01(value_type x, value_type y, value_type z) const noexcept;
  • Octave noise (The result can be out of the range [-1, 1])
    • value_type octave1D(value_type x, std::int32_t octaves, value_type persistence = value_type(0.5)) const noexcept;
    • value_type octave2D(value_type x, value_type y, std::int32_t octaves, value_type persistence = value_type(0.5)) const noexcept;
    • value_type octave3D(value_type x, value_type y, value_type z, std::int32_t octaves, value_type persistence = value_type(0.5)) const noexcept;
  • Octave noise (The result is clamped to the range [-1, 1])
    • value_type octave1D_11(value_type x, std::int32_t octaves, value_type persistence = value_type(0.5)) const noexcept;
    • value_type octave2D_11(value_type x, value_type y, std::int32_t octaves, value_type persistence = value_type(0.5)) const noexcept;
    • value_type octave3D_11(value_type x, value_type y, value_type z, std::int32_t octaves, value_type persistence = value_type(0.5)) const noexcept;
  • Octave noise (The result is clamped and remapped to the range [0, 1])
    • value_type octave1D_01(value_type x, std::int32_t octaves, value_type persistence = value_type(0.5)) const noexcept;
    • value_type octave2D_01(value_type x, value_type y, std::int32_t octaves, value_type persistence = value_type(0.5)) const noexcept;
    • value_type octave3D_01(value_type x, value_type y, value_type z, std::int32_t octaves, value_type persistence = value_type(0.5)) const noexcept;
  • Octave noise (The result is normalized to the range [-1, 1])
    • value_type normalizedOctave1D(value_type x, std::int32_t octaves, value_type persistence = value_type(0.5)) const noexcept;
    • value_type normalizedOctave2D(value_type x, value_type y, std::int32_t octaves, value_type persistence = value_type(0.5)) const noexcept;
    • value_type normalizedOctave3D(value_type x, value_type y, value_type z, std::int32_t octaves, value_type persistence = value_type(0.5)) const noexcept;
  • Octave noise (The result is normalized and remapped to the range [0, 1])
    • value_type normalizedOctave1D_01(value_type x, std::int32_t octaves, value_type persistence = value_type(0.5)) const noexcept;
    • value_type normalizedOctave2D_01(value_type x, value_type y, std::int32_t octaves, value_type persistence = value_type(0.5)) const noexcept;
    • value_type normalizedOctave3D_01(value_type x, value_type y, value_type z, std::int32_t octaves, value_type persistence = value_type(0.5)) const noexcept;

Example

Run example.cpp with the following parameters.

frequency = 8.0
octaves = 8
seed = 12345

noise


frequency = 8.0
octaves = 8
seed = 23456

noise


frequency = 8.0
octaves = 3
seed = 23456

noise

More Repositories

1

Laptops

💻 ゲーム開発・プログラミングにおすすめの低予算ノート PC 💰
152
star
2

Xoshiro-cpp

Header-only Xoshiro/Xoroshiro PRNG wrapper library for modern C++ (C++17/C++20)
C++
147
star
3

tenkei_90

競プロ典型 90 問 練習 (C++17)
46
star
4

Siv3D-Reference

[deprecated] Siv3D Reference
C++
30
star
5

games

様々なゲームのプログラムを C++ & Siv3D で書いていくプロジェクト
23
star
6

NamedParameter

Simple named parameter interface for modern C++
C++
21
star
7

EnumBitmask

A C++ library to enable bitmask operators for an enum class type
C++
12
star
8

SivMetal

An experimental Metal project for OpenSiv3D
Objective-C++
12
star
9

Zenn.Public

11
star
10

YesNo

C++
5
star
11

IndexedIterator

Header-only indexed iterator library for modern C++
C++
5
star
12

YatCoder

競技プログラミング(プログラミングコンテスト) C++14 ライブラリ
C++
4
star
13

Guetzli-test

4
star
14

Siv

Utilities for VC++
C++
2
star
15

RandomHints

https://qiita.com/Reputeless/items/70f737e78827057b7dd1
C++
2
star
16

Reputeless

2
star
17

Siv3D-GameJam-11-RiseInSeaLevel

第 11 回 Siv3D Game Jam (テーマ「島」) 参加作品
C++
1
star
18

Siv3D-GameJam-16-2DVisibility

第 16 回 Siv3D Game Jam (テーマ「光」) 参加作品
C++
1
star
19

SivShader

C++
1
star
20

Kemurikusa-Siv3D

https://twitter.com/Reputeless/status/1119952385034440704
C++
1
star