nmfisher / thermion

3D rendering toolkit for Dart and/or Flutter
https://thermion.dev
Apache License 2.0
115 stars 9 forks source link

Custom shader & runtime material switching support #64

Open kerberjg opened 1 month ago

kerberjg commented 1 month ago

AFAIK Filament supports custom shader compilation/rendering, but I haven't found any references to it in Thermion's docs.

Is it something that has been experimented with? Can they be loaded as part of the GLTF/GLB format? (assuming that's supported)

I'm happy to help out on this if needed 🤗✨

nmfisher commented 1 month ago

Thanks for bringing this up, it's something I've wanted to look at more closely. Currently, you can only load custom materials:

The latter isn't a very flexible option, because then you're basically stuck with one set of materials for the lifetime of the viewer (though in some cases, maybe that's all you need).

Ideally, I think you should probably be able to 1) expose a function like createMaterialProvider(String path) to load materials from filamat files, and 2) accept a materialProvider parameter to loadGlb/loadGltf to specify a custom material for the asset (or fall-back to the ubershader if none is provided). This would probably also need to expose the whole MaterialInstance interface to the Dart bindings.

Can you give me more details about how you'd like to use custom materials?

kerberjg commented 1 month ago

Sure! I'd like to be able to load material definition files (as per Filament docs) on a per-entity basis at runtime. AFAIK right now the only way to set a material on an entity is when creating the GLB/GLTF file, as the materials are embedded. Another thing would be allowing the developers to change the material's properties at runtime as well.

I understand these need to be compiled with matc, so ideally Thermion would define a Flutter asset transformer to run on those material files at build-time.

I made sure to link relevant documentation above, I hope it's helpful 😊