Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support getting noise value at arbitrary points to support warping #7

Open
lukehesluke opened this issue Jun 6, 2024 · 0 comments
Open

Comments

@lukehesluke
Copy link
Contributor

Hi, I'd like to implement warping (e.g. https://iquilezles.org/articles/warp/) using this library. An example warping function is provided in that article. It looks like:

float pattern( in vec2 p )
{
    vec2 q = vec2( fbm( p + vec2(0.0,0.0) ),
                   fbm( p + vec2(5.2,1.3) ) );

    return fbm( p + 4.0*q );
}

where fbm(..) is a fractal noise function that takes, in this case, a 2D vector and returns the noise value at that point. This example therefore deals with the same kind of noise as makeRectangle(..) in fractal-noise-js.

This technique requires being able to get noise values at arbitrary points and is therefore not presently possible with the grid-like approach used in this library.

One way to be able to support this and maintain the grid-first approach that makes this library very approachable would be to provide a function like:

getRectangleNoiseValue(noise2: Noise2Fn, options: Options, x: number, y: number): number {

Which gets the 2D noise value at x and y, which can here be non-integer, non-positive, etc, but still describe the same surface as makeRectangle(..). makeRectangle(..) could then be adjusted to use the above function.

Extra Benefits

  • There are many other techniques that similarly make use of being able to sample arbitrary points. For example, calculating normals.
  • For situations in which the grid is too large to be stored in memory and it is better to iterate through and reduce.

Example

An example of how this could look is in this draft PR: #6. Let me know if you agree with the approach or would prefer changes (or disagree with its inclusion in this repo) and then it can potentially be finalised.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant