Best approach for accessing DrawCommands from custom RendererFeatures?
Hi! I realize this isn't exactly "supported" but I'm wondering if there's a minimally-hacky way to pull this off?
CONTEXT:
- I'm adding Shapes to a game that makes extensive use of custom RendererFeatures and ScriptableRenderPasses in URP
- Different groups of geometry are associated with different "compositing layers" (not Unity's layer bitmasks, more like Photoshop layers)
- ScriptableRenderPasses filter the scene geometry and draw each group into different rendertextures, which are later composited together
- I would like to use Shapes' Immediate Mode API, but draw into specific compositing layers
PROBLEM:
I can make my own version of ShapesRenderFeature easily enough, but each camera just has a list of DrawCommands in a dictionary. There's no way for an ImmediateModeShapeDrawer to "tag" a DrawCommand with any additional information; it just appends its commands to the camera's list, making them effectively anonymous.
Thus, I can only make one pass that renders all the DrawCommands, but what I need is multiple passes that each render different subsets of DrawCommands into different targets.
POSSIBLE SOLUTIONS:
- Skip the Draw.Command(cam) block and create/manage my own lists of DrawCommands? This seems Very Dangerous, given all the internal static state-management stuff that DrawCommand does.
- Inside of a Draw.Command(cam) block, somehow(?) obtain a reference to the current DrawCommand and add it to a "which DrawCommands go in which layers" table, which the RenderPasses can access? This also seems risky, since the lifecycle of DrawCommands looks pretty complex.
- Put a bunch of disabled Cameras in the scene, one for each compositing layer, and add my DrawCommands to whichever one is relevant? The cameras wouldn't actually DRAW anything, they'd exist solely as dictionary keys so that the RenderPasses can look up their associated DrawCommand lists. This would probably work, but also I hate it lol (the whole point of custom rendererfeatures is to *avoid* having dozens of disabled cameras in the scenegraph)
THUS:
Is there a least-worst option here?
Or is this whole problem just fundamentally at odds with Shapes' way of doing things
sorry for seeing this so late!
I've kinda suppressed and forgotten most of the knowledge I used to have in how I got all this up and running bc the SRP situation was a nightmare (:
Spontaneously I feel like you should be able to use/hijack/mimic Draw.Command's second parameter and use that as your tagging system for saying which "layer" it should draw into (rather than which order it should draw in, which is kind of a similar use case), but I'm not sure how that works with execution order within your custom render features, or if you'd need to duplicate/add/change the shapes render feature