Automatically add default blend/base style pairs #719
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR attempts to ease another common pain point with blend modes, as a follow-up to enabling
blend_orderto be set at thedrawlevel in #703.In this case, the goal is to make it easier to use the different
blendmodes without having to write boilerplate styles. However, this PR takes a different approach than was used forblend_order. For each combination ofblendmode (opaque,overlay, etc.) and stylebase(polygons,lines, etc.), a style is automatically created at scene load-time with the naming schemeblend_base, e.g.translucent_polygons,overlay_lines, etc. Each of these is a minimal style definition, such as (if expressed in YAML):In effect the PR expands the set of built-in styles by bootstrapping them with the existing custom style system.
To maintain backwards compatibility, any of these bootstrapped styles is skipped if the user has already defined one with the same name.
Ideally, we would be consistent and also enable setting
blendat thedrawlevel, but this is a much more involved change due to several assumptions baked into rendering styles, e.g. each style has a single shader program, and the shaders have several#definesor other logic dependencies based on theblendmode (by comparison,blend_orderonly affects the CPU-side render order).From a usage standpoint, it's arguably much more useful to set
blend_orderindraw, to re-order sets of features based on filters, while for blend modes it's more an issue of simply wanting to be able to use them quickly/naturally without having to first go write a boilerplate (and this enables them to effectively be set in adrawgroup with thestylekeyword).This change has a low run-time cost. There's some parsing for these additional styles at scene load-time, but it's minimal since they contain no mixing or shader blocks. Since we now have robust on-demand shader compilation and caching by shader/program source, there should be no impact for unused styles. The main downside is that they can "pollute" the style namespace when debugging or examining all of a scene's styles programmatically.