TokisanGames/Terrain3D

Adjustable mesh density

TokisanGames opened this issue · 6 comments

Our mesh vertices are every 1 unit. The Witcher 3 uses 0.5 for their clipmap terrain, which I'd like to copy. Lower end hardware might benefit from 2+.

This would allow using a 1024px map for a 512m world, or a 2048m world instead of the current 1024px = 1024m world.

Maybe as of a . later pr, if i understand this correctly you can make the density decrease automatically when more far away while maintaining the distance to save some performance.

I'm going to take a look at this. I've figured out how to make the terrain scale visually, I just need to do a bunch of testing to make sure the physics and terrain sculpting/painting works. Then I'll send a PR assuming that's all working.


One open question, though. When changing the terrain size, the height scale is incorrect. That is, when changing from 1024 to 2048, the terrain is half the height it should be. Do we want to try to do anything about that? I can think of three options:

  1. Explicitly update the height scale when changing the terrain size. By this I mean when going from 1024 to 2048, automatically change the height scale in the inspector from, say, 1000 to 2000 (same factor as the terrain size change).
  2. Implicitly update the height scale. If the user specifies height scale 1000 and terrain size 2048, we internally treat it as if they'd specified 2000 for height. That is, we calculate a multiplier based on the terrain size vs 1024 and apply that when using height.
  3. Do nothing, make the user specify the height each time. And...frankly users shouldn't be importing terrain all that often (hopefully).

Each of these have merit. 1 is nice because it usually Just Works but users keep control if they want to specify the exact height. 2 is nice because it means if I have two heightmaps of the same logical region, but different sizes, I can give them the same height scale and that Just works. 3 is kinda nice because there's no magic involved.

IMO there should be a little magic here. I think I'm personally leaning slightly towards 2 because I already have problems forgetting which height scale I import my terrains at, and last thing I want is to remember more numbers.

Thoughts?

There are two other devs who have implementations of adjusting mesh density. One enabled Godot's transforms, but is leaning away from this solution. The other is adjusting the vertices per distance, which we are going with. You are welcome to join the discussion.
https://discord.com/channels/691957978680786944/1065519581013229578/1192760635931508746

When changing the terrain size, the height scale is incorrect.

Heights are absolute, displaying the height stored in the height data.

The importer could use an option to resize maps and already has an option to scale or offset height. I don't think it needs more than that. In the future, the tools menu needs some image manipulation tools which can expose resizing images and scaling heights. See #81.

So the user could change the height data with the importer, future image tools, or externally.

And...frankly users shouldn't be importing terrain all that often (hopefully).

Yes, generally set and forget. Changing mesh density should be instant. Then with included image tools, they can adjust the height data. Maybe we'll add a realtime height scaler.

Okay, I'll join the Discord when I can...

But I was able to revert this commit and get that working with a 1-line code change. Is that approach fundamentally flawed or something?

That commit came out of #77, and you can read about why it was temporarily disabled. Not the same thing as mesh density, in this ticket.

Subsequent changes may allow other region sizes to work, but it needs further testing before it can be enabled again.

Implemented in #296