-
-
Notifications
You must be signed in to change notification settings - Fork 401
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use shader for ColorSelect and add color similarity option
- Loading branch information
1 parent
941f515
commit fa38bdc
Showing
3 changed files
with
115 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
shader_type canvas_item; | ||
render_mode unshaded; | ||
|
||
uniform sampler2D selection : hint_black; | ||
uniform vec4 color; | ||
uniform float similarity_percent : hint_range(0.0, 100.0); | ||
uniform int operation = 0; // 0 = add, 1 = subtract, 2 = intersect | ||
|
||
void fragment() { | ||
vec4 original_color = texture(TEXTURE, UV); | ||
float diff = distance(original_color, color); | ||
float similarity = abs(2.0 - ((similarity_percent/100.0) * 2.0)); | ||
vec4 col = texture(selection, UV); | ||
if (col.rgb == vec3(0.0)) | ||
col.a = 0.0; | ||
|
||
if (diff <= similarity) | ||
{ | ||
if (operation == 0) | ||
col = vec4(1.0); | ||
else if (operation == 1) | ||
col = vec4(0.0); | ||
} | ||
else | ||
if (operation == 2) | ||
col = vec4(0.0); | ||
|
||
COLOR = col; | ||
} |
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