perf: Render ground-aligned particles without sorting#2838
perf: Render ground-aligned particles without sorting#2838stephanmeesters wants to merge 1 commit into
Conversation
|
| Filename | Overview |
|---|---|
| Core/Libraries/Source/WWVegas/WW3D2/pointgr.cpp | Adds Billboard && guard to the sort condition in Render, skipping sorting for ground-aligned particles. The parallel sort condition in RenderVolumeParticle (line 1845) was not updated, leaving that path inconsistent with the new behavior. |
Flowchart
%%{init: {'theme': 'neutral'}}%%
flowchart TD
A[Particle Render Request] --> B{depth > 1?}
B -- No --> C[Render]
B -- Yes --> D[RenderVolumeParticle]
C --> E{Billboard?}
E -- No --> F[sort = false\nSkip sorting NEW]
E -- Yes --> G{Translucent & sorting enabled?}
G -- Yes --> H[sort = true\nSortingRenderer path]
G -- No --> I[sort = false\nDirect draw path]
D --> J{Billboard?}
J -- No --> K[sort = still checks shader only\n Not updated]
J -- Yes --> L{Translucent & sorting enabled?}
L -- Yes --> M[sort = true\nSortingRenderer path]
L -- No --> N[sort = false\nDirect draw path]
%%{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[Particle Render Request] --> B{depth > 1?}
B -- No --> C[Render]
B -- Yes --> D[RenderVolumeParticle]
C --> E{Billboard?}
E -- No --> F[sort = false\nSkip sorting NEW]
E -- Yes --> G{Translucent & sorting enabled?}
G -- Yes --> H[sort = true\nSortingRenderer path]
G -- No --> I[sort = false\nDirect draw path]
D --> J{Billboard?}
J -- No --> K[sort = still checks shader only\n Not updated]
J -- Yes --> L{Translucent & sorting enabled?}
L -- Yes --> M[sort = true\nSortingRenderer path]
L -- No --> N[sort = false\nDirect draw path]
Comments Outside Diff (2)
-
Core/Libraries/Source/WWVegas/WW3D2/pointgr.cpp, line 1844-1845 (link)Incomplete optimization in
RenderVolumeParticleThe
sortcondition inRenderVolumeParticle(line 1845) was not updated with theBillboard &&guard introduced inRender. Any ground-aligned (non-billboard) volume particles withdepth > 1will still be sorted, sinceRenderVolumeParticleonly delegates toRenderwhendepth <= 1. The two code paths will diverge in behavior for the same particle emitter depending on the depth setting.Prompt To Fix With AI
This is a comment left during a code review. Path: Core/Libraries/Source/WWVegas/WW3D2/pointgr.cpp Line: 1844-1845 Comment: **Incomplete optimization in `RenderVolumeParticle`** The `sort` condition in `RenderVolumeParticle` (line 1845) was not updated with the `Billboard &&` guard introduced in `Render`. Any ground-aligned (non-billboard) volume particles with `depth > 1` will still be sorted, since `RenderVolumeParticle` only delegates to `Render` when `depth <= 1`. The two code paths will diverge in behavior for the same particle emitter depending on the depth setting. How can I resolve this? If you propose a fix, please make it concise.
-
Core/Libraries/Source/WWVegas/WW3D2/pointgr.cpp, line 1840-1845 (link)The same
Billboard &&guard should be applied here to keepRenderVolumeParticleconsistent with the updatedRenderpath.Prompt To Fix With AI
This is a comment left during a code review. Path: Core/Libraries/Source/WWVegas/WW3D2/pointgr.cpp Line: 1840-1845 Comment: The same `Billboard &&` guard should be applied here to keep `RenderVolumeParticle` consistent with the updated `Render` path. How can I resolve this? If you propose a fix, please make it concise.
Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!
Prompt To Fix All With AI
Fix the following 2 code review issues. Work through them one at a time, proposing concise fixes.
---
### Issue 1 of 2
Core/Libraries/Source/WWVegas/WW3D2/pointgr.cpp:1844-1845
**Incomplete optimization in `RenderVolumeParticle`**
The `sort` condition in `RenderVolumeParticle` (line 1845) was not updated with the `Billboard &&` guard introduced in `Render`. Any ground-aligned (non-billboard) volume particles with `depth > 1` will still be sorted, since `RenderVolumeParticle` only delegates to `Render` when `depth <= 1`. The two code paths will diverge in behavior for the same particle emitter depending on the depth setting.
### Issue 2 of 2
Core/Libraries/Source/WWVegas/WW3D2/pointgr.cpp:1840-1845
The same `Billboard &&` guard should be applied here to keep `RenderVolumeParticle` consistent with the updated `Render` path.
```suggestion
DX8Wrapper::Set_Material(PointMaterial);
DX8Wrapper::Set_Shader(Shader);
DX8Wrapper::Set_Texture(0,Texture);
// 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.
const bool sort = Billboard &&
Shader.Get_Dst_Blend_Func() != ShaderClass::DSTBLEND_ZERO &&
Shader.Get_Alpha_Test() == ShaderClass::ALPHATEST_DISABLE &&
WW3D::Is_Sorting_Enabled();
```
Reviews (3): Last reviewed commit: "perf: Render ground-aligned particles wi..." | Re-trigger Greptile
fdcebaf to
45a97a7
Compare
|
@greptileai It should not apply to RenderVolumeParticle as these are layered particles that require sorting |
|
The current PR diff only modifies To guard against that, it would be worth adding a short comment in |
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