#Accessing ECS components from custom shader?

8 messages · Page 1 of 1 (latest)

hasty herald
#

I want to have one custom material+mesh that's instanced (potentially) millions of times, which then varies it's shading behaviour based on data in components attached to the per-instance entities.
From what I can tell, the only ways to do this are:

  • Create a new CustomMaterial component for every single instance and put my custom per-instance data in that. Which seems like it's going to preform badly
  • Use MeshTag to look up the per-instance data in a ShaderStorageBuffer. But then I need to manually manage that Storage Buffer myself, copying the data out of the ECS into the shader buffer whenever it changes (and defragging the Storage Buffer when instances are destroyed and created)

I feel like I'm missing something. Feels like there should be a way for Bevy to do this automatically, without me having to worry about manually managing storage buffers.

smoky shore
#

You need mesh tags and storage buffers

#

People often comment that there should be a way for bevy to do something automatically, and to that I say: complain when it hits 1.0. ATM every update to bevy contains major changes that will effect almost every project, it’s at the stage of making sure it can do things, not do them easily

#

May I enquire about the scenario though? If you have the same mesh instanced millions of times, there’s probably a more efficient way to get what you need

hasty herald
#

Yeah... I was considering simply throwing every single voxel at into the ECS for now, and then worry about optimising it into better data structures later, after profiling

#

but If I'm going to have to write custom code to manage storage buffers, I might as well start optimising early

hasty herald
#

IMO, it's more obviously missing when you are dealing with tens of instances. Because you still want them all to be batched into the same draw call, but the numbers are too low to justify writing a manual storage management system for them

smoky shore
#

Well, bevy automatically batches entities that share a mesh and a material