[Terrain] How to deal with interdependent component properties #10800
Labels
needs-triage
Indicates an issue or PR lacks a `triage/foo` label and requires one.
sig/ui-ux
Categorizes an issue or PR as relevant to SIG UI-UX.
Projects
There are several situations that have come up in terrain where changing one component property can cause a separate property (sometimes on a different component) to no longer be in a reasonable range. In the best case this will just lead to visual artifacts, but sometimes this can also lead to a crash.
To start with, a quick overview of the main components in question.
Terrain World
This component is the top level terrain system component. It sets global properties and helps keep different terrain systems in sync. For instance, "query resolution" is used by physics and rendering to make sure the geometry they create is based on the same positions without needing to be aware of each other.
Terrain World Renderer
This component controls all the rendering related properties - basically how the terrain will look to the user. The order is admittedly pretty random.
Interdependencies
The main problem we run into is how the query resolution settings affect everything. For instance a query resolution of 1.0 with a first LOD distance of 500 meters means each LOD will have roughly 1 million vertices. (1km x 1km area, so 1000 x 1000 points).
![image](https://user-images.githubusercontent.com/1105143/180275261-965c9ca9-39c7-4477-9afd-78776eca2e87.png)
This is a lot, but is fine on modern graphics cards. However if the query resolution were turned down to 0.1, then this would be 10000x10000, or 100,000,000 vertices, which would likely cause significant performance degradation or probably crash. However, if the first LOD distance was just 50 meters, then a query resolution of 0.1 would be equivalent to the first example, and work just fine.
Possible crashes
Height query resolution◀️ ▶️ First LOD distance
Decreasing Height query resolution too much while First LOD distance is large or increasing the First LOD distance too much while Height query resolution is small could increase the number of vertices required to go beyond system limits and cause a crash.
Height query resolution◀️ ▶️ Mesh render distance
Decreasing Height query resolution too much while Mesh render distance is large or increasing the Mesh render distance too much while Height query resolution is small could increase the number of vertices required to go beyond system limits and cause a crash.
First LOD distance◀️ ▶️ Mesh render distance
Increasing First LOD distance too much while Mesh render distance is large or increasing the Mesh render distance too much while First LOD distance is large could increase the number of vertices required to go beyond system limits and cause a crash.
Surface Query Resolution◀️ ▶️ Detail material render distance
Decreasing Surface query resolution too much while Detail material render distance is large or increasing the Detail material render distance too much while Surface query resolution is small could increase the size of the detail material id texture beyond system limits and cause a crash.
Unexpected behavior which shouldn't cause a crash
These interactions are purely inside the terrain rendering component, so we may be able to find a more elegant solution than the cross-component interactions.
Detail material fade distance◀️ ▶️ Detail material rendering distance
Setting Detail material fade distance too high relative to Detail material rendering distance could cause visual artifacts because the detail material won't have enough space to finish fading out before the end of detail material rendering.
Possible Workaround: Change Detail material fade distance to a percentage based control, so the last x% of the total distance fades out. This would also keep the look visually consistent as Detail material rendering distance changed.
First LOD distance◀️ ▶️ CLOD distance
Setting CLOD distance too high relative to First LOD distance could cause visual artifacts because the continuous lod won't have enough space to finish its blending before the LOD switches. Generally this needs to be about 25% the size of the First LOD distance but actually depends on a combination of the First LOD distance and Height query resolution to determine the maximum possible safe CLOD distance
Possible Workaround: Change CLOD distance to a percentage based control, so a percentage of the maximum fade size is used. This would also keep the look visually consistent as First LOD distance changed.
Settings that should clamp to each other
Some of the distance settings should logically be constrained by other distance settings, but otherwise don't cause technical issues. They can be edited in either order, so it's unclear what should happen when a user tries to break the constraint.
Mesh Render Distance >= First LOD Distance : The terrain will only ever render as far as Mesh Render Distance so breaking this rule means that the whole terrain will be the First LOD.
Mesh Render Distance >= Detail material rendering distance : Breaking this rule means that detail materials will be processed for areas of terrain that aren't visible.
Detail material rendering distance >= Detail material fade distance : Breaking this rule means that the detail materials start fading out right next to the camera (for instance if the fade distance was 2x the render distance, detail materials right next to the camera would already by 50% faded)
Clipmap settings
In short, clipmaps can be considered a special set of mipmaps that gathers all the material info into different resolution, and is used in rendering to improve performance.
Namings
The namings are a bit wordy and have duplication parts beyond macro/detail.
Interdependencies
Clipmap config has 2 dependencies on Detail material render distance and Mesh render distance (highlighted in red in the screenshot). They are used to set the max render radius in the clipmap stack, so that it knows how far the terrain texture are rendered.
The problem here is how we want to manage the layout of the settings and maybe better names to indicate what they actually control.
Possible crashes
Clipmap can cause crash when it generate too many layers. The number of layers are auto calculated based on:
This can cause too many layers of clipmap generated at certain settings, and we won't be able to afford performance wise and memory wise.
A solution is to replace scale to number of layers directly, and figure out the scale in the code. Then it will never crash. But the number of layers are not something the user wants to care about. Instead, it is easier to understand using scale because we know regular mipmap has a scale of 2.
The text was updated successfully, but these errors were encountered: