Skip to content

Bump MAX_CELLS_TO_RENDER#338

Merged
JeodC merged 1 commit intoDescentDevelopers:mainfrom
JeodC:renderdistance
May 13, 2024
Merged

Bump MAX_CELLS_TO_RENDER#338
JeodC merged 1 commit intoDescentDevelopers:mainfrom
JeodC:renderdistance

Conversation

@JeodC
Copy link
Collaborator

@JeodC JeodC commented May 12, 2024

Pull Request Type

  • GitHub Workflow changes
  • Documentation or Wiki changes
  • Build and Dependency changes
  • Runtime changes
    • Render changes
    • Audio changes
    • Input changes
    • Network changes
    • Other changes

Description

Bump max cells to 32678 from 8000, allowing a much larger render distance for outdoor terrain. This commit also fixes MAX_HORIZON_PIECES, which may have been broken during a clang-format.

Testing on Level 7 yielded no performance loss, and in fact revealed an existing bug with z-ranges where blue electricity effects from disabled turrets are visible overtop of terrain.

image

Related Issues

Fixes #280

Bump max cells to 32678 from 8000, allowing a much larger render distance for outdoor terrain. This commit also fixes MAX_HORIZON_PIECES, which may have been broken during a clang-format.
@Lgt2x
Copy link
Member

Lgt2x commented May 13, 2024

It's unclear to me without diving in the rendering code why decreasing the maximum number of horizon pieces increases the render distance. What happens there?

@JeodC
Copy link
Collaborator Author

JeodC commented May 13, 2024

It's unclear to me without diving in the rendering code why decreasing the maximum number of horizon pieces increases the render distance. What happens there?

The horizon distance change has nothing to do with the render distance. In the current terrain.h file though it looks like this:

// Sky defines
#define MAX_STARS 600    // how many stars in our sky
#define MAX_SATELLITES 5 // max satellites in our sky
#define MAX_HORIZON_PIECES                                                                                             \
  16 // how many segments of the horizon
     // there are around our sphere

The change just brings it inline like the rest. I'm not sure if it was broken or not, with the random backslash after a ton of spaces, but it was inconsistent.

@Lgt2x
Copy link
Member

Lgt2x commented May 13, 2024

I was talking about the MAX_CELLS_TO_RENDER change, sorry. The other change is fine.

@JeodC
Copy link
Collaborator Author

JeodC commented May 13, 2024

I was talking about the MAX_CELLS_TO_RENDER change, sorry. The other change is fine.

It's an increase, not a decrease. Original value was 8000, and in TerrainSearch.cpp:

  if (*ccount >= MAX_CELLS_TO_RENDER) {
    mprintf((0, "Trying to render too many cells!  Cell limit=%d\n", MAX_CELLS_TO_RENDER));
#ifndef NEWEDITOR
    Detail_settings.Terrain_render_distance = 80.0 * TERRAIN_SIZE;
#endif
    return;
  }

That's within the CheckCellOccupancy function. If it evaluates to true, it stops rendering the terrain cells. If it's false, terrain gets rendered. The problem is that if it does evaluate to true, the game's render depth setting gets reset to 40--even if the player had it at 100. The solution to the issue is to increase the MAX_CELLS_TO_RENDER variable--it's unclear why it was set to such a low value in the first place. The alternative is to comment out this safety check entirely, which would allow excessive rendering and potential stability issues.

It's also used in static ushort LOD_sort_bucket[MAX_TERRAIN_LOD][MAX_CELLS_TO_RENDER]; -- increasing the value increases the capacity of this array, which lets it store more cells for rendering.

@JeodC
Copy link
Collaborator Author

JeodC commented May 13, 2024

Here's a screenshot of the same level from the retail edition:

image

@Lgt2x
Copy link
Member

Lgt2x commented May 13, 2024

Thanks for the clear explanation!

@JeodC JeodC merged commit 07262f6 into DescentDevelopers:main May 13, 2024
@JeodC JeodC deleted the renderdistance branch May 13, 2024 13:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Runtime Issue]: Render depth resets to lowest on map edge

2 participants