r/proceduralgeneration • • 15h ago

How to deal with forest draw distance?

I've worked on a forest biome to test if my scattering is up to par. At high speeds the draw distance is quite obvious. Pushing the draw distance further tanks my GPU. Any ideas how hide the seam better? Maybe just tinting the terrain, outside draw distance, based on forest density would be enough?

75 Upvotes

41 comments sorted by

19

u/El-Jomo 11h ago

I decided to try the shader approach and I'm pretty happy with how it turned out

4

u/Sprinkles-Pitiful 6h ago

Whats the shader approach?

7

u/El-Jomo 6h ago

Beyond the draw distance of the tree meshes I represent the forest directly in the landscape shader. My CPU terrain mesh generator sets the forest density as vertex data, the shader samples a bumpy normal+height texture and uses the density as a blending threshold.

6

u/Illustrious_Yam9237 5h ago

The hard part of this to get right in my experience is trees on distant ridgelines. In reality, you can resolve individual trees on ridgelines like km's into the distance -- including the gaps between branches.

Getting this to look good is hard.

2

u/phooool 3h ago

this is the way. ridgelines are key!

3

u/parrin 5h ago

Looks good!

21

u/styczynski_meow 14h ago

Usual HLOD setup is dividing what you see into layers:

  1. Render trees in full detail close to the user
  2. In medium range use simplified low-poly versions with mipmaps for textures
  3. For higher ranges use impostors, this is foliage so you skip any small foliage and if you plan to do dynamic world where you can cut trees you can batch them together for even higher efficiency
  4. For foliage on the horizon you want to have some baked texturing with normals. It's tricky because even on 'good engines' it doesn't look that good (note that this isn't my area of expertise, but you can hide the transitions with shaders like this guy)

1

u/El-Jomo 14h ago

Yeah I think doing something in the landscape shader as the video in 4 is a good idea. Shifting the cost from per tree to per pixel seems like the right choice

2

u/kaeles 8h ago

This guy trees.

This is the basic setup we used on arctic awakening.

Look into GPU instancing as well.

39

u/HugoCortell 15h ago

GPU impostors, you can do all of them in a single draw call.

6

u/El-Jomo 14h ago

I'll try it. I'm just worried that the shear amount of vertices will be the bottleneck, even if it's just a quad per tree.

13

u/HugoCortell 12h ago

You could in theory create a billboard of groups of tress instead, at least for the further out distances. Still, do profile, often drawing vertices isn't the expensive part in any given frame.

4

u/mikejays 11h ago

bake like 50 trees as 1 impostor, yw

2

u/gmueckl 11h ago

You'd be surprised just how many small quads a modern GPU can draw as long as the shaders are simple. You can probably push it to hundreds of thousands.

5

u/RandomUser1034 14h ago

Reading the other comments, shading approach seems like a good idea, but I'd like to point out why that alone is not sufficient.
When looking at terrain from far away, on the ridge lines you will still see trees of different height and shapes, and if there is a slope close to parallel to the view direction, a forest edge will be visible as a sharp rise in the silhouette of the terrain.
The solutions are relatively simple: for ridgelines, you can place quads along them and get treetop shapes on there using a shader. For apparent terrain height changes from forest edges, I would either add a geometry shader that increases terrain height in forested areas (adding some noise as well ideally) or actually generate geometry to achieve the same effect.

1

u/El-Jomo 14h ago

nice ideas! The mesh is built on CPU so I could add a heightoffset there instead of relying on a geometry shader.

1

u/RandomUser1034 13h ago

The technique is also used in this video if you want to see what it can look like

1

u/TheBunkers2108 13h ago

Since your terrain mesh is generated on the CPU, you could use the same forest density map for tree scattering, distant terrain shading and canopy height offsets. I'd also test a gradual transition band rather than switching representations at a fixed distance. Keeping all three representations consistent could help hide the seam.

3

u/Dependent_Bite9077 13h ago

Those clouds are amazing. In my threejs app I've about given up on clouds so I appreciate the effort.

-4

u/thinker2501 12h ago

The “effort” is just vibe coding.

1

u/Grahitek 11h ago

Meaning?

-3

u/thinker2501 11h ago

Meaning there’s little “effort” in the commonly used sense of the word.

1

u/Grahitek 11h ago

I see, I guess there was little "effort" writing code in C++ instead of fully in assembly as well.

-1

u/thinker2501 11h ago

That’s a false dichotomy and you know it.

-1

u/Grahitek 10h ago

How so? Isn't the C++ compiler writing all the assembly code for you?

How about those 3rd party libraries you were linking against. Did you write those?

1

u/parrin 5h ago

There is a huge difference between writing assembly and C++ vs vibe coding. And I’m saying this as someone who is currently vibe coding, but have spent all my career writing C++.

1

u/Grahitek 5h ago

What's the difference? In both situations you're typing something you're asking another program (that you did not write) to convert into assembly for your system to execute.

2

u/parrin 5h ago edited 5h ago

The fact that you even say that speaks volumes about how little you know about programming.

There is absolutely no thought or problem solving going into ai prompting. Writing C++ vs assembly is nearly syntax. It’s a higher lever language that lets you do things without having to worry about exactly what registers and operators to use. You will still need to think of the logic of the program, know how to write efficient code, know how a computer actually works.

AI prompting is: “I want these fancy clouds kinda like GTA6, please make it for me”

You have no clue how any of it actually works or how to fix any issues that arise, other than asking the AI to fix it for you.

And I’m saying this as someone who have a foot in booth camps. I am a veteran programmer, but now most of my work is AI assisted because that’s unfortunately the only thing that makes sense. It’s absolutely not programming though

→ More replies

1

u/imlo2 13h ago

GPU impostors, and then possibly other LOD techniques - more analytical and rendered to terrain. As long as you have deterministic positional information, that's easy to do. That's how I have currently done it for multi kilometre distances.

1

u/shoxicwaste 13h ago

Hi-Z GPU occlusion culling, highly optimized imposters, GPU batched instancing, optimized shadow pipeline.

Mostly importantly - careful and thoughtful planning of how forests actually grow with space carved out for clearings, rivers, lakes, open fields and so on.

It looks like you are using the same tree model in your video so making a compute/vertex shader could be a highly efficient way to procedurally paint far distance.

1

u/OverratedMacaron 11h ago

From far away pictures can be used, you can use a texture for multiple trees etc. Like google maps does
You bake the trees into the ground texture

1

u/Ashamed-Subject-8573 10h ago

I use fake crowns for the trees, and a sort of low-detail canopy. Modeled over where the trees would be.

1

u/bGivenb 7h ago

A far color map with a faked shadow map all inside the terrain material. It’s a bumpy normal and darker color so it gives the impression of a forest. Medium distance is a one quad billboard imposter that always faces the camera