Java-Gaming.org    
Featured games (91)
games approved by the League of Dukes
Games in Showcase (577)
games submitted by our members
Games in WIP (498)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  noise implementation  (Read 1013 times)
0 Members and 1 Guest are viewing this topic.
Offline kromide

Junior Newbie





« Posted 2013-09-29 15:12:04 »

I have been searching on how to implement noise into voxel world gen and i cant find any good resources only ones that have the functions which i can get a float returned from it i just dont know what to do with it. any help would be awesome Smiley please and thank you.
Offline opiop65

JGO Kernel


Medals: 123
Projects: 7
Exp: 3 years


Team Alluminum


« Reply #1 - Posted 2013-09-29 15:35:26 »

Here's a library that has lots of noise functions, you can use the library or just look in the code to see how it works, but it should be fairly simple to figure out how to use them:
toxiclibs.org/docs/core/overview-summary.html
Here's the SimplexNoise class:
www.itn.liu.se/~stegu/simplexnoise/SimplexNoise.java

Offline kromide

Junior Newbie





« Reply #2 - Posted 2013-09-29 17:01:32 »

i know how to use a noise function and get a float then i divide by 2 add 1 and multiply by the max i want but i cant get it to do anything when i try to use it as a "Y" axis variable it just makes straight lines the same height. do i need to test each(x,y,z) get its float as at (0,0) is (output) blocks high. and then draw coordinate by coordinate? sorry i see all these great images of noise gen'ed worlds but cant get it to work for me xD
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Longor1996
« Reply #3 - Posted 2013-09-29 19:07:10 »

i know how to use a noise function and get a float then i divide by 2 add 1 and multiply by the max i want but i cant get it to do anything when i try to use it as a "Y" axis variable it just makes straight lines the same height. do i need to test each(x,y,z) get its float as at (0,0) is (output) blocks high. and then draw coordinate by coordinate? sorry i see all these great images of noise gen'ed worlds but cant get it to work for me xD

Let me help you (Pseudocode):
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
// This is the scale between the single noise values. Use bigger values than 128 to get bigger scaled noise.
constant float scale = 1.0 / 128.0;

for_each CELL in SPACE_BEING_GENERATED
{
  float NOISE = perlinOrSimplex(CELL.x * scale, CELL.y * scale, CELL.z * scale) * 0.5 + 1.0;
 
  CELL.type = NOISE smaller_than 0 then (water) else (land);
  CELL.height = NOISE * 16;
}


It should be translateable into Java-code easely.

- Longor1996

Sorry for my bad English! That's because i am from Germany.
Offline opiop65

JGO Kernel


Medals: 123
Projects: 7
Exp: 3 years


Team Alluminum


« Reply #4 - Posted 2013-09-29 19:16:14 »

Sorry, I don't entirely understand. Could you post some code and screenshots of what's happening? I think you might be using 2D noise somehow, because a straight line shouldn't happen ever with 3D noise, at least not too often.

Offline kromide

Junior Newbie





« Reply #5 - Posted 2013-09-30 04:47:36 »

I use in pseudo code
for each x<chunksize; x++
       For each y<chunksize; y++
             For each z<chunksize; z++

Rendering method and I have tried putting the output into the y like I have read but it makes all blocks of the same z the same y so I get lines all the away across. Iv tried many differant ways but I think I need to redesign my world gen method

Edit I'm not home to post a screenshot but ill get one when I get there
edit 2: I'm using a 3d array to store "block" Data
Offline philfrei
« Reply #6 - Posted 2013-09-30 09:42:27 »

The tool below has some interesting 2D textures that you can fiddle with.

http://www.hexara.com/SimplexBuilder.html

The main thing is to go to the Menu Bar item "View" and click on Gallery. There are about a dozen different textures there. When you click on them, they will load into the tool, and you will be able to see what the settings are and play around with them.

I got side-tracked onto another project and haven't written a guide as to how I implement the settings in Java, but it might be obvious with a little study if you already understand the basics. I'm happy to answer questions.

"Greetings my friends! We are all interested in the future, for that is where you and I are going to spend the rest of our lives!" -- The Amazing Criswell
Offline kromide

Junior Newbie





« Reply #7 - Posted 2013-10-01 09:36:20 »

So I read through http://www.itn.liu.se/~stegu/simplexnoise/simplexnoise.pdf
and I have a few questions about it. I'm assuming I use 3d noise? But do I feed it random numbers or the coordinates of the blowing I'm needing to draw. If so what do I use for the yin that's what I'm fringe to find I thought?
Offline opiop65

JGO Kernel


Medals: 123
Projects: 7
Exp: 3 years


Team Alluminum


« Reply #8 - Posted 2013-10-01 14:29:48 »

Actually, you really should be using 2D noise and making a height map. Every single number tat comes out of the generator is a tile, or whatever you use for your terrain. Color each tile corresponding to the value that comes out of the generator (1 = more red, 0 = more blue etc) then loop through the image and get the rgb value and create a new tile at that position and set the height corresponding to the color. Sorry that was a quick explanation, I'm in school! Tongue

Offline kromide

Junior Newbie





« Reply #9 - Posted 2013-10-01 16:17:46 »

ok so make a 2D array to hold all the values for each(x,z) and then read that to set the (y or height).. as far as generating the noise ie when i call noise(x,y) is the x,y correspond to the map? like if i want the height for "tile" (0,0) do i call noise(0,0) then noise(0,1)...ect. ?  sorry for all the questions but your being a big help and there is not many "easy" to read guides...
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline philfrei
« Reply #10 - Posted 2013-10-01 19:43:45 »

Yes. Feed the noise function your X & Z, and it will give you the Y that corresponds. The function always gives the exact same result for any given input.

