komadori / bevy_mod_outline

Apache License 2.0
123 stars 10 forks source link

Add support for RenderLayers to determine which views an outline is visible on #8

Closed mxgrey closed 1 year ago

mxgrey commented 1 year ago

Thanks for this amazing crate! I've used it to massively improve the user experience for a bevy application that I'm working on.

However I have a use case with multiple views where I want the user view to see the whole world plus extra visual cues (including outlines that I'm generating with bevy_mod_outline) while other views are supposed to simulate the viewpoint of a real physical camera that can only see real physical objects and not any visual cues.

I'm still using Bevy 0.8 so I've implemented my feature suggestion on branch outline_render_layers_v0.2 of my fork. I'll be happy to open a PR for it if you can create a branch in your repo that builds off of v0.2.4. Here's a before and after screenshot of my application, to give an idea of why I'm doing this:

BEFORE (notice that the desks are outlined in the right-hand view which is supposed to data from a simulated physical camera) outline_before

AFTER (notice that the right-hand view no longer has any outlines in it, while the user-camera on the left still does) outline_after

My approach was to define a new optional component OutlineRenderLayers that can be added alongside the Outline component. The OutlineRenderLayers component will be extracted in the render stage and then compared against the RenderLayers component of each view before adding the outline to its render queue. Since this is introducing a new optional component it should be fully API compatible with 0.2.4.

I suspect the same technique could be used for v0.3, but I haven't migrated my application to Bevy 0.9 yet so I wouldn't be able to test it out.

komadori commented 1 year ago

This approach seems reasonable. I had thought about having a per-View component to offer control over the outline scaling, which could also offer the opportunity to disable outlines, but I suppose render-layers are more generic.

Also, even in the absence of OutlineRenderLayers, the plugin should probably still respect RenderLayers. This isn't checked at the moment, neither ComputedVisibility::is_visible_in_hierarchy() for that matter.

Are you looking for a new crate release in the 0.2.x or series, or just this functionality going forward for when you upgrade to Bevy 0.9?

mxgrey commented 1 year ago

I would definitely appreciate a new release in 0.2.x so I can move my application off of a dependency on my custom branch. And since the solution is fully semver compatible I think it'll be a nice free-lunch upgrade for the 0.2 series.

mxgrey commented 1 year ago

Also, even in the absence of OutlineRenderLayers, the plugin should probably still respect RenderLayers.

I don't know for sure if I've fully wrapped my head around the implementation of outlines, but from what I do understand I would recommend keeping RenderLayers and OutlineRenderLayers separate for the entities that are being rendered. That way a user could choose to give the outline a render layer setting that is different from the mesh's render layer setting. I imagine there could be some creative use cases where that's desirable.

komadori commented 1 year ago

Ok, I've created a 0.2.x branch for you to submit a PR against: https://github.com/komadori/bevy_mod_outline/tree/release-0.2.x

komadori commented 1 year ago

Accepted #9. I'll port it to 0.3.x, probably write a new example, and should be able to make a release in a day or two.

komadori commented 1 year ago

render_layers example: render_layers

komadori commented 1 year ago

Released 0.2.5 and 0.3.2.