Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Terrain] How to deal with interdependent component properties #10800

Open
invertednormal opened this issue Jul 21, 2022 · 1 comment
Open

[Terrain] How to deal with interdependent component properties #10800

invertednormal opened this issue Jul 21, 2022 · 1 comment
Assignees
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.

Comments

@invertednormal
Copy link
Contributor

invertednormal commented Jul 21, 2022

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

image
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.

  • World Bounds The XYZ bounds of the world. Soon the XY bounds will go away and we'll only need the Z bounds which affects the position and scaling of the height of the terrain.
  • Height Query Resolution A terrain system wide standard for the spacing between terrain height points. For instance, if this is set to 1.0, then the renderer, physics, etc, will all query height positions in 1 meter increments.
  • Surface Data Query Resolution Similar to Height Query Resolution, this is the system wide standard for spacing between surface data points, which affects things like detail materials.

Terrain World Renderer

image
This component controls all the rendering related properties - basically how the terrain will look to the user. The order is admittedly pretty random.

  • Height based texture blending - Controls how detail materials blend with each other. When this is turned on, heights are taken into account to provide more realistic material blending.
  • Detail material render distance - How far from the camera (in meters) the detail materials will render
  • Detail material fade distance - The distance over which the detail materials will fade out to the macro material
  • Detail material scale - A global scale modifier to the terrain detail textures.
  • Mesh render distance - How far from the camera (in meters) the terrain will render.
  • First LOD distance - How far from the camera (in meters) the highest LOD terrain will render before transitioning to the next LOD. Subsequent LOD transitions double the distance. For instance, if First LOD distance is 100m, then the second lod will end at 200m, the third at 400m, then 800m, 1600m, 3200m etc until there are enough LOD levels to cover the entire Mesh render distance
  • Continuous LOD (CLOD) - turns on a feature that blends each LOD into the next so transitions between terrain mesh LODs are hard to notice.
  • CLOD Distance - the distance over which CLOD fades. For instance, if the First LOD distance is 100m and CLOD distance is 25 meters, then the first lod will render normally until 75 meters from camera, then over the next 25 meters it'll smoothly transition to the second LOD, then at 100 meters it will look like the second lod.

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
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

clipmap settings
Capture
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.

  • Clipmap image size - The size of the clipmap image in each layer.
  • Macro clipmap max resolution: texels/m & Detail clipmap max resolution: texels/m - The resolution of the highest resolution clipmap in the stack.
  • Macro clipmap scale base & Detail clipmap scale base - The scale base between two adjacent clipmap layers. For example, 3 means the (n+1)th clipmap covers 3^2 = 9 times the area covered by the nth clipmap.
  • Macro clipmap margin size: texels & Detail clipmap margin size: texels - The margin of the clipmap beyond the visible data. Increasing the margins results in less frequent clipmap updates but also results in lower resolution clipmaps rendering closer to the camera.

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:

  1. how clear we want to have at the closest distance (max resolution)
  2. how far we want to render using the clipmap (max render distance, using the inter dependencies)
  3. the scale between each clipmap (how much area the adjacent clipmap will cover growing at a constant rate)
    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.
@invertednormal invertednormal added 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. labels Jul 21, 2022
@rainbj rainbj added this to Needs Triage in O3DE UX Roadmap via automation Jul 21, 2022
@rainbj rainbj moved this from Needs Triage to Accepted in O3DE UX Roadmap Jul 21, 2022
@rainbj
Copy link

rainbj commented Jul 21, 2022

Adding design document link to work through details - https://www.figma.com/file/RtuizO1WSkfOJJh24vAgb9/Large-worlds?node-id=0%3A1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
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
O3DE UX Roadmap
Accepted - Jira needed
Development

No branches or pull requests

4 participants