OpenSimplex2 icon indicating copy to clipboard operation
OpenSimplex2 copied to clipboard

What kind of things can be generalized?

Open s5bug opened this issue 5 years ago • 10 comments

Say, porting OpenSimplex to Scala:

def eval[N <: Nat](coords: Sized[N, Double])(implicit ev: OpenSimplex[N]): Double

What constants can't be calculated (i.e. they would have to be included in OpenSimplex)? Is it possible to generalize the algorithm over N?

s5bug avatar Mar 21 '20 23:03 s5bug

The versions released prior to now could not be generalized straightforwardly, but the 4D function in OpenSimplex2F I just released can be generalized to N dimensions. I may do a more detailed write-up of this at some point.

KdotJPG avatar Jul 06 '20 17:07 KdotJPG

Can the 4D function be generalized downwards?

s5bug avatar Jul 06 '20 19:07 s5bug

It can! In 3D you will have four A3 lattices spaced out by <0.25, 0.25, 0.25>, or in 2D you will have three A2 lattices spaced out by <0.333..., 0.333..., 0.333...>. The initial step of finding the closest point on the first lattice might differ. The one included for 4D generalizes straightforwardly to other even dimensions, but for odd dimensions it will require slight modifications.

KdotJPG avatar Jul 07 '20 00:07 KdotJPG

Where should I get started? I.e. what part of the code should I be looking at (and how should I figure out how certain constants/control structures were derived) to do so?

s5bug avatar Jul 07 '20 00:07 s5bug

I covered a bit of that in a post here. Should cover at least some of it. https://www.reddit.com/r/proceduralgeneration/comments/hm9bam/opensimplex2_4d_implementations_now_available_new/fxcyo2q/

Let me know if you have any more questions in particular!

KdotJPG avatar Jul 09 '20 21:07 KdotJPG

Sorry to necro this thread, but I had a similar issue.

I'm trying to port OpenSimplex to Julia, and I'm trying to make an N-dimensional function, as opposed to having different functions for 2D, 3D, 4D...

First, is this even possible, or are there differences in the number of dimensions that make it not generalizable? I've taken the 4D (simplified) code as a foundation.

Most things I could figure out how to generalize from your reddit post, but I still don't understand how the gradient tables are computed. I would like to avoid any lookup tables, if possible. I know I would be sacrificing performance, but I would like to give this a try.

szethh avatar Nov 06 '21 02:11 szethh

I never even started on this, despite having wanted to for a while, so I'm still interested in any new developments/explanations/improvements 😄

s5bug avatar Nov 06 '21 02:11 s5bug

Maybe @KdotJPG can offer some help on the lookup table issue. When I finish I will post the code on github too, maybe it helps others :)

szethh avatar Nov 06 '21 12:11 szethh

FWIW I just updated the repo with new instancelessly-seedable versions, which also greatly reduce the use of lookup tables.

KdotJPG avatar Jan 16 '22 23:01 KdotJPG

Thanks, looks great!

However, I still have some questions... How are these tables generated? lookup4DVertexCodes and grad4 (or any gradN table, for that matter). Since I'm trying to port it to N dimensions, I need a way to generate these tables programatically. Is that possible?

Also, take for example the function noise4_ImproveXYZ_ImproveXZ. There are some constants multiplied to the input parameters (-0.21132486540518699998 etc). How are these calculated? Could they be generalized to more dimensions?

szethh avatar Feb 21 '22 16:02 szethh