Skip to content

Optimize indexed face rendering with adaptive material strategies - #9

Draft
tritao wants to merge 3 commits into
FreeCAD:freecad-masterfrom
tritao:renderer-performance-fixtures
Draft

Optimize indexed face rendering with adaptive material strategies#9
tritao wants to merge 3 commits into
FreeCAD:freecad-masterfrom
tritao:renderer-performance-fixtures

Conversation

@tritao

@tritao tritao commented Aug 7, 2026

Copy link
Copy Markdown
Collaborator

Improve SoIndexedFaceSet rendering for opaque PER_FACE_INDEXED materials.

The renderer now analyzes referenced face materials and selects an appropriate strategy:

  • overall material for uniform referenced colors;
  • grouped material indexers for a small number of repeated colors;
  • unified coordinate/normal/color/index VBOs for high-cardinality materials;
  • existing fallback rendering for unsupported cases.

This is intended to reduce per-face material overhead while preserving indexed geometry and Coin-owned VBO management.

Related to FreeCAD/FreeCAD#31603.

Implementation

  • Analyze only materials referenced by the current face set.
  • Group faces by resolved packed color rather than material index.
  • Deduplicate unified vertices by coordinate, normal, and packed color.
  • Keep coordinate, normal, color, and index buffers separately cacheable.
  • Correct packed RGBA byte order for little-endian systems.
  • Reset Coin’s cached diffuse state after color-array rendering.
  • Include source node generations, pointers, counts, and color hashes in cache keys.
  • Preserve the referenced material when a uniform face set uses a nonzero material index.
  • Fall back for transparency, textures, custom vertex attributes, invalid material data, and unsupported topology.

The strategy selector and crossover thresholds are configurable through diagnostic environment variables:

COIN_FACE_MATERIAL_STRATEGY=auto|overall|grouped|unified|fallback
COIN_FACE_MATERIAL_MAX_GROUPS
COIN_FACE_MATERIAL_MIN_TRIANGLES_PER_GROUP
COIN_FACE_MATERIAL_MIN_UNIFIED_TRIANGLES
COIN_FACE_MATERIAL_MAX_UNIFIED_BYTES

Rendering statistics can optionally be written as JSON with:

COIN_RENDER_STATS_OUTPUT=<path>

Tests

Added Coin-native offscreen regression coverage for:

  • uniform nonzero material indices;
  • multiple material indices resolving to the same packed color;
  • asymmetric packed RGBA;
  • forced overall, grouped, unified, and fallback strategies;
  • automatic fallback for small high-cardinality geometry;
  • color, coordinate, normal, material-index, and coordinate-index mutations;
  • unified rejection for textures and custom vertex attributes;
  • transparent material fallback;
  • unified cache hits and rebuilds.

@tritao tritao self-assigned this Aug 7, 2026
@tritao tritao changed the title Optimize indexed face rendering with grouped materials Optimize indexed face rendering with adaptive material strategies Aug 7, 2026
@tritao
tritao force-pushed the renderer-performance-fixtures branch 2 times, most recently from fce7d10 to 4ff2be5 Compare August 7, 2026 13:06
@tritao
tritao force-pushed the renderer-performance-fixtures branch from 4ff2be5 to 2c5f645 Compare August 7, 2026 13:21
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