Java-Gaming.org Hi !
 Featured games (91) games approved by the League of Dukes Games in Showcase (804) Games in Android Showcase (237) games submitted by our members Games in WIP (867) games currently in development
 News: Read the Java Gaming Resources, or peek at the official Java tutorials
Pages: [1]
 ignore  |  Print
 [Solved] SimpleXnoise Translation.  (Read 2487 times) 0 Members and 1 Guest are viewing this topic.
Jakibah

Junior Devvie

Medals: 2
Exp: 5 years

 « Posted 2017-08-03 16:49:27 »

So I was experimenting with noise a little bit and I found this code on this forum that generates a 2D noise.

 1  2  3  4  5  6  7  8  9  10  11  12  13  14  15  16  17  18  19  20  21  22 `public class NoiseGenerator{    public static float[][] generateOctavedSimplexNoise(float xTrans, float yTrans, int width, int height, int octaves, float roughness, float scale){         float[][] totalNoise = new float[width][height];          float layerFrequency = scale;          float layerWeight = 1;          float weightSum = 0;          for (int octave = 0; octave < octaves; octave++) {             for(int x = 0; x < width; x++){                for(int y = 0; y < height; y++){                   totalNoise[x][y] += (float) SimplexNoise.noise(x * layerFrequency,y * layerFrequency) * layerWeight;                }             }              layerFrequency *= 2;              weightSum += layerWeight;              layerWeight *= roughness;                        }          return totalNoise;      }}`

It works good for me as long a I am generating single chunks. But when I try to generate the chunks around the initial one they are the same. So I wanted to add  a translation so when I leave the first chunk it loads a new chunk that continues the previous one. The Translation that I want to add is like the translation that you have in SiVi http://www.java-gaming.org/topics/sivi-2d-simplex-noise-visualizer-tool/30187/view.html for those that are familiar with it.
But where do I have to apply the Translation. I thought like this:
 1 `totalNoise[x][y] += (float) SimplexNoise.noise((x + xTrans) * layerFrequency,(y + yTrans) * layerFrequency) * layerWeight;`
. But that makes all chunks empty except the first one.
philfrei
 « Reply #1 - Posted 2017-08-03 18:31:01 »

[EDIT: Basically this post was quite off base, so the simplest thing is to just delete it.]

Jakibah

Junior Devvie

Medals: 2
Exp: 5 years

 « Reply #2 - Posted 2017-08-03 19:11:01 »

So I changed the code to this:
 1 `totalNoise[x][y] += (float) SimplexNoise.noise((x * layerFrequency) + xTrans,((y * layerFrequency)) + yTrans) * layerWeight;                }`

So now the layerweight is applied to each result. But the world still cuts of at the chunk borders.
philfrei
 « Reply #3 - Posted 2017-08-03 23:33:09 »

First off, I apologize for not reading your question more closely. I didn't notice that you want the chunks to be contiguous. I also didn't notice that you had consulted SiVi!    I need to slow down.

Maybe get rid of the roughness calculation? Or make roughness = 1. I think this is complicating things in an unhelpful way.

So, your first solution was correct.

 1 `totalNoise[x][y] += (float) SimplexNoise.noise((x + xTrans) * layerFrequency,(y + yTrans) * layerFrequency) * layerWeight;`

When calling the generatedOctavedSimplexNoise function, the xTrans argument should equal a multiple of width, and yTrans should equal a multiple of height. The multiple would correspond to the number of chunks distance from the original chunk where xTrans and yTrans are both 0.

What does it mean when you say the chunks are "empty"? Are they drawing black? white? Is there literally no data in the returned array? Is it all 0? Is there data > 1 or < -1?

philfrei
 « Reply #4 - Posted 2017-08-03 23:58:41 »

By the way, I never tested that particular noise generation algorithm, and it might be breaking down for certain input values.

If I understand it correctly, it is designed to always produce the same relationship between the overlays, where each higher (faster varying) octave has half the weight of the previous.

I think it is useful to specify scalings and weights to individual overlays of the noise, and to use as few overlays as necessary to make the desired effect, as each "octave" adds significantly to cpu expense. For example, a graphic with "octaves" of 1, 2, 4, 8 might also work with "octaves" of 1, 3, 8, costing 25% less.

Jakibah

Junior Devvie

Medals: 2
Exp: 5 years

 « Reply #5 - Posted 2017-08-04 14:18:24 »

Solved!!! Thanks so much!!!
Pages: [1]
 ignore  |  Print

 Riven (397 views) 2019-09-04 15:33:17 hadezbladez (5280 views) 2018-11-16 13:46:03 hadezbladez (2204 views) 2018-11-16 13:41:33 hadezbladez (5544 views) 2018-11-16 13:35:35 hadezbladez (1150 views) 2018-11-16 13:32:03 EgonOlsen (4585 views) 2018-06-10 19:43:48 EgonOlsen (5462 views) 2018-06-10 19:43:44 EgonOlsen (3119 views) 2018-06-10 19:43:20 DesertCoockie (4016 views) 2018-05-13 18:23:11 nelsongames (4708 views) 2018-04-24 18:15:36
 A NON-ideal modular configuration for Eclipse with JavaFXby philfrei2019-12-19 19:35:12Java Gaming Resourcesby philfrei2019-05-14 16:15:13Deployment and Packagingby philfrei2019-05-08 15:15:36Deployment and Packagingby philfrei2019-05-08 15:13:34Deployment and Packagingby philfrei2019-02-17 20:25:53Deployment and Packagingby mudlee2018-08-22 18:09:50Java Gaming Resourcesby gouessej2018-08-22 08:19:41Deployment and Packagingby gouessej2018-08-22 08:04:08
 java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org