Skip to content
This repository has been archived by the owner on Nov 13, 2023. It is now read-only.

Improve terrain generation in lod_terrain example #30

Closed
wants to merge 2 commits into from

Conversation

Matt343
Copy link
Contributor

@Matt343 Matt343 commented Jun 24, 2021

I implemented some of the basic terrain generation techniques outlined here: https://developer.nvidia.com/gpugems/gpugems3/part-i-geometry/chapter-1-generating-complex-procedural-terrains-using-gpu

Specifically, I added a base layer at y=0 and offset the noise lookup coordinates with a warp noise (which generates 3d offset vectors at each point). This gives us some amount of overhangs and interesting features to test against, although I didn't spend too much time tuning the relative frequencies and scales of the two noise textures to achieve anything super realistic.

@bonsairobo
Copy link
Owner

bonsairobo commented Jun 24, 2021

I found these parameters are pretty good:

let freq = 0.25;
let scale = 5.0;
let seed = 666;
let octaves = 9;
let freq_warp = 0.05;
let scale_warp = 1000.0;

@bonsairobo
Copy link
Owner

This is definitely more interesting than the noise we had before. It does take a lot longer to generate, but that's not a big problem for this example. It might be worth adding some output to say "generating noise, please wait."

I've also noticed that it results in some weird artifacts in the meshes. I'm assuming either the noise itself is getting some weird jaggy regions or the mesh normal estimation is having problems.

Of course, there is only one light in the scene so it's not going to look quite right when a triangle is not getting any light, but it basically looks like acne when there are noticeable patterns of darkness.

mesh_acne

@Matt343
Copy link
Contributor Author

Matt343 commented Jun 25, 2021

This is definitely more interesting than the noise we had before. It does take a lot longer to generate, but that's not a big problem for this example. It might be worth adding some output to say "generating noise, please wait."

I've also noticed that it results in some weird artifacts in the meshes. I'm assuming either the noise itself is getting some weird jaggy regions or the mesh normal estimation is having problems.

Of course, there is only one light in the scene so it's not going to look quite right when a triangle is not getting any light, but it basically looks like acne when there are noticeable patterns of darkness.

mesh_acne

Yeah I was going for more of a stress test of the system than anything realistic, so I dialed up the warping to get more overhangs. I'll see about adding some console output.

The dark patches are strange, I don't get those on my machine at all

@Matt343
Copy link
Contributor Author

Matt343 commented Jun 25, 2021

Ah, with your parameters I do see the dark patches. Seems to be related to triangles next to very sharp edges. It makes sense that the normals might be thrown off by that case I guess, depending on how they're generated.

@bonsairobo
Copy link
Owner

Yea I made an issue for these artifacts: #31

I think I understand pretty well what the issue is but I don't know of an obvious fix, other than trying to constrain the SDF to avoid sharp edges. Or maybe there is something to do in the shader to get interpolation that's aware of the surface curvature.

@bonsairobo
Copy link
Owner

bonsairobo commented Jun 25, 2021

I have been messing around more with noise parameters because I've noticed some artifacts. I made all of the parameters load from a file so I can quickly test them out.

Here's a weird case:

    noise: (
        freq: 0.1,
        scale: 50.0,
        seed: 666,
        octaves: 9,
        freq_warp: 0.1,
        scale_warp: 100.0,
    ),

noise_cliff

I don't understand the noise well enough to say why this would happen.

@bonsairobo
Copy link
Owner

bonsairobo commented Jun 25, 2021

I think after warping and resampling, we should be doing trilinear interpolation rather than just truncating the floating point coordinates. If I had to guess, this would help make the warping look a lot smoother. I will give it a try.

@Matt343
Copy link
Contributor Author

Matt343 commented Jun 25, 2021

Yeah you're totally right, I was hesitant to try anything that would slow it down further :/

@bonsairobo
Copy link
Owner

Yea I'm guessing the main bottleneck is hashing every point when calling ChunkMap::get_point. We can probably figure out a faster way. The unfortunate part is that the warping will inevitably go out of bounds of any chunk array, but we can probably figure out what the bounds are and pad the array we're sampling. That might mean we write all of the chunks into one big padded array that we sample.

@bonsairobo
Copy link
Owner

Dang I am having a hard time getting the trilinear interpolation to make this look any better. The warping seems nice in theory but I'm not able to make it look as smooth as the GPU gems article.

I think I'd like to try my heightmap with subtracted noise idea.

@bonsairobo
Copy link
Owner

I will commit something close to what you've written but without the warping if that's OK. I will add you as a co-author. I think adding more octaves was a big improvement, so I will keep that.

@Matt343
Copy link
Contributor Author

Matt343 commented Jun 27, 2021

Yeah I actually tried your heightmap idea before this, it just didn't seem like the heightmap was adding that much complexity that the fbm noise wasn't already providing.

That sounds good, I'll close this out then.

@Matt343 Matt343 closed this Jun 27, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants