Skip to content

perf: Render ground-aligned particles without sorting#2831

Closed
stephanmeesters wants to merge 1 commit into
mainfrom
perf/ground-aligned-particles-nosort
Closed

perf: Render ground-aligned particles without sorting#2831
stephanmeesters wants to merge 1 commit into
mainfrom
perf/ground-aligned-particles-nosort

Conversation

@stephanmeesters

@stephanmeesters stephanmeesters commented Jun 27, 2026

Copy link
Copy Markdown

A performance gain (about 8%) could be achieved in a busy scene, see animated gif below, by not sorting particles that are "ground-aligned". (tested in release mode, windowed, stats averaged in 60 secs window)

The reasoning is that ground-aligned particles generally do not have much benefit from back to front sorting, as they are effectively on the ground with nothing behind them, and other nearby ground-aligned particles are at about the same height.

In testing this actually appeared to resolve some rendering issues as ground particles would sometimes cut into nearby particles leaving hard edges (see the before image).

sorting-renderer.webm

Todo

  • Do some more testing, in campaign etc

@greptile-apps

greptile-apps Bot commented Jun 27, 2026

Copy link
Copy Markdown

Greptile Summary

This PR skips back-to-front sorting for ground-aligned (non-billboard) particles by prepending a Billboard && guard to the sort condition in PointGroupClass::Render. The rationale is that flat ground particles gain little from depth sorting and the change also resolves visible hard-edge artefacts where ground particles cut into one another.

  • sort condition change: Billboard && short-circuits sorting for any particle whose Billboard flag is false, routing those draw calls through the regular (non-sorting) render path and moving their geometry out of the sorting renderer's budget.
  • Comment block: A // TheSuperHackers @perf attribution comment is added above the modified line; three of the four new comment lines use 2-space indentation instead of the file's tab style.

Confidence Score: 4/5

The change is safe to merge; the only finding is a cosmetic mixed-indentation issue in the new comment block.

The logic is a straightforward one-flag guard on a boolean that is already used in the same function to control transform behaviour. Ground-aligned particles routed through the regular draw path rather than the sorting renderer is the stated and visually confirmed intent. No sorting-path code is removed — billboard particles continue to sort as before.

No files require special attention; the single changed file has a trivial indentation inconsistency in the new comments.

Important Files Changed

Filename Overview
Core/Libraries/Source/WWVegas/WW3D2/pointgr.cpp Skips back-to-front sorting for non-billboard (ground-aligned) particles by short-circuiting on Billboard == false; logic is sound, minor mixed tabs/spaces in the new comment block.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A[PointGroupClass::Render] --> B{Billboard?}
    B -- false\nground-aligned --> C[sort = false]
    B -- true\nbillboard --> D{DST blend != ZERO?}
    D -- false --> C
    D -- true --> E{Alpha test disabled?}
    E -- false --> C
    E -- true --> F{Sorting enabled?}
    F -- false --> C
    F -- true --> G[sort = true]
    C --> H[Regular DX8 draw call\nDYNAMIC_DX8 buffer]
    G --> I[Sorting renderer draw call\nDYNAMIC_SORTING buffer]
Loading
%%{init: {'theme': 'base', 'themeVariables': {"darkMode": true, "background": "#0d1117", "primaryColor": "#21262d", "primaryTextColor": "#e6edf3", "primaryBorderColor": "#8b949e", "lineColor": "#8b949e", "textColor": "#e6edf3", "edgeLabelBackground": "#161b22", "actorBkg": "#21262d", "actorBorder": "#8b949e", "actorTextColor": "#e6edf3", "actorLineColor": "#8b949e", "signalColor": "#8b949e", "signalTextColor": "#e6edf3", "noteBkgColor": "#373320", "noteBorderColor": "#d4a72c", "noteTextColor": "#f0e6c0", "labelBoxBkgColor": "#21262d", "labelBoxBorderColor": "#8b949e", "labelTextColor": "#e6edf3", "loopTextColor": "#e6edf3", "activationBkgColor": "#30363d", "activationBorderColor": "#8b949e"}}}%%
flowchart TD
    A[PointGroupClass::Render] --> B{Billboard?}
    B -- false\nground-aligned --> C[sort = false]
    B -- true\nbillboard --> D{DST blend != ZERO?}
    D -- false --> C
    D -- true --> E{Alpha test disabled?}
    E -- false --> C
    E -- true --> F{Sorting enabled?}
    F -- false --> C
    F -- true --> G[sort = true]
    C --> H[Regular DX8 draw call\nDYNAMIC_DX8 buffer]
    G --> I[Sorting renderer draw call\nDYNAMIC_SORTING buffer]
Loading
Prompt To Fix All With AI
Fix the following 1 code review issue. Work through them one at a time, proposing concise fixes.

---

### Issue 1 of 1
Core/Libraries/Source/WWVegas/WW3D2/pointgr.cpp:929-932
The new annotation and comment lines use 2-space indentation while the rest of the function body (and every other `// TheSuperHackers @...` annotation in the codebase) uses tabs. This creates mixed indentation within the block.

```suggestion
	// TheSuperHackers @perf stephanmeesters 27/06/2026
	// Enable sorting if the primitives are translucent and alpha testing is not enabled.
	// However, do not apply sorting for ground-aligned (i.e. non-billboard) particles.
	// This is for performance reasons and because ground-aligned particles do not generally benefit from back-to-front sorting.
```

Reviews (1): Last reviewed commit: "perf: Render ground-aligned particles wi..." | Re-trigger Greptile

@stephanmeesters stephanmeesters deleted the perf/ground-aligned-particles-nosort branch June 28, 2026 11:31
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.

1 participant