A lot depends on how you scale your input. You will want to scale your X & Z unit values to fractions of 1. The Simplex function has something that can kind of be called a "period" that is close to 1. I don't know the exact term. But that is about the average distance of a random "wave". Once the unit increment gets up to around 1, the results approach random noise.

A single iteration of the Simplex function is a fairly smooth. You can get more interesting terrain by adding "octaves" (additional iterations) of noise. An octave function progresses over the function space at a multiple of the rate. The results of the octave functions are then summed together.

You can translate to any spot and use that as your starting point.
Y = noise(x * xScale + xTranslate, z * zScale + zTranslate);

The program I cited previously has a "terra map" 2D graphic. The output of the X & Y values are scaled so that they will map to a Color Map with colors that correspond to types of terrain. You could just use the generated values as Y values instead of as indices into the color map. Switching to the B&W color bar (in the GUI) might make the results clearer for your intended use.

The "terra map" demo makes use of several octaves. The idea is that you can play around with the settings to figure out what sort of contours you get with various combinations of "octaves" (immediate visual feedback), then plug the settings into your code.

I use an xScale & yScale = 1/256 as the base scale value, then double the scale for the octaves (GUI only shows the doubling values, not the 1/256 which is built into all channels). In the example, there is no translation used. But you can play with that and see the result immediately.






"Greetings my friends! We are all interested in the future, for that is where you and I are going to spend the rest of our lives!" -- The Amazing Criswell
Offline kromide

Junior Newbie





« Reply #11 - Posted 2013-10-01 19:52:10 »

yall are the greatest i looked for almost a week before posting here should have done so sooner. saved me so much time and aggravation i will test asap and let yall know how it goes Cheesy
Offline opiop65

JGO Kernel


Medals: 123
Projects: 7
Exp: 3 years


Team Alluminum


« Reply #12 - Posted 2013-10-01 20:22:55 »

Whoa, great explanation! Even though I already knew all that, it somehow helped me a bit too. I medaled you Smiley

Offline kromide

Junior Newbie





« Reply #13 - Posted 2013-10-02 11:21:01 »

so for octaves do i literally add the different outputs?

1  
2  
3  
4  
5  
6  
7  
        
             
for(int o=0;o<octave;o++){
   y += n.noise(x * xScale, z * zScale);
   xScale=(xScale*2);
   zScale=(zScale*2);
}
Offline philfrei
« Reply #14 - Posted 2013-10-02 12:53:23 »

When Ken Perlin described doing this, he called it "sum 1/f(noise)", referring to it as a fractal progression.

http://www.noisemachine.com/talk1/21.html

It took me a while to figure this out. (It took a while for much about using noise to "click" for me!) By his formula, you would add half as much for each iteration.

Or another way to think about it: make the result a weighted sum, with the weights in a series that keeps dropping by a factor of 2.

1+2+4+8 = 15, so 8/15 * the lowest octave + 4/15 * the second octave + 2/15 * the third octave + 1/15 * the top octave (if you had four octaves).

By making it a proper weighting, you can ensure keeping the sum of the additions within the bounds [-1, 1].

In the visualizer app, the weighting occurs in the "mixer" (bank of sliders, lower left). In the "terrain" example, you'll see the values in the mixer dropping by 2's: 64, 32, 16, 8, etc. If you play around with the levels, you will find out that if the octaves are all given the same value, then the activity of the data at the top octaves will overpower the rest of the graphic.

Being a musician, I was bugged by the use of the term "octave." Part of the reason I built the dang visualizer was because I couldn't believe that the doubling relationships were all that magical in the visual realm, as they are in sound. And in truth, you don't have to follow them strictly. But this fractal formula does seem to come up a lot, does have a basic niceness to it.

"Greetings my friends! We are all interested in the future, for that is where you and I are going to spend the rest of our lives!" -- The Amazing Criswell
Offline philfrei
« Reply #15 - Posted 2013-10-02 13:03:22 »

I just remembered, making the denominator the next power of two might lend itself to a nifty algorithm for creating the weighting, maybe using bit shifting.

For four octaves,
1st octave: 8/16
2nd octave: 4/16
3rd octave: 2/16
4th octave: 1/16

It slightly compresses the result (will be 15/16ths of the range [-1, 1]).

But the Simplex noise function itself is so costly in comparison, that the pickup in efficiency by avoiding division is not that big an issue.

I think I got this idea from someone else here at JGO, possibly Dzzd.

"Greetings my friends! We are all interested in the future, for that is where you and I are going to spend the rest of our lives!" -- The Amazing Criswell
Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

xsi3rr4x (22 views)
2014-04-15 18:08:23

BurntPizza (17 views)
2014-04-15 03:46:01

UprightPath (31 views)
2014-04-14 17:39:50

UprightPath (15 views)
2014-04-14 17:35:47

Porlus (31 views)
2014-04-14 15:48:38

tom_mai78101 (57 views)
2014-04-10 04:04:31

BurntPizza (115 views)
2014-04-08 23:06:04

tom_mai78101 (214 views)
2014-04-05 13:34:39

trollwarrior1 (182 views)
2014-04-04 12:06:45

CJLetsGame (189 views)
2014-04-01 02:16:10
List of Learning Resources
by Longarmx
2014-04-08 03:14:44

Good Examples
by matheus23
2014-04-05 13:51:37

Good Examples
by Grunnt
2014-04-03 15:48:46

Good Examples
by Grunnt
2014-04-03 15:48:37

Good Examples
by matheus23
2014-04-01 18:40:51

Good Examples
by matheus23
2014-04-01 18:40:34

Anonymous/Local/Inner class gotchas
by Roquen
2014-03-11 15:22:30

Anonymous/Local/Inner class gotchas
by Roquen
2014-03-11 15:05:20
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
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!