bevy icon indicating copy to clipboard operation
bevy copied to clipboard

UI node size in vertex shader

Open johnbchron opened this issue 1 year ago • 2 comments
trafficstars

What problem does this solve or what need does it fill?

Having access to the node's size in a UI material shader makes UI materials more useful. My use case is an SDF-based material, where the UVs are insufficient to build the SDF.

What solution would you like?

Add the node's size to vertex information being sent to the vertex shader, and propagate it in the default vertex shader and in UiVertexOutput.

What alternative(s) have you considered?

  • I have tried having a material per node and manually updating the size of each node in the materials each frame, but this is difficult to coordinate correctly and also leads to poor performance due to the number of materials.
  • To build an SDF shader, world-space position + UVs + node size is sufficient, and so is world-space position + UVs + world-space node center, but I think it makes the most sense to pass in the size of the node.

I'd be willing to submit a PR if needed.

johnbchron avatar Jan 17 '24 21:01 johnbchron

I had the same use case, and my solution was to propose a way to extend materials in #10816. That allowed me to add an instance vertex buffer with the nodes' size and other parameters I wanted on my custom material. That PR needs an example though :sweat_smile:

Davier avatar Jan 18 '24 15:01 Davier

I feel like this deserves a special case among the vertex data though, because any number of effects depend on being able to know the exact distance to the edge of the node.

johnbchron avatar Jan 18 '24 18:01 johnbchron