-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathslab_ownership.shader
92 lines (78 loc) · 3.2 KB
/
slab_ownership.shader
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
shader_type canvas_item;
render_mode blend_mix;
uniform sampler2D territoryTexture : hint_albedo;
uniform float zoom;
uniform float alphaFilled;
uniform float alphaOutline;
uniform float outlineThickness;
uniform float alphaFadeColor0 = 1.00;
uniform float alphaFadeColor1 = 1.00;
uniform float alphaFadeColor2 = 1.00;
uniform float alphaFadeColor3 = 1.00;
uniform float alphaFadeColor4 = 1.00;
uniform float alphaFadeColor5 = 1.00;
uniform float alphaFadeColor6 = 1.00;
uniform float alphaFadeColor7 = 1.00;
uniform float alphaFadeColor8 = 1.00;
uniform vec4 color0;
uniform vec4 color1;
uniform vec4 color2;
uniform vec4 color3;
uniform vec4 color4;
uniform vec4 color5;
uniform vec4 color6;
uniform vec4 color7;
uniform vec4 color8;
void fragment() {
vec4 baseCol = texture(territoryTexture,UV);
//vec4 baseCol = texture(TEXTURE,UV);
vec4 modifiedCol = baseCol;
float textureWidth = float(textureSize(territoryTexture,0).x) * 96.0; // The 96 is how much it has been stretched by
float textureHeight = float(textureSize(territoryTexture,0).y) * 96.0;
vec2 texel = vec2(1.0/textureWidth, 1.0/textureHeight);
// vec2 superPixel = max(texel.x, texel.x*zoom) * outlineThickness;
vec2 superPixel = vec2(max(texel.x,texel.x*zoom),max(texel.y,texel.y*zoom)) * outlineThickness;
// Place border around colour which has the mouse over it.
//if (cursorOnColor.rgb == vec3(0.0,0.0,0.0)) {
//
//
// }
//} else {
float fadeAlpha;
if (baseCol == color0) {fadeAlpha = alphaFadeColor0;}
if (baseCol == color1) {fadeAlpha = alphaFadeColor1;}
if (baseCol == color2) {fadeAlpha = alphaFadeColor2;}
if (baseCol == color3) {fadeAlpha = alphaFadeColor3;}
if (baseCol == color4) {fadeAlpha = alphaFadeColor4;}
if (baseCol == color5) {fadeAlpha = alphaFadeColor5;}
if (baseCol == color6) {fadeAlpha = alphaFadeColor6;}
if (baseCol == color7) {fadeAlpha = alphaFadeColor7;}
if (baseCol == color8) {fadeAlpha = alphaFadeColor8;}
modifiedCol.a = alphaFilled;
modifiedCol.a *= 1.0-fadeAlpha;
if (baseCol.a == 1.0) {
bool isBorder = false;
if (texture(territoryTexture, vec2(UV.x, UV.y+superPixel.y )) != baseCol) {isBorder = true;}
if (texture(territoryTexture, vec2(UV.x, UV.y-superPixel.y )) != baseCol) {isBorder = true;}
if (texture(territoryTexture, vec2(UV.x+superPixel.x, UV.y )) != baseCol) {isBorder = true;}
if (texture(territoryTexture, vec2(UV.x-superPixel.x, UV.y )) != baseCol) {isBorder = true;}
if (texture(territoryTexture, vec2(UV.x+superPixel.x, UV.y+superPixel.y )) != baseCol) {isBorder = true;}
if (texture(territoryTexture, vec2(UV.x+superPixel.x, UV.y-superPixel.y )) != baseCol) {isBorder = true;}
if (texture(territoryTexture, vec2(UV.x-superPixel.x, UV.y+superPixel.y )) != baseCol) {isBorder = true;}
if (texture(territoryTexture, vec2(UV.x-superPixel.x, UV.y-superPixel.y )) != baseCol) {isBorder = true;}
if (isBorder == true) {
modifiedCol.a = alphaOutline;
//if (cursorOnColor == baseCol) {
modifiedCol.a *= fadeAlpha;
//}
modifiedCol.a = max(modifiedCol.a, alphaFilled);
}
}
//}
// Always make transparent if ownership is none (represented by black)
if (baseCol.rgb == vec3(0.0,0.0,0.0)) {
COLOR = vec4(0.0,0.0,0.0,0.0);
} else {
COLOR = modifiedCol;
}
}