How should I apply 3D noise to sphere?

Started by
17 comments, last by Chillzy 1 year ago

alvaro said:
Try using a debugger to see what's happening to the noise, or even adding a bunch of print statements.

Using print statements, it just prints out one 0 and that's it.

alvaro said:
We can't possibly help you with the information we have.

Fyi, what I was asking is a method (or multiple) of generating noise and applying it to my sphere, specific to my situation.

None

Advertisement

Any of the methods you tried can be made to work. If we give you another method, it won't work either.

I'm starting to smell troll. If not, good luck. In either case, I'm out.

Generating 3D noise (Perlin or Simplex) on a sphere is easy since it's a 3D object. You feed it the surface coordinates, and you get out a number from (roughly) from -1.0 to 1.0. You can mix and match octaves, magnitudes and so forth and get something that looks pretty good. The problem people often have is precision. If you are actually doing a planet sized object you will start to lose millimeter precision at maybe 10 to 20 kilometers. On the CPU you can use double precision and that solves the problem to as big as you'll probably ever want it (say the orbit of Neptune or something), larger than any planet you'll make. On the GPU it's not so easy since even on modern GPUs doubles are painstakingly slow.

However, you have some options. You can tile noise on the GPU and when you mix it with other tiled noise you will eliminate any repetition. For Perlin noise this is easy since you can mod your input values into a repeating box. You can do this with simplex noise too, but you have to put the mod in the noise function itself, after the “skew” operation. It's really not that hard however.

All this is great for shading, but it doesn't solve the vertex coordinate precision issue. They will still lose precision and if you are down on the surface with say meter sized triangles, they are going to be all twisted and stuff. There are a couple methods of solving this, but most involve moving your data around the camera instead of the other way around.

I use doubles on the CPU and basically set up my matrix to go straight to view coordinates. My planet is in chunks and each chunk is sent down to the GPU in float but with an offset, so that the coordinates are now in a chunk local system. Then each chunk has a transformation matrix (and this is the important part) that goes straight to “view” coordinates. In view coordinates the camera is always at the origin, so everything close to it will be in high precision. Stuff far away will lose precision but that won't matter since it's far away. Realistically you need a good LOD system to make this work.

There are also other methods of dealing with this without using doubles. They use origin rebasing and offsets and stuff, but this is how I do it and it works for me. There are some pros and cons to each system. It kind of depends on the specifics.

@Gnollrunner I appreciate the useful information. I think the method I'm going to try and use to generate the noise is that I'm just going to iterate over the noise functions while simultaneously using that to modify my octahedron vertices. I think I'm going to use either that, or just constantly send it to the GPU through a uniform variable and then from there I use that to modify the sphere vertices. I'll get back to you when (and if) I got it working (at least to some point).

None

Why not use the 3D Perlin noise generator? I used it to create cow colouring on a mesh. Looks good.

A code is at:

https://github.com/sjhalayka/Julia4d2/blob/aac5a2fd485802cf78c232bbd474c1338e20f53f/perlin.h#L34

Hi guys, so few days later, but I actually got the noise working. It turns out that I was creating the noise texture wrong. I figured out that I needed to actually write the noise data to a texture first (I know, shocking!!), and from there, after I used the stb library to write the data to a jpg file (I know, it's a bad file extension, but for now, doesn't really matter) and from there I load the image containing the noise back into the program, bind it to my sphere, and from there, offset the sphere vertices. This is how my sphere looked before

Sphere without noise

And this is how it looks like with the noise texture applied (nothing else!!)

Sphere with noise texture (I know it looks like a star / snow planet but let me cook!!)

And last, but certainly not least, this is how it looks like when I use the noise data to offset the sphere vertices

Sphere with offsetted vertices!

Obviously, this isn't the final product, but this is just sort of the test, to really make sure I can do what I plan to with this project! This is just the beginning of my project, and if you want me to share the code I got you. I might make a blog in the future about this game.

None

Check out this website for some reasonably good and simple noise terrain algorithms: https://www.redblobgames.com/

Also, it looks like your frequency is too high for that size sphere. That should be easy to adjust.

@gnollrunner Yeah I already toned down the frequency, just forgot to update the post

None

This topic is closed to new replies.

Advertisement