summary refs log tree commit diff
path: root/config.nix
blob: 1dd1750ae0253b60ba5f1b56c0e1d050edb0fbae (plain)
1
2
3
{
  allowUnfree = true;
}
Double */ .highlight .se { color: #87CEEB } /* Literal.String.Escape */ .highlight .sh { color: #87CEEB } /* Literal.String.Heredoc */ .highlight .si { color: #87CEEB } /* Literal.String.Interpol */ .highlight .sx { color: #87CEEB } /* Literal.String.Other */ .highlight .sr { color: #87CEEB } /* Literal.String.Regex */ .highlight .s1 { color: #87CEEB } /* Literal.String.Single */ .highlight .ss { color: #87CEEB } /* Literal.String.Symbol */ .highlight .bp { color: #DDD } /* Name.Builtin.Pseudo */ .highlight .fm { color: #FF0 } /* Name.Function.Magic */ .highlight .vc { color: #EEDD82 } /* Name.Variable.Class */ .highlight .vg { color: #EEDD82 } /* Name.Variable.Global */ .highlight .vi { color: #EEDD82 } /* Name.Variable.Instance */ .highlight .vm { color: #EEDD82 } /* Name.Variable.Magic */ .highlight .il { color: #F0F } /* Literal.Number.Integer.Long */
#pragma once

#include "Common.hpp"

namespace Math::Perlin {

Real raw(Vector<2> pos);
Real raw(Vector<3> pos);

template <USize D>
struct Noise {
    static_assert(D > 1 && D < 4);

    Vector<D> offset{20000.0f};
    Real scale = 15.0f;

    UInt octaves = 3;
    Real persistence = 0.3f;
    Real lacunarity = 2.0f;

    Real at(Vector<D> pos) const {
        Real result = 0;
        Real max = 0;
        Real frequency = 1;
        Real amplitude = 1;

        for (UInt octave = 0; octave < octaves; octave++) {
            result += raw((pos + offset).abs() / scale * frequency) * amplitude;
            max += amplitude;

            frequency *= lacunarity;
            amplitude *= persistence;
        }

        return result / max;
    }
};

}