Hacktoberfest 2026: los issues que los mantenedores marcaron para octubre, abiertos y aptos para principiantes. Explorar issues de Hacktoberfest

[flame_3d] Support instanced drawing of repeated meshes

Abierto
#4,157 0 comentarios 0 reacciones 0 asignados Ver en GitHub

Los mantenedores suelen responder en 1 día

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
5/5
Tiempo estimado
Más de una semana
Aptitud para principiantes
35/100
Tipo de issue
Nueva funcionalidad
Claridad
Bastante claro
Estado de actividad
Activo
Stack tecnológico
dart

Línea de trabajo

Start by reading the flame_3d rendering backend and RenderContext3D, then check how flutter_gpu exposes instance-rate vertex layouts and instance counts. The issue proposes backend support, shader changes, and either an explicit game API or automatic grouping, so first agree on the API and scope with maintainers. Done means repeated compatible meshes can be drawn with instancing while existing and skinned rendering paths continue to work.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

Problem to solve

Every surface in flame_3d is drawn with its own draw call, even when the same mesh with the same material is repeated many times in a scene: trees, grass tufts, fences, rocks, crowds. Each draw rebinds the pipeline, the uniforms and the geometry, and on mobile that per-draw CPU cost, on the Dart side and in flutter_gpu's command encoding, quickly dominates the frame.

flutter_gpu now has what is needed to draw such meshes once: vertex layouts with instance-rate buffers (VertexLayout, VertexStepMode.instance) and draw/drawIndexed with an instanceCount. flame_3d has no way to use them today.

Proposal

A backend layer that changes nothing for existing code:

  • GpuBackend.createInstancedPipeline({vertexShader, fragmentShader, layout}), returning null when the backend cannot instance (the WebGPU backend could start there).
  • GpuInstanceLayout, describing the per-vertex attributes of the surface buffer and the per-instance attributes (stride and named attributes for each).
  • GpuInstancedRenderPass.drawInstances(ByteData instances, int instanceCount), implemented by the flutter_gpu render pass by emplacing the instance data in the host buffer and binding it as the second vertex buffer.
  • GraphicsDevice.supportsInstancing, true only while a pass that supports it is open, and GraphicsDevice.bindInstancedGeometry(surface, instances, instanceCount).

On the shader side, an instanced variant of the built-in vertex shaders that reads the model matrix from four per-instance vec4 attributes instead of VertexInfo.model. Skinned surfaces would keep the regular path.

The open question is how games would use it:

  1. An explicit API, such as a component or a method taking one mesh and a list of transforms.
  2. Automatic grouping in RenderContext3D: draws captured during a pass are grouped by surface, and a group is drawn instanced when every member shares the same material and the same material state. Anything else, including alpha-blended surfaces that must stay depth-sorted, is drawn as today.

Option 2 needs no change in games but adds bookkeeping to every frame. Option 1 is more predictable. Both could build on the same backend layer, which could also land first on its own.

More information

We implemented the backend layer and option 2 in a 3D engine built on flame_3d, with its own material. In a village scene measured on an AYN Thor (Android handheld), 165 repeated decor draws became 17 instanced draws, and the UI thread time per frame (Animator::BeginFrame) went from 7.0 ms to 5.1 ms. The flutter_gpu instancing API was used with Flutter 3.47.5.

Limits of that first version: only the model matrix varies per instance, and instanced groups are drawn after the other opaque draws of the pass, which depth testing makes invisible for opaque and alpha-tested surfaces.

I'd be happy to port it as a PR, starting with whichever part and shape you prefer.

Lenguaje dominante
Dart
Estrellas
10.8k
Forks
1.1k
Merge medio
1 d 21 h
PR fusionados (30 d)
52

Preparar el entorno

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de flame-engine/flame

Todos los issues de flame-engine/flame

Issues similares

Más issues de Dart

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.