ianmackenzie / elm-3d-scene

A high-level 3D rendering engine for Elm, with support for lighting, shadows, and realistic materials.
https://package.elm-lang.org/packages/ianmackenzie/elm-3d-scene/latest/
Mozilla Public License 2.0
205 stars 26 forks source link

Add drawable packing #13

Open ianmackenzie opened 6 years ago

ianmackenzie commented 6 years ago

Add function that combines multiple meshes within a single Drawable into one big mesh, to reduce the number of total draw calls:

Drawable.pack : Drawable -> Drawable

Alternate names:

This means that the original vertex data must be retained for each leaf Drawable, so that multiple transformed drawables can all be converted into the same coordinate system before being converted back into one big WebGL mesh. One efficient way to do this would be to store vertex data in 'fat objects' with types such as

{ x : Float
, y : Float
, z : Float
, nx : Float
, ny : Float
, nz : Float
, r : Float
, g : Float
, b : Float
, rg : Float -- roughness
, mt : Float -- metallic
}

which could then be stored and transformed efficiently.

ianmackenzie commented 4 years ago

Useful reference: https://github.com/xeokit/xeokit-sdk/wiki/High-Performance-Model-Representation (thanks @pixelpartner!)

PixelPartner commented 4 years ago

xeokit even stores all vertex data on GPU for this mode, but allows neither textures nor vertex-colors as it also optimizes by reassigning instances for same drawcalls.