-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* WIP add new blend mode * WIP add cover blend mode * fix uint24 rendering in merge mode - and add ui to switch rendering modes * remove unused imports * rename to render mode to blend mode * improve in line comments * decide whether a color is valid by alpha < 0. - Fix layer precedence order. * multiple fixes in cover blend mode - fix uint24 rendering - fix rendering layers below if the the upper layer has no data yet - fix color and opacity setting in cover blend mode * fix reading blendmode from backend on inital load * refactoring & make changes ready for review * add changelog entry * add blend mode setting to docs * Apply suggestions from code review Co-authored-by: Philipp Otto <[email protected]> * refactor shader code for blending - make clear that the blend mode only applies to color layers excluding segment layers --------- Co-authored-by: Philipp Otto <[email protected]>
- Loading branch information
1 parent
a7bbbef
commit d338889
Showing
14 changed files
with
125 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import type { ShaderModule } from "./shader_module_system"; | ||
export const getBlendLayersAdditive: ShaderModule = { | ||
code: ` | ||
vec4 blendLayersAdditive( | ||
vec4 current_color, | ||
vec4 color_to_add | ||
) { | ||
return current_color + color_to_add; | ||
} | ||
`, | ||
}; | ||
|
||
export const getBlendLayersCover: ShaderModule = { | ||
code: ` | ||
// Applying alpha blending to merge the layers where the top most layer has priority. | ||
// See https://en.wikipedia.org/wiki/Alpha_compositing#Alpha_blending for details. | ||
vec4 blendLayersCover( | ||
vec4 current_color, | ||
vec4 layer_color, | ||
bool used_fallback_color | ||
) { | ||
float mixed_alpha_factor = (1.0 - current_color.a) * layer_color.a; | ||
float mixed_alpha = mixed_alpha_factor + current_color.a; | ||
vec3 cover_color_rgb = current_color.a * current_color.rgb + mixed_alpha_factor * layer_color.rgb; | ||
// Catching edge case where mixed_alpha is 0.0 and therefore the cover_color would have nan values. | ||
float is_mixed_alpha_zero = float(mixed_alpha == 0.0); | ||
vec4 cover_color = vec4(cover_color_rgb / (mixed_alpha + is_mixed_alpha_zero), mixed_alpha); | ||
cover_color = mix(cover_color, vec4(0.0), is_mixed_alpha_zero); | ||
// Do not overwrite current_color if the fallback color has been used. | ||
float is_current_color_valid = float(!used_fallback_color); | ||
cover_color = mix(current_color, cover_color, is_current_color_valid); | ||
return cover_color; | ||
} | ||
`, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters