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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
|
[gd_scene load_steps=9 format=3 uid="uid://ct48qux7spi6u"]
[ext_resource type="PackedScene" uid="uid://cr7p1k2xm7mum" path="res://src/Game/Theme/PieChart/PieChart.tscn" id="1_cdu1k"]
[ext_resource type="Script" path="res://src/Game/Theme/PieChart/LayeredChart.gd" id="1_wxoci"]
[sub_resource type="Shader" id="Shader_ojesc"]
code = "shader_type canvas_item;
// The center in UV coordinates, which will always
//be 0.5, the actual radius will be controlled by the control node
//const vec2 center = vec2(0.5,0.5);
uniform float radius = 0.4;
//shadow
uniform vec2 shadow_displacement = vec2(0.75,0.75);
uniform float shadow_tightness = 10;
uniform float shadow_radius = 0.7;
uniform float shadow_thickness = 1.0;
// Control of the slices
uniform float stopAngles[5];
uniform vec3 colours[5];
// Trim
uniform vec3 trim_colour;
uniform float trim_size = 0.05;
// The center is spotlighted by the gradient,
//control its size and falloff with these
uniform float gradient_falloff = 3.6;
uniform float gradient_base = 3.1;
// control whether this is a donut instead of a pie chart
uniform bool donut = false;
uniform bool donut_inner_trim = false;
uniform float donut_inner_radius = 0.15;
// get the polar coordinates of a pixel relative to the center
vec2 getPolar(vec2 UVin, vec2 center){
vec2 relcoord = (UVin-center);
float dist = length(relcoord);
float theta = PI/2.0 + atan((relcoord.y)/(relcoord.x));
if(UVin.x < 0.5){
theta += PI;
}
return vec2(dist,theta);
}
// from thebookofshaders, returns a gradient falloff
float parabola( float base, float x, float k ){
return pow( base*x*(1.0-x), k );
}
float parabola_shadow(float base, float x){
return base*x*x;
}
void fragment() {
vec2 coords = getPolar(UV,vec2(0.5,0.5));
float dist = coords.x;
float theta = coords.y;
vec2 shadow_polar = getPolar(UV,vec2(0.0+shadow_displacement.x,0.0+shadow_displacement.y));
float shadow_peak = radius+(radius-donut_inner_radius)/2.0;
float shadow_gradient = shadow_thickness+parabola_shadow(shadow_tightness*-10.0,shadow_polar.x+shadow_peak-shadow_radius);
// inner hole of the donut => make it transparent
if(donut && dist <= donut_inner_radius){
COLOR = vec4(0.1,0.1,0.1,shadow_gradient);
}
// inner trim
else if(donut && donut_inner_trim && dist <= donut_inner_radius + trim_size){
COLOR = vec4(trim_colour,1.0);
}
// interior
else if(dist <= radius-trim_size){
for(int i=0;i<stopAngles.length();i++){
if(theta <= stopAngles[i]){
float gradient = parabola(gradient_base,dist,gradient_falloff);
COLOR = vec4(colours[i]*(1.0-gradient),1.0);
break;
}
}
}
// outer trim
else if(dist <= radius){
COLOR = vec4(trim_colour,1.0);
}
//outside the circle
else{
COLOR = vec4(0.1,0.1,0.1,shadow_gradient);
}
}"
[sub_resource type="ShaderMaterial" id="ShaderMaterial_6ril8"]
resource_name = "Piechart_shader"
shader = SubResource("Shader_ojesc")
shader_parameter/radius = 0.4
shader_parameter/shadow_displacement = Vector2(0.6, 0.6)
shader_parameter/shadow_tightness = 2.0
shader_parameter/shadow_radius = 0.75
shader_parameter/shadow_thickness = 1.0
shader_parameter/stopAngles = [3.14159, 5.02655, 6.28319]
shader_parameter/colours = [Vector3(0, 0, 1), Vector3(1, 1, 0), Vector3(0.4, 0, 0.6)]
shader_parameter/trim_colour = Vector3(0, 0, 0)
shader_parameter/trim_size = 0.02
shader_parameter/gradient_falloff = 3.6
shader_parameter/gradient_base = 3.1
shader_parameter/donut = false
shader_parameter/donut_inner_trim = true
shader_parameter/donut_inner_radius = 0.051
[sub_resource type="CanvasTexture" id="CanvasTexture_pwdgy"]
[sub_resource type="Shader" id="Shader_vq8ad"]
code = "shader_type canvas_item;
// The center in UV coordinates, which will always
//be 0.5, the actual radius will be controlled by the control node
//const vec2 center = vec2(0.5,0.5);
uniform float radius = 0.4;
//shadow
uniform vec2 shadow_displacement = vec2(0.75,0.75);
uniform float shadow_tightness = 10;
uniform float shadow_radius = 0.7;
uniform float shadow_thickness = 1.0;
// Control of the slices
uniform float stopAngles[5];
uniform vec3 colours[5];
// Trim
uniform vec3 trim_colour;
uniform float trim_size = 0.05;
// The center is spotlighted by the gradient,
//control its size and falloff with these
uniform float gradient_falloff = 3.6;
uniform float gradient_base = 3.1;
// control whether this is a donut instead of a pie chart
uniform bool donut = false;
uniform bool donut_inner_trim = false;
uniform float donut_inner_radius = 0.15;
// get the polar coordinates of a pixel relative to the center
vec2 getPolar(vec2 UVin, vec2 center){
vec2 relcoord = (UVin-center);
float dist = length(relcoord);
float theta = PI/2.0 + atan((relcoord.y)/(relcoord.x));
if(UVin.x < 0.5){
theta += PI;
}
return vec2(dist,theta);
}
// from thebookofshaders, returns a gradient falloff
float parabola( float base, float x, float k ){
return pow( base*x*(1.0-x), k );
}
float parabola_shadow(float base, float x){
return base*x*x;
}
void fragment() {
vec2 coords = getPolar(UV,vec2(0.5,0.5));
float dist = coords.x;
float theta = coords.y;
vec2 shadow_polar = getPolar(UV,vec2(0.0+shadow_displacement.x,0.0+shadow_displacement.y));
float shadow_peak = radius+(radius-donut_inner_radius)/2.0;
float shadow_gradient = shadow_thickness+parabola_shadow(shadow_tightness*-10.0,shadow_polar.x+shadow_peak-shadow_radius);
// inner hole of the donut => make it transparent
if(donut && dist <= donut_inner_radius){
COLOR = vec4(0.1,0.1,0.1,shadow_gradient);
}
// inner trim
else if(donut && donut_inner_trim && dist <= donut_inner_radius + trim_size){
COLOR = vec4(trim_colour,1.0);
}
// interior
else if(dist <= radius-trim_size){
for(int i=0;i<stopAngles.length();i++){
if(theta <= stopAngles[i]){
float gradient = parabola(gradient_base,dist,gradient_falloff);
COLOR = vec4(colours[i]*(1.0-gradient),1.0);
break;
}
}
}
// outer trim
else if(dist <= radius){
COLOR = vec4(trim_colour,1.0);
}
//outside the circle
else{
COLOR = vec4(0.1,0.1,0.1,shadow_gradient);
}
}"
[sub_resource type="ShaderMaterial" id="ShaderMaterial_5ilmo"]
resource_name = "Piechart_shader"
shader = SubResource("Shader_vq8ad")
shader_parameter/radius = 0.4
shader_parameter/shadow_displacement = Vector2(0.75, 0.75)
shader_parameter/shadow_tightness = 10.0
shader_parameter/shadow_radius = 0.0
shader_parameter/shadow_thickness = 1.0
shader_parameter/stopAngles = [3.14159, 5.02655, 6.28319]
shader_parameter/colours = [Vector3(0, 0, 1), Vector3(1, 1, 0), Vector3(0.4, 0, 0.6)]
shader_parameter/trim_colour = Vector3(0, 0, 0)
shader_parameter/trim_size = 0.02
shader_parameter/gradient_falloff = 3.6
shader_parameter/gradient_base = 3.1
shader_parameter/donut = true
shader_parameter/donut_inner_trim = true
shader_parameter/donut_inner_radius = 0.2
[sub_resource type="CanvasTexture" id="CanvasTexture_x3pc8"]
[node name="LayeredChart" type="CenterContainer"]
offset_right = 50.0
offset_bottom = 50.0
script = ExtResource("1_wxoci")
[node name="PieChart" parent="." instance=ExtResource("1_cdu1k")]
material = SubResource("ShaderMaterial_6ril8")
layout_mode = 2
size_flags_horizontal = 4
size_flags_vertical = 4
texture = SubResource("CanvasTexture_pwdgy")
donut_inner_radius = 0.102
shadow_focus = 2.0
shadow_radius = 0.75
[node name="PieChart2" parent="." instance=ExtResource("1_cdu1k")]
material = SubResource("ShaderMaterial_5ilmo")
layout_mode = 2
size_flags_horizontal = 4
size_flags_vertical = 4
texture = SubResource("CanvasTexture_x3pc8")
donut = true
donut_inner_radius = 0.4
shadow_displacement = Vector2(0.75, 0.75)
shadow_focus = 10.0
shadow_radius = 0.0
|