datacut 0.1.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- datacut/__init__.py +121 -0
- datacut/__main__.py +122 -0
- datacut/animation/__init__.py +0 -0
- datacut/animation/animation.py +336 -0
- datacut/animation/composition.py +258 -0
- datacut/animation/creation.py +315 -0
- datacut/animation/fading.py +328 -0
- datacut/animation/growing.py +90 -0
- datacut/animation/indication.py +608 -0
- datacut/animation/movement.py +165 -0
- datacut/animation/numbers.py +92 -0
- datacut/animation/physics.py +453 -0
- datacut/animation/rotation.py +95 -0
- datacut/animation/specialized.py +956 -0
- datacut/animation/transform.py +505 -0
- datacut/animation/transform_matching_parts.py +343 -0
- datacut/animation/update.py +95 -0
- datacut/camera/__init__.py +0 -0
- datacut/camera/camera.py +795 -0
- datacut/camera/camera_frame.py +320 -0
- datacut/camera/cinematography.py +1166 -0
- datacut/config.py +479 -0
- datacut/constants.py +160 -0
- datacut/css/__init__.py +189 -0
- datacut/css/easing.py +328 -0
- datacut/css/engine.py +1727 -0
- datacut/css/gradients.py +678 -0
- datacut/css/motion.py +1615 -0
- datacut/css/parser.py +741 -0
- datacut/css/presets.py +143 -0
- datacut/css/shader_fill.py +703 -0
- datacut/css/values.py +650 -0
- datacut/default_config.yml +224 -0
- datacut/event_handler/__init__.py +6 -0
- datacut/event_handler/event_dispatcher.py +161 -0
- datacut/event_handler/event_listner.py +31 -0
- datacut/event_handler/event_type.py +11 -0
- datacut/event_handler/picking.py +111 -0
- datacut/event_keys.py +53 -0
- datacut/extract_scene.py +200 -0
- datacut/layout/__init__.py +39 -0
- datacut/layout/components.py +425 -0
- datacut/layout/containers.py +1520 -0
- datacut/logger.py +13 -0
- datacut/mobject/__init__.py +0 -0
- datacut/mobject/boolean_ops.py +168 -0
- datacut/mobject/changing.py +209 -0
- datacut/mobject/coordinate_systems.py +1056 -0
- datacut/mobject/fractals.py +348 -0
- datacut/mobject/frame.py +80 -0
- datacut/mobject/functions.py +147 -0
- datacut/mobject/geometry.py +1834 -0
- datacut/mobject/gltf.py +243 -0
- datacut/mobject/interactive.py +906 -0
- datacut/mobject/lights.py +366 -0
- datacut/mobject/materials.py +207 -0
- datacut/mobject/matrix.py +570 -0
- datacut/mobject/mesh3d.py +2288 -0
- datacut/mobject/mobject.py +2885 -0
- datacut/mobject/mobject_update_utils.py +123 -0
- datacut/mobject/model.py +543 -0
- datacut/mobject/number_line.py +517 -0
- datacut/mobject/numbers.py +441 -0
- datacut/mobject/probability.py +536 -0
- datacut/mobject/shape_matchers.py +161 -0
- datacut/mobject/subtitles.py +260 -0
- datacut/mobject/svg/__init__.py +0 -0
- datacut/mobject/svg/brace.py +356 -0
- datacut/mobject/svg/drawings.py +1041 -0
- datacut/mobject/svg/old_tex_mobject.py +335 -0
- datacut/mobject/svg/path_cache.py +155 -0
- datacut/mobject/svg/special_tex.py +216 -0
- datacut/mobject/svg/string_mobject.py +622 -0
- datacut/mobject/svg/svg_mobject.py +657 -0
- datacut/mobject/svg/svg_parse.py +437 -0
- datacut/mobject/svg/tex_mobject.py +499 -0
- datacut/mobject/svg/text_mobject.py +702 -0
- datacut/mobject/svg/typst_mobject.py +864 -0
- datacut/mobject/three_dimensions.py +686 -0
- datacut/mobject/types/__init__.py +0 -0
- datacut/mobject/types/dot_cloud.py +220 -0
- datacut/mobject/types/image_mobject.py +130 -0
- datacut/mobject/types/point_cloud_mobject.py +138 -0
- datacut/mobject/types/shader_mobject.py +268 -0
- datacut/mobject/types/surface.py +848 -0
- datacut/mobject/types/vectorized_mobject.py +1749 -0
- datacut/mobject/types/video_mobject.py +3902 -0
- datacut/mobject/value_tracker.py +110 -0
- datacut/mobject/vector_field.py +585 -0
- datacut/module_loader.py +176 -0
- datacut/reactive/__init__.py +25 -0
- datacut/reactive/signals.py +610 -0
- datacut/renderer/__init__.py +4 -0
- datacut/renderer/drawing.py +1066 -0
- datacut/renderer/gpu.py +800 -0
- datacut/renderer/material.py +88 -0
- datacut/renderer/pipeline.py +179 -0
- datacut/renderer/post_process.py +577 -0
- datacut/renderer/renderer.py +1285 -0
- datacut/renderer/shader_source.py +146 -0
- datacut/renderer/shared_buffer.py +185 -0
- datacut/renderer/texture.py +217 -0
- datacut/renderer/uniform_block.py +118 -0
- datacut/scene/__init__.py +0 -0
- datacut/scene/incremental.py +233 -0
- datacut/scene/interactive_scene.py +758 -0
- datacut/scene/performance.py +226 -0
- datacut/scene/presentation_scene.py +783 -0
- datacut/scene/recording.py +541 -0
- datacut/scene/safe_zones.py +323 -0
- datacut/scene/scene.py +2849 -0
- datacut/scene/scene_embed.py +277 -0
- datacut/scene/scene_file_writer.py +1014 -0
- datacut/scene/scene_task.py +183 -0
- datacut/scene/sfx.py +164 -0
- datacut/scene/sound.py +702 -0
- datacut/scene/sound_clip.py +580 -0
- datacut/scene/timeline.py +1689 -0
- datacut/scene/transcript.py +503 -0
- datacut/shaders/fill.wgsl +107 -0
- datacut/shaders/fill_depth.wgsl +198 -0
- datacut/shaders/image.wgsl +25 -0
- datacut/shaders/inserts/NOTE.md +16 -0
- datacut/shaders/inserts/clip_test.wgsl +14 -0
- datacut/shaders/inserts/complex_functions.wgsl +20 -0
- datacut/shaders/inserts/fill_color.wgsl +10 -0
- datacut/shaders/inserts/finalize_color.wgsl +44 -0
- datacut/shaders/inserts/frame_uniforms.wgsl +37 -0
- datacut/shaders/inserts/frame_units.wgsl +18 -0
- datacut/shaders/inserts/image_quad.wgsl +28 -0
- datacut/shaders/inserts/mobject_uniforms.wgsl +11 -0
- datacut/shaders/inserts/project_point.wgsl +44 -0
- datacut/shaders/inserts/quad_corners.wgsl +12 -0
- datacut/shaders/inserts/read_data.wgsl +33 -0
- datacut/shaders/inserts/surface_mesh.wgsl +106 -0
- datacut/shaders/mandelbrot_fractal.wgsl +100 -0
- datacut/shaders/mesh.wgsl +474 -0
- datacut/shaders/newton_fractal.wgsl +200 -0
- datacut/shaders/present.wgsl +62 -0
- datacut/shaders/stroke.wgsl +1141 -0
- datacut/shaders/stroke_depth.wgsl +1136 -0
- datacut/shaders/surface.wgsl +40 -0
- datacut/shaders/textured_surface.wgsl +59 -0
- datacut/shaders/true_dot.wgsl +78 -0
- datacut/shaders/video.wgsl +42 -0
- datacut/tex_templates.yml +736 -0
- datacut/transcribe.py +32 -0
- datacut/typing.py +412 -0
- datacut/utils/__init__.py +0 -0
- datacut/utils/bezier.py +467 -0
- datacut/utils/browser_audio.py +423 -0
- datacut/utils/browser_code_transform.py +1293 -0
- datacut/utils/browser_completions.py +2255 -0
- datacut/utils/browser_fonts.py +143 -0
- datacut/utils/browser_pathops.py +47 -0
- datacut/utils/browser_scheduler.py +18 -0
- datacut/utils/browser_typst.py +82 -0
- datacut/utils/cache.py +34 -0
- datacut/utils/cinematic_vfx.py +779 -0
- datacut/utils/color.py +203 -0
- datacut/utils/debug.py +46 -0
- datacut/utils/dict_ops.py +22 -0
- datacut/utils/directories.py +55 -0
- datacut/utils/editor_signatures.py +1806 -0
- datacut/utils/editor_thumbnails.py +769 -0
- datacut/utils/family_ops.py +48 -0
- datacut/utils/file_ops.py +65 -0
- datacut/utils/images.py +52 -0
- datacut/utils/iterables.py +216 -0
- datacut/utils/native.py +280 -0
- datacut/utils/paths.py +83 -0
- datacut/utils/rate_functions.py +154 -0
- datacut/utils/render_geometry.py +186 -0
- datacut/utils/simple_functions.py +99 -0
- datacut/utils/sounds.py +43 -0
- datacut/utils/space_ops.py +460 -0
- datacut/utils/structured_array.py +256 -0
- datacut/utils/svg_export.py +102 -0
- datacut/utils/tex.py +139 -0
- datacut/utils/tex_file_writing.py +164 -0
- datacut/utils/tex_to_symbol_count.py +186 -0
- datacut/utils/typst_file_writing.py +205 -0
- datacut/utils/vfx_presets.py +4543 -0
- datacut/utils/visual_css.py +737 -0
- datacut/utils/visual_editor.py +4292 -0
- datacut/utils/window_audio.py +760 -0
- datacut/window.py +910 -0
- datacut-0.1.0.dist-info/METADATA +226 -0
- datacut-0.1.0.dist-info/RECORD +193 -0
- datacut-0.1.0.dist-info/WHEEL +5 -0
- datacut-0.1.0.dist-info/entry_points.txt +2 -0
- datacut-0.1.0.dist-info/licenses/LICENSE.md +21 -0
- datacut-0.1.0.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,1136 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Depth-only stroke shader.
|
|
3
|
+
|
|
4
|
+
This is the depth counterpart of stroke.wgsl.
|
|
5
|
+
|
|
6
|
+
The generated geometry is identical. The fragment stage only keeps the
|
|
7
|
+
portion that belongs to the actual stroke.
|
|
8
|
+
|
|
9
|
+
The render pipeline using this shader has:
|
|
10
|
+
|
|
11
|
+
color_write = false
|
|
12
|
+
depth_write = true
|
|
13
|
+
|
|
14
|
+
so the returned color is never stored.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
const IS_FILL_BORDER: bool = false;
|
|
18
|
+
|
|
19
|
+
#INSERT mobject_uniforms.wgsl
|
|
20
|
+
#INSERT frame_uniforms.wgsl
|
|
21
|
+
#INSERT read_data.wgsl
|
|
22
|
+
#INSERT project_point.wgsl
|
|
23
|
+
#INSERT fill_color.wgsl
|
|
24
|
+
#INSERT finalize_color.wgsl
|
|
25
|
+
#INSERT clip_test.wgsl
|
|
26
|
+
|
|
27
|
+
const ALIGNMENT_THRESHOLD: f32 = 0.99;
|
|
28
|
+
const POLYLINE_FACTOR: f32 = 100.0;
|
|
29
|
+
const MAX_STEPS: i32 = 32;
|
|
30
|
+
const NONE: i32 = -1;
|
|
31
|
+
const EPSILON: f32 = 1e-15;
|
|
32
|
+
|
|
33
|
+
const ROUND_COS_SHARP: f32 = -0.5;
|
|
34
|
+
const ROUND_COS_ROUND: f32 = -0.95;
|
|
35
|
+
|
|
36
|
+
const STROKE_WIDTH_CONVERSION: f32 = 0.01;
|
|
37
|
+
|
|
38
|
+
const RECORD_STEP: u32 = 2u;
|
|
39
|
+
|
|
40
|
+
const VERTS_PER_CURVE: u32 =
|
|
41
|
+
u32(6 * (MAX_STEPS - 1));
|
|
42
|
+
|
|
43
|
+
const JOINT_SEGMENTS: i32 = 3;
|
|
44
|
+
|
|
45
|
+
const POLYLINE_SEGMENTS: i32 =
|
|
46
|
+
MAX_STEPS - 1 - JOINT_SEGMENTS;
|
|
47
|
+
|
|
48
|
+
const FAN_TRIANGLES: i32 =
|
|
49
|
+
2 * JOINT_SEGMENTS;
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
const CORNERS = array<vec2f, 6>(
|
|
53
|
+
vec2f(0.0, -1.0),
|
|
54
|
+
vec2f(0.0, 1.0),
|
|
55
|
+
vec2f(1.0, -1.0),
|
|
56
|
+
|
|
57
|
+
vec2f(1.0, -1.0),
|
|
58
|
+
vec2f(0.0, 1.0),
|
|
59
|
+
vec2f(1.0, 1.0),
|
|
60
|
+
);
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
struct VertexOutput {
|
|
64
|
+
@builtin(position) position: vec4f,
|
|
65
|
+
|
|
66
|
+
@location(0)
|
|
67
|
+
clip_distances: vec4f,
|
|
68
|
+
|
|
69
|
+
@location(1)
|
|
70
|
+
color: vec4f,
|
|
71
|
+
|
|
72
|
+
@location(2)
|
|
73
|
+
dist_to_aaw: f32,
|
|
74
|
+
|
|
75
|
+
@location(3)
|
|
76
|
+
half_width_to_aaw: f32,
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
fn point_on_quadratic(
|
|
81
|
+
t: f32,
|
|
82
|
+
c0: vec3f,
|
|
83
|
+
c1: vec3f,
|
|
84
|
+
c2: vec3f,
|
|
85
|
+
) -> vec3f {
|
|
86
|
+
return c0
|
|
87
|
+
+ c1 * t
|
|
88
|
+
+ c2 * t * t;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
fn tangent_on_quadratic(
|
|
93
|
+
t: f32,
|
|
94
|
+
c1: vec3f,
|
|
95
|
+
c2: vec3f,
|
|
96
|
+
) -> vec3f {
|
|
97
|
+
return c1
|
|
98
|
+
+ 2.0 * c2 * t;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
|
|
102
|
+
fn project(
|
|
103
|
+
vect: vec3f,
|
|
104
|
+
normal: vec3f,
|
|
105
|
+
) -> vec3f {
|
|
106
|
+
return vect
|
|
107
|
+
- dot(vect, normal) * normal;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
|
|
111
|
+
fn rotate_vector(
|
|
112
|
+
vect: vec3f,
|
|
113
|
+
normal: vec3f,
|
|
114
|
+
turn: vec2f,
|
|
115
|
+
) -> vec3f {
|
|
116
|
+
return turn.x * vect
|
|
117
|
+
+ turn.y * cross(normal, vect);
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
|
|
121
|
+
fn neighbor_tangent(
|
|
122
|
+
record: i32,
|
|
123
|
+
subpath: vec2f,
|
|
124
|
+
at_start: bool,
|
|
125
|
+
anchor: vec3f,
|
|
126
|
+
) -> vec3f {
|
|
127
|
+
let first =
|
|
128
|
+
record - i32(subpath.x);
|
|
129
|
+
|
|
130
|
+
let last =
|
|
131
|
+
record + i32(subpath.y);
|
|
132
|
+
|
|
133
|
+
let closed = all(
|
|
134
|
+
read_vec3(
|
|
135
|
+
u32(first),
|
|
136
|
+
DATA_OFFSET_point,
|
|
137
|
+
)
|
|
138
|
+
==
|
|
139
|
+
read_vec3(
|
|
140
|
+
u32(last),
|
|
141
|
+
DATA_OFFSET_point,
|
|
142
|
+
)
|
|
143
|
+
);
|
|
144
|
+
|
|
145
|
+
if (at_start) {
|
|
146
|
+
var previous = NONE;
|
|
147
|
+
|
|
148
|
+
if (record > first) {
|
|
149
|
+
previous = record - 1;
|
|
150
|
+
}
|
|
151
|
+
else if (closed) {
|
|
152
|
+
previous = last - 1;
|
|
153
|
+
}
|
|
154
|
+
else if (IS_FILL_BORDER) {
|
|
155
|
+
previous = last;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
if (previous == NONE) {
|
|
159
|
+
return vec3f(0.0);
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
return anchor
|
|
163
|
+
- read_vec3(
|
|
164
|
+
u32(previous),
|
|
165
|
+
DATA_OFFSET_point,
|
|
166
|
+
);
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
var next = NONE;
|
|
170
|
+
|
|
171
|
+
if (record + 2 < last) {
|
|
172
|
+
next = record + 3;
|
|
173
|
+
}
|
|
174
|
+
else if (closed || record == last) {
|
|
175
|
+
next = first + 1;
|
|
176
|
+
}
|
|
177
|
+
else if (IS_FILL_BORDER) {
|
|
178
|
+
next = first;
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
if (next == NONE) {
|
|
182
|
+
return vec3f(0.0);
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
return read_vec3(
|
|
186
|
+
u32(next),
|
|
187
|
+
DATA_OFFSET_point,
|
|
188
|
+
) - anchor;
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
|
|
192
|
+
fn vector_length_squared(v: vec3f) -> f32 {
|
|
193
|
+
return dot(v, v);
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
|
|
197
|
+
fn is_degenerate(v: vec3f) -> bool {
|
|
198
|
+
return vector_length_squared(v) <= EPSILON * EPSILON;
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
|
|
202
|
+
fn safe_normalize(v: vec3f, fallback: vec3f) -> vec3f {
|
|
203
|
+
let len2 = dot(v, v);
|
|
204
|
+
if (len2 <= EPSILON * EPSILON) {
|
|
205
|
+
let fallback_len2 = dot(fallback, fallback);
|
|
206
|
+
if (fallback_len2 <= EPSILON * EPSILON) {
|
|
207
|
+
return vec3f(0.0, 0.0, 0.0);
|
|
208
|
+
}
|
|
209
|
+
return fallback * inverseSqrt(fallback_len2);
|
|
210
|
+
}
|
|
211
|
+
return v * inverseSqrt(len2);
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
|
|
215
|
+
fn flat_tangent(
|
|
216
|
+
tangent: vec3f,
|
|
217
|
+
facing_normal: vec3f,
|
|
218
|
+
) -> vec3f {
|
|
219
|
+
let flattened = project(tangent, facing_normal);
|
|
220
|
+
|
|
221
|
+
if (is_degenerate(flattened)) {
|
|
222
|
+
return vec3f(0.0);
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
return safe_normalize(flattened, vec3f(0.0));
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
|
|
229
|
+
fn safe_normalize_2d(v: vec2f, fallback: vec2f) -> vec2f {
|
|
230
|
+
let len2 = dot(v, v);
|
|
231
|
+
if (len2 <= EPSILON * EPSILON) {
|
|
232
|
+
let fallback_len2 = dot(fallback, fallback);
|
|
233
|
+
if (fallback_len2 <= EPSILON * EPSILON) {
|
|
234
|
+
return vec2f(0.0, 0.0);
|
|
235
|
+
}
|
|
236
|
+
return fallback * inverseSqrt(fallback_len2);
|
|
237
|
+
}
|
|
238
|
+
return v * inverseSqrt(len2);
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
|
|
242
|
+
fn get_camera_basis() -> array<vec3f, 2> {
|
|
243
|
+
var R = vec3f(frame.view[0].x, frame.view[1].x, frame.view[2].x);
|
|
244
|
+
var U = vec3f(frame.view[0].y, frame.view[1].y, frame.view[2].y);
|
|
245
|
+
if (mob.is_fixed_in_frame != 0.0) {
|
|
246
|
+
R = vec3f(1.0, 0.0, 0.0);
|
|
247
|
+
U = vec3f(0.0, 1.0, 0.0);
|
|
248
|
+
} else {
|
|
249
|
+
R = safe_normalize(R, vec3f(1.0, 0.0, 0.0));
|
|
250
|
+
U = safe_normalize(U, vec3f(0.0, 1.0, 0.0));
|
|
251
|
+
}
|
|
252
|
+
return array<vec3f, 2>(R, U);
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
|
|
256
|
+
fn get_camera_normal() -> vec3f {
|
|
257
|
+
if (mob.is_fixed_in_frame != 0.0) {
|
|
258
|
+
return vec3f(0.0, 0.0, 1.0);
|
|
259
|
+
}
|
|
260
|
+
let N = vec3f(frame.view[0].z, frame.view[1].z, frame.view[2].z);
|
|
261
|
+
return safe_normalize(N, vec3f(0.0, 0.0, 1.0));
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
|
|
265
|
+
fn get_screen_tangent(point: vec3f, tangent: vec3f) -> vec2f {
|
|
266
|
+
var p_view = (frame.view * vec4f(point, 1.0)).xyz;
|
|
267
|
+
var t_view = (frame.view * vec4f(tangent, 0.0)).xyz;
|
|
268
|
+
if (mob.is_fixed_in_frame != 0.0) {
|
|
269
|
+
p_view = point;
|
|
270
|
+
t_view = tangent;
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
let w = 1.0 - p_view.z * frame.frame_rescale_factors.z;
|
|
274
|
+
let screen_tan = t_view.xy * w + p_view.xy * (t_view.z * frame.frame_rescale_factors.z);
|
|
275
|
+
|
|
276
|
+
if (dot(screen_tan, screen_tan) > EPSILON * EPSILON) {
|
|
277
|
+
return safe_normalize_2d(screen_tan, vec2f(1.0, 0.0));
|
|
278
|
+
}
|
|
279
|
+
if (dot(t_view.xy, t_view.xy) > EPSILON * EPSILON) {
|
|
280
|
+
return safe_normalize_2d(t_view.xy, vec2f(1.0, 0.0));
|
|
281
|
+
}
|
|
282
|
+
return vec2f(1.0, 0.0);
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
|
|
286
|
+
fn joint_shift(
|
|
287
|
+
point: vec3f,
|
|
288
|
+
tan_in: vec3f,
|
|
289
|
+
tan_out: vec3f,
|
|
290
|
+
facing_normal: vec3f,
|
|
291
|
+
draw_flat: bool,
|
|
292
|
+
) -> f32 {
|
|
293
|
+
if (!draw_flat) {
|
|
294
|
+
let a = get_screen_tangent(point, tan_in);
|
|
295
|
+
let b = get_screen_tangent(point, tan_out);
|
|
296
|
+
|
|
297
|
+
let sin_angle = a.x * b.y - a.y * b.x;
|
|
298
|
+
|
|
299
|
+
if (abs(sin_angle) < 1e-6) {
|
|
300
|
+
return 0.0;
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
let cos_angle = clamp(
|
|
304
|
+
dot(a, b),
|
|
305
|
+
-1.0,
|
|
306
|
+
1.0,
|
|
307
|
+
);
|
|
308
|
+
|
|
309
|
+
let keep = smoothstep(
|
|
310
|
+
ROUND_COS_ROUND,
|
|
311
|
+
ROUND_COS_SHARP,
|
|
312
|
+
cos_angle,
|
|
313
|
+
) * (1.0 - mob.joint_roundness);
|
|
314
|
+
|
|
315
|
+
return keep * (cos_angle - 1.0) / sin_angle;
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
let a = flat_tangent(
|
|
319
|
+
tan_in,
|
|
320
|
+
facing_normal,
|
|
321
|
+
);
|
|
322
|
+
|
|
323
|
+
let b = flat_tangent(
|
|
324
|
+
tan_out,
|
|
325
|
+
facing_normal,
|
|
326
|
+
);
|
|
327
|
+
|
|
328
|
+
if (
|
|
329
|
+
all(a == vec3f(0.0))
|
|
330
|
+
||
|
|
331
|
+
all(b == vec3f(0.0))
|
|
332
|
+
) {
|
|
333
|
+
return 0.0;
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
let sin_angle =
|
|
337
|
+
dot(
|
|
338
|
+
cross(a, b),
|
|
339
|
+
facing_normal,
|
|
340
|
+
);
|
|
341
|
+
|
|
342
|
+
if (
|
|
343
|
+
abs(sin_angle)
|
|
344
|
+
< 1e-6
|
|
345
|
+
) {
|
|
346
|
+
return 0.0;
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
let cos_angle =
|
|
350
|
+
dot(a, b);
|
|
351
|
+
|
|
352
|
+
let keep =
|
|
353
|
+
smoothstep(
|
|
354
|
+
ROUND_COS_ROUND,
|
|
355
|
+
ROUND_COS_SHARP,
|
|
356
|
+
cos_angle,
|
|
357
|
+
)
|
|
358
|
+
* (
|
|
359
|
+
1.0
|
|
360
|
+
- mob.joint_roundness
|
|
361
|
+
);
|
|
362
|
+
|
|
363
|
+
return keep
|
|
364
|
+
* (cos_angle - 1.0)
|
|
365
|
+
/ sin_angle;
|
|
366
|
+
}
|
|
367
|
+
|
|
368
|
+
|
|
369
|
+
fn step_to_corner(
|
|
370
|
+
point: vec3f,
|
|
371
|
+
tangent: vec3f,
|
|
372
|
+
facing_normal: vec3f,
|
|
373
|
+
shift: f32,
|
|
374
|
+
draw_flat: bool,
|
|
375
|
+
) -> vec3f {
|
|
376
|
+
if (!draw_flat) {
|
|
377
|
+
let basis = get_camera_basis();
|
|
378
|
+
let R = basis[0];
|
|
379
|
+
let U = basis[1];
|
|
380
|
+
let tan_2d = get_screen_tangent(point, tangent);
|
|
381
|
+
let step_2d = vec2f(-tan_2d.y, tan_2d.x);
|
|
382
|
+
return (step_2d.x + shift * tan_2d.x) * R + (step_2d.y + shift * tan_2d.y) * U;
|
|
383
|
+
}
|
|
384
|
+
|
|
385
|
+
var unflattened = tangent;
|
|
386
|
+
|
|
387
|
+
let unit_tan =
|
|
388
|
+
normalize(
|
|
389
|
+
unflattened
|
|
390
|
+
);
|
|
391
|
+
|
|
392
|
+
var step =
|
|
393
|
+
normalize(
|
|
394
|
+
cross(
|
|
395
|
+
facing_normal,
|
|
396
|
+
unit_tan,
|
|
397
|
+
)
|
|
398
|
+
);
|
|
399
|
+
|
|
400
|
+
let alignment =
|
|
401
|
+
abs(
|
|
402
|
+
dot(
|
|
403
|
+
normalize(tangent),
|
|
404
|
+
facing_normal,
|
|
405
|
+
)
|
|
406
|
+
);
|
|
407
|
+
|
|
408
|
+
if (
|
|
409
|
+
alignment
|
|
410
|
+
> ALIGNMENT_THRESHOLD
|
|
411
|
+
) {
|
|
412
|
+
let perp =
|
|
413
|
+
normalize(
|
|
414
|
+
cross(
|
|
415
|
+
mob.unit_normal,
|
|
416
|
+
tangent,
|
|
417
|
+
)
|
|
418
|
+
);
|
|
419
|
+
|
|
420
|
+
step = mix(
|
|
421
|
+
step,
|
|
422
|
+
project(
|
|
423
|
+
step,
|
|
424
|
+
perp,
|
|
425
|
+
),
|
|
426
|
+
smoothstep(
|
|
427
|
+
ALIGNMENT_THRESHOLD,
|
|
428
|
+
1.0,
|
|
429
|
+
alignment,
|
|
430
|
+
),
|
|
431
|
+
);
|
|
432
|
+
}
|
|
433
|
+
|
|
434
|
+
return step
|
|
435
|
+
+ shift * unit_tan;
|
|
436
|
+
}
|
|
437
|
+
|
|
438
|
+
|
|
439
|
+
@vertex
|
|
440
|
+
fn vs_main(
|
|
441
|
+
@builtin(vertex_index) vertex_index: u32,
|
|
442
|
+
) -> VertexOutput {
|
|
443
|
+
var out: VertexOutput;
|
|
444
|
+
|
|
445
|
+
let blank =
|
|
446
|
+
vec4f(
|
|
447
|
+
0.0,
|
|
448
|
+
0.0,
|
|
449
|
+
0.0,
|
|
450
|
+
1.0,
|
|
451
|
+
);
|
|
452
|
+
|
|
453
|
+
let curve =
|
|
454
|
+
vertex_index
|
|
455
|
+
/ VERTS_PER_CURVE;
|
|
456
|
+
|
|
457
|
+
let within =
|
|
458
|
+
vertex_index
|
|
459
|
+
% VERTS_PER_CURVE;
|
|
460
|
+
|
|
461
|
+
let segment =
|
|
462
|
+
i32(within / 6u);
|
|
463
|
+
|
|
464
|
+
let tri_vert =
|
|
465
|
+
i32(within % 6u);
|
|
466
|
+
|
|
467
|
+
let corner =
|
|
468
|
+
CORNERS[tri_vert];
|
|
469
|
+
|
|
470
|
+
let record =
|
|
471
|
+
RECORD_STEP * curve;
|
|
472
|
+
|
|
473
|
+
let joint_fan =
|
|
474
|
+
segment
|
|
475
|
+
>= POLYLINE_SEGMENTS;
|
|
476
|
+
|
|
477
|
+
let subpath =
|
|
478
|
+
read_vec2(
|
|
479
|
+
record,
|
|
480
|
+
DATA_OFFSET_subpath_range,
|
|
481
|
+
);
|
|
482
|
+
|
|
483
|
+
var controls =
|
|
484
|
+
array<vec3f, 3>(
|
|
485
|
+
read_vec3(
|
|
486
|
+
record,
|
|
487
|
+
DATA_OFFSET_point,
|
|
488
|
+
),
|
|
489
|
+
|
|
490
|
+
read_vec3(
|
|
491
|
+
record + 1u,
|
|
492
|
+
DATA_OFFSET_point,
|
|
493
|
+
),
|
|
494
|
+
|
|
495
|
+
read_vec3(
|
|
496
|
+
record + 2u,
|
|
497
|
+
DATA_OFFSET_point,
|
|
498
|
+
),
|
|
499
|
+
);
|
|
500
|
+
|
|
501
|
+
if (
|
|
502
|
+
IS_FILL_BORDER
|
|
503
|
+
&&
|
|
504
|
+
subpath.y == 0.0
|
|
505
|
+
) {
|
|
506
|
+
controls[2] =
|
|
507
|
+
read_vec3(
|
|
508
|
+
u32(
|
|
509
|
+
i32(record)
|
|
510
|
+
- i32(subpath.x)
|
|
511
|
+
),
|
|
512
|
+
DATA_OFFSET_point,
|
|
513
|
+
);
|
|
514
|
+
|
|
515
|
+
controls[1] =
|
|
516
|
+
0.5
|
|
517
|
+
* (
|
|
518
|
+
controls[0]
|
|
519
|
+
+ controls[2]
|
|
520
|
+
);
|
|
521
|
+
}
|
|
522
|
+
|
|
523
|
+
let widths =
|
|
524
|
+
array<f32, 3>(
|
|
525
|
+
read_float(
|
|
526
|
+
record,
|
|
527
|
+
DATA_OFFSET_stroke_width,
|
|
528
|
+
),
|
|
529
|
+
|
|
530
|
+
read_float(
|
|
531
|
+
record + 1u,
|
|
532
|
+
DATA_OFFSET_stroke_width,
|
|
533
|
+
),
|
|
534
|
+
|
|
535
|
+
read_float(
|
|
536
|
+
record + 2u,
|
|
537
|
+
DATA_OFFSET_stroke_width,
|
|
538
|
+
),
|
|
539
|
+
);
|
|
540
|
+
|
|
541
|
+
let colors =
|
|
542
|
+
array<vec4f, 3>(
|
|
543
|
+
read_vec4(
|
|
544
|
+
record,
|
|
545
|
+
DATA_OFFSET_stroke_rgba,
|
|
546
|
+
),
|
|
547
|
+
|
|
548
|
+
read_vec4(
|
|
549
|
+
record + 1u,
|
|
550
|
+
DATA_OFFSET_stroke_rgba,
|
|
551
|
+
),
|
|
552
|
+
|
|
553
|
+
read_vec4(
|
|
554
|
+
record + 2u,
|
|
555
|
+
DATA_OFFSET_stroke_rgba,
|
|
556
|
+
),
|
|
557
|
+
);
|
|
558
|
+
|
|
559
|
+
let c0 =
|
|
560
|
+
controls[0];
|
|
561
|
+
|
|
562
|
+
let c1 =
|
|
563
|
+
2.0
|
|
564
|
+
* (
|
|
565
|
+
controls[1]
|
|
566
|
+
- controls[0]
|
|
567
|
+
);
|
|
568
|
+
|
|
569
|
+
let c2 =
|
|
570
|
+
controls[0]
|
|
571
|
+
- 2.0 * controls[1]
|
|
572
|
+
+ controls[2];
|
|
573
|
+
|
|
574
|
+
let area =
|
|
575
|
+
0.5
|
|
576
|
+
* length(
|
|
577
|
+
cross(
|
|
578
|
+
controls[1]
|
|
579
|
+
- controls[0],
|
|
580
|
+
|
|
581
|
+
controls[2]
|
|
582
|
+
- controls[0],
|
|
583
|
+
)
|
|
584
|
+
);
|
|
585
|
+
|
|
586
|
+
let count =
|
|
587
|
+
i32(
|
|
588
|
+
round(
|
|
589
|
+
POLYLINE_FACTOR
|
|
590
|
+
* sqrt(area)
|
|
591
|
+
/ get_frame_unit_size()
|
|
592
|
+
)
|
|
593
|
+
);
|
|
594
|
+
|
|
595
|
+
let n_steps =
|
|
596
|
+
min(
|
|
597
|
+
2 + count,
|
|
598
|
+
POLYLINE_SEGMENTS + 1,
|
|
599
|
+
);
|
|
600
|
+
|
|
601
|
+
var nothing_to_draw =
|
|
602
|
+
all(
|
|
603
|
+
controls[0]
|
|
604
|
+
== controls[1]
|
|
605
|
+
);
|
|
606
|
+
|
|
607
|
+
nothing_to_draw =
|
|
608
|
+
nothing_to_draw
|
|
609
|
+
||
|
|
610
|
+
(
|
|
611
|
+
!joint_fan
|
|
612
|
+
&&
|
|
613
|
+
segment >= n_steps - 1
|
|
614
|
+
);
|
|
615
|
+
|
|
616
|
+
if (IS_FILL_BORDER) {
|
|
617
|
+
nothing_to_draw =
|
|
618
|
+
nothing_to_draw
|
|
619
|
+
||
|
|
620
|
+
min(
|
|
621
|
+
mob.fill_rgba.a,
|
|
622
|
+
mob.fill_rgba_end.a,
|
|
623
|
+
) < 0.999;
|
|
624
|
+
}
|
|
625
|
+
else {
|
|
626
|
+
nothing_to_draw =
|
|
627
|
+
nothing_to_draw
|
|
628
|
+
||
|
|
629
|
+
all(
|
|
630
|
+
vec3f(
|
|
631
|
+
widths[0],
|
|
632
|
+
widths[1],
|
|
633
|
+
widths[2],
|
|
634
|
+
)
|
|
635
|
+
== vec3f(0.0)
|
|
636
|
+
)
|
|
637
|
+
||
|
|
638
|
+
any(
|
|
639
|
+
vec3f(
|
|
640
|
+
colors[0].a,
|
|
641
|
+
colors[1].a,
|
|
642
|
+
colors[2].a,
|
|
643
|
+
)
|
|
644
|
+
< vec3f(0.999)
|
|
645
|
+
);
|
|
646
|
+
}
|
|
647
|
+
|
|
648
|
+
if (nothing_to_draw) {
|
|
649
|
+
out.position = blank;
|
|
650
|
+
return out;
|
|
651
|
+
}
|
|
652
|
+
|
|
653
|
+
let index =
|
|
654
|
+
segment
|
|
655
|
+
+ i32(corner.x);
|
|
656
|
+
|
|
657
|
+
var t = 1.0;
|
|
658
|
+
|
|
659
|
+
if (!joint_fan) {
|
|
660
|
+
t =
|
|
661
|
+
f32(index)
|
|
662
|
+
/ f32(n_steps - 1);
|
|
663
|
+
}
|
|
664
|
+
|
|
665
|
+
var point =
|
|
666
|
+
controls[2];
|
|
667
|
+
|
|
668
|
+
if (!joint_fan) {
|
|
669
|
+
point =
|
|
670
|
+
point_on_quadratic(
|
|
671
|
+
t,
|
|
672
|
+
c0,
|
|
673
|
+
c1,
|
|
674
|
+
c2,
|
|
675
|
+
);
|
|
676
|
+
}
|
|
677
|
+
|
|
678
|
+
let tangent =
|
|
679
|
+
tangent_on_quadratic(
|
|
680
|
+
t,
|
|
681
|
+
c1,
|
|
682
|
+
c2,
|
|
683
|
+
);
|
|
684
|
+
|
|
685
|
+
var own_width =
|
|
686
|
+
mix(
|
|
687
|
+
widths[0],
|
|
688
|
+
widths[2],
|
|
689
|
+
t,
|
|
690
|
+
);
|
|
691
|
+
|
|
692
|
+
if (IS_FILL_BORDER) {
|
|
693
|
+
own_width =
|
|
694
|
+
mob.fill_border_width;
|
|
695
|
+
}
|
|
696
|
+
|
|
697
|
+
let width =
|
|
698
|
+
STROKE_WIDTH_CONVERSION
|
|
699
|
+
* mix(
|
|
700
|
+
get_frame_unit_size(),
|
|
701
|
+
1.0,
|
|
702
|
+
mob.stroke_width_in_scene_units,
|
|
703
|
+
)
|
|
704
|
+
* own_width;
|
|
705
|
+
|
|
706
|
+
let draw_flat =
|
|
707
|
+
mob.flat_stroke != 0.0
|
|
708
|
+
||
|
|
709
|
+
mob.is_fixed_in_frame != 0.0;
|
|
710
|
+
|
|
711
|
+
var facing_normal = get_camera_normal();
|
|
712
|
+
|
|
713
|
+
if (draw_flat) {
|
|
714
|
+
facing_normal = safe_normalize(
|
|
715
|
+
mob.unit_normal,
|
|
716
|
+
vec3f(0.0, 0.0, 1.0),
|
|
717
|
+
);
|
|
718
|
+
}
|
|
719
|
+
|
|
720
|
+
var own_color =
|
|
721
|
+
mix(
|
|
722
|
+
colors[0],
|
|
723
|
+
colors[2],
|
|
724
|
+
t,
|
|
725
|
+
);
|
|
726
|
+
|
|
727
|
+
if (IS_FILL_BORDER) {
|
|
728
|
+
own_color =
|
|
729
|
+
fill_color_at(point);
|
|
730
|
+
}
|
|
731
|
+
|
|
732
|
+
out.color =
|
|
733
|
+
finalize_color(
|
|
734
|
+
own_color,
|
|
735
|
+
point,
|
|
736
|
+
facing_normal,
|
|
737
|
+
);
|
|
738
|
+
|
|
739
|
+
let aaw =
|
|
740
|
+
max(
|
|
741
|
+
mob.anti_alias_width
|
|
742
|
+
* get_pixel_unit_size(),
|
|
743
|
+
1e-15,
|
|
744
|
+
);
|
|
745
|
+
|
|
746
|
+
let half_width =
|
|
747
|
+
0.5
|
|
748
|
+
* (
|
|
749
|
+
width
|
|
750
|
+
+ aaw
|
|
751
|
+
);
|
|
752
|
+
|
|
753
|
+
let at_start =
|
|
754
|
+
!joint_fan
|
|
755
|
+
&&
|
|
756
|
+
index == 0;
|
|
757
|
+
|
|
758
|
+
let at_joint =
|
|
759
|
+
joint_fan
|
|
760
|
+
||
|
|
761
|
+
at_start
|
|
762
|
+
||
|
|
763
|
+
index == n_steps - 1;
|
|
764
|
+
|
|
765
|
+
var neighbor =
|
|
766
|
+
vec3f(0.0);
|
|
767
|
+
|
|
768
|
+
if (at_joint) {
|
|
769
|
+
neighbor =
|
|
770
|
+
neighbor_tangent(
|
|
771
|
+
i32(record),
|
|
772
|
+
subpath,
|
|
773
|
+
at_start,
|
|
774
|
+
point,
|
|
775
|
+
);
|
|
776
|
+
}
|
|
777
|
+
|
|
778
|
+
var has_joint =
|
|
779
|
+
at_joint
|
|
780
|
+
&& !is_degenerate(neighbor);
|
|
781
|
+
|
|
782
|
+
var shift = 0.0;
|
|
783
|
+
|
|
784
|
+
if (has_joint) {
|
|
785
|
+
if (at_start) {
|
|
786
|
+
shift =
|
|
787
|
+
-joint_shift(
|
|
788
|
+
point,
|
|
789
|
+
neighbor,
|
|
790
|
+
tangent,
|
|
791
|
+
facing_normal,
|
|
792
|
+
draw_flat,
|
|
793
|
+
);
|
|
794
|
+
}
|
|
795
|
+
else {
|
|
796
|
+
shift =
|
|
797
|
+
joint_shift(
|
|
798
|
+
point,
|
|
799
|
+
tangent,
|
|
800
|
+
neighbor,
|
|
801
|
+
facing_normal,
|
|
802
|
+
draw_flat,
|
|
803
|
+
);
|
|
804
|
+
}
|
|
805
|
+
}
|
|
806
|
+
|
|
807
|
+
var step: vec3f;
|
|
808
|
+
var dist_to_curve: f32;
|
|
809
|
+
var edge_dist: f32;
|
|
810
|
+
|
|
811
|
+
if (joint_fan) {
|
|
812
|
+
if (!has_joint) {
|
|
813
|
+
out.position = blank;
|
|
814
|
+
return out;
|
|
815
|
+
}
|
|
816
|
+
|
|
817
|
+
if (!draw_flat) {
|
|
818
|
+
let basis = get_camera_basis();
|
|
819
|
+
let R = basis[0];
|
|
820
|
+
let U = basis[1];
|
|
821
|
+
|
|
822
|
+
let a = get_screen_tangent(point, tangent);
|
|
823
|
+
let b = get_screen_tangent(point, neighbor);
|
|
824
|
+
|
|
825
|
+
let perp_a = vec2f(-a.y, a.x);
|
|
826
|
+
let perp_b = vec2f(-b.y, b.x);
|
|
827
|
+
|
|
828
|
+
var outward = -1.0;
|
|
829
|
+
if (a.x * b.y - a.y * b.x < 0.0) {
|
|
830
|
+
outward = 1.0;
|
|
831
|
+
}
|
|
832
|
+
|
|
833
|
+
let edge_in_2d = outward * safe_normalize_2d(perp_a + shift * a, perp_a);
|
|
834
|
+
let edge_out_2d = outward * safe_normalize_2d(perp_b - shift * b, perp_b);
|
|
835
|
+
|
|
836
|
+
let sweep = atan2(
|
|
837
|
+
edge_in_2d.x * edge_out_2d.y - edge_in_2d.y * edge_out_2d.x,
|
|
838
|
+
dot(edge_in_2d, edge_out_2d),
|
|
839
|
+
);
|
|
840
|
+
|
|
841
|
+
if (abs(sweep) < 1e-5) {
|
|
842
|
+
out.position = blank;
|
|
843
|
+
return out;
|
|
844
|
+
}
|
|
845
|
+
|
|
846
|
+
let fan_tri =
|
|
847
|
+
2 * (segment - POLYLINE_SEGMENTS) + tri_vert / 3;
|
|
848
|
+
|
|
849
|
+
let fan_vert = tri_vert % 3;
|
|
850
|
+
|
|
851
|
+
let along =
|
|
852
|
+
f32(fan_tri + fan_vert - 1) / f32(FAN_TRIANGLES);
|
|
853
|
+
|
|
854
|
+
let angle = along * sweep;
|
|
855
|
+
let c = cos(angle);
|
|
856
|
+
let s = sin(angle);
|
|
857
|
+
let rotated_2d = vec2f(
|
|
858
|
+
edge_in_2d.x * c - edge_in_2d.y * s,
|
|
859
|
+
edge_in_2d.x * s + edge_in_2d.y * c,
|
|
860
|
+
);
|
|
861
|
+
|
|
862
|
+
step = rotated_2d.x * R + rotated_2d.y * U;
|
|
863
|
+
|
|
864
|
+
edge_dist =
|
|
865
|
+
sqrt(1.0 + shift * shift) * 0.5 * width;
|
|
866
|
+
|
|
867
|
+
dist_to_curve = 0.0;
|
|
868
|
+
|
|
869
|
+
if (fan_vert != 0) {
|
|
870
|
+
dist_to_curve =
|
|
871
|
+
edge_dist + 0.5 * aaw;
|
|
872
|
+
}
|
|
873
|
+
}
|
|
874
|
+
else {
|
|
875
|
+
/*
|
|
876
|
+
The fan normally joins the incoming and outgoing strips.
|
|
877
|
+
|
|
878
|
+
If one of the tangents is degenerate, do NOT discard the whole fan.
|
|
879
|
+
Instead construct a local round cap using the valid tangent.
|
|
880
|
+
|
|
881
|
+
This is the important change for complex VMobjects/text.
|
|
882
|
+
*/
|
|
883
|
+
var tan_in = flat_tangent(
|
|
884
|
+
tangent,
|
|
885
|
+
facing_normal,
|
|
886
|
+
);
|
|
887
|
+
|
|
888
|
+
var tan_out = flat_tangent(
|
|
889
|
+
neighbor,
|
|
890
|
+
facing_normal,
|
|
891
|
+
);
|
|
892
|
+
|
|
893
|
+
/*
|
|
894
|
+
If the neighboring tangent is unavailable, use the current tangent.
|
|
895
|
+
This turns the fan into a round cap instead of creating a hole.
|
|
896
|
+
*/
|
|
897
|
+
if (is_degenerate(tan_out)) {
|
|
898
|
+
tan_out = tan_in;
|
|
899
|
+
}
|
|
900
|
+
|
|
901
|
+
if (is_degenerate(tan_in)) {
|
|
902
|
+
tan_in = tan_out;
|
|
903
|
+
}
|
|
904
|
+
|
|
905
|
+
/*
|
|
906
|
+
If both are still unavailable, fall back to a stable direction derived from
|
|
907
|
+
the object's normal. This prevents NaNs and, importantly, prevents an entire
|
|
908
|
+
reserved fan from disappearing.
|
|
909
|
+
*/
|
|
910
|
+
if (is_degenerate(tan_in) && is_degenerate(tan_out)) {
|
|
911
|
+
let fallback_axis = safe_normalize(
|
|
912
|
+
cross(
|
|
913
|
+
facing_normal,
|
|
914
|
+
mob.unit_normal,
|
|
915
|
+
),
|
|
916
|
+
vec3f(1.0, 0.0, 0.0),
|
|
917
|
+
);
|
|
918
|
+
|
|
919
|
+
tan_in = fallback_axis;
|
|
920
|
+
tan_out = fallback_axis;
|
|
921
|
+
|
|
922
|
+
has_joint = false;
|
|
923
|
+
}
|
|
924
|
+
|
|
925
|
+
var outward = -1.0;
|
|
926
|
+
|
|
927
|
+
if (
|
|
928
|
+
dot(
|
|
929
|
+
cross(
|
|
930
|
+
tan_in,
|
|
931
|
+
tan_out,
|
|
932
|
+
),
|
|
933
|
+
facing_normal,
|
|
934
|
+
) < 0.0
|
|
935
|
+
) {
|
|
936
|
+
outward = 1.0;
|
|
937
|
+
}
|
|
938
|
+
|
|
939
|
+
/*
|
|
940
|
+
Construct the incoming and outgoing edge directions.
|
|
941
|
+
|
|
942
|
+
Unlike the previous version, normalize() is never applied to a vector that
|
|
943
|
+
has not first been checked for degeneracy.
|
|
944
|
+
*/
|
|
945
|
+
var edge_in_raw =
|
|
946
|
+
cross(
|
|
947
|
+
facing_normal,
|
|
948
|
+
tan_in,
|
|
949
|
+
)
|
|
950
|
+
+ shift * tan_in;
|
|
951
|
+
|
|
952
|
+
var edge_out_raw =
|
|
953
|
+
cross(
|
|
954
|
+
facing_normal,
|
|
955
|
+
tan_out,
|
|
956
|
+
)
|
|
957
|
+
- shift * tan_out;
|
|
958
|
+
|
|
959
|
+
var edge_in = safe_normalize(
|
|
960
|
+
edge_in_raw,
|
|
961
|
+
cross(
|
|
962
|
+
facing_normal,
|
|
963
|
+
tan_in,
|
|
964
|
+
),
|
|
965
|
+
);
|
|
966
|
+
|
|
967
|
+
var edge_out = safe_normalize(
|
|
968
|
+
edge_out_raw,
|
|
969
|
+
cross(
|
|
970
|
+
facing_normal,
|
|
971
|
+
tan_out,
|
|
972
|
+
),
|
|
973
|
+
);
|
|
974
|
+
|
|
975
|
+
/*
|
|
976
|
+
A completely degenerate camera/normal configuration should still produce
|
|
977
|
+
finite geometry.
|
|
978
|
+
*/
|
|
979
|
+
if (is_degenerate(edge_in)) {
|
|
980
|
+
edge_in = safe_normalize(
|
|
981
|
+
cross(
|
|
982
|
+
mob.unit_normal,
|
|
983
|
+
tan_in,
|
|
984
|
+
),
|
|
985
|
+
vec3f(1.0, 0.0, 0.0),
|
|
986
|
+
);
|
|
987
|
+
}
|
|
988
|
+
|
|
989
|
+
if (is_degenerate(edge_out)) {
|
|
990
|
+
edge_out = safe_normalize(
|
|
991
|
+
cross(
|
|
992
|
+
mob.unit_normal,
|
|
993
|
+
tan_out,
|
|
994
|
+
),
|
|
995
|
+
edge_in,
|
|
996
|
+
);
|
|
997
|
+
}
|
|
998
|
+
|
|
999
|
+
edge_in *= outward;
|
|
1000
|
+
edge_out *= outward;
|
|
1001
|
+
|
|
1002
|
+
let sweep = atan2(
|
|
1003
|
+
dot(
|
|
1004
|
+
cross(
|
|
1005
|
+
edge_in,
|
|
1006
|
+
edge_out,
|
|
1007
|
+
),
|
|
1008
|
+
facing_normal,
|
|
1009
|
+
),
|
|
1010
|
+
dot(
|
|
1011
|
+
edge_in,
|
|
1012
|
+
edge_out,
|
|
1013
|
+
),
|
|
1014
|
+
);
|
|
1015
|
+
|
|
1016
|
+
/*
|
|
1017
|
+
Of each triangle's three vertices, one sits at the joint and two on the arc.
|
|
1018
|
+
*/
|
|
1019
|
+
let fan_tri =
|
|
1020
|
+
2 * (
|
|
1021
|
+
segment - POLYLINE_SEGMENTS
|
|
1022
|
+
)
|
|
1023
|
+
+ tri_vert / 3;
|
|
1024
|
+
|
|
1025
|
+
let fan_vert = tri_vert % 3;
|
|
1026
|
+
|
|
1027
|
+
let along =
|
|
1028
|
+
f32(
|
|
1029
|
+
fan_tri
|
|
1030
|
+
+ fan_vert
|
|
1031
|
+
- 1
|
|
1032
|
+
)
|
|
1033
|
+
/ f32(FAN_TRIANGLES);
|
|
1034
|
+
|
|
1035
|
+
step = rotate_vector(
|
|
1036
|
+
edge_in,
|
|
1037
|
+
facing_normal,
|
|
1038
|
+
vec2f(
|
|
1039
|
+
cos(along * sweep),
|
|
1040
|
+
sin(along * sweep),
|
|
1041
|
+
),
|
|
1042
|
+
);
|
|
1043
|
+
|
|
1044
|
+
/*
|
|
1045
|
+
The corners reach out by this much, being a step out plus a shift along.
|
|
1046
|
+
*/
|
|
1047
|
+
edge_dist = sqrt(
|
|
1048
|
+
max(
|
|
1049
|
+
1.0 + shift * shift,
|
|
1050
|
+
0.0,
|
|
1051
|
+
)
|
|
1052
|
+
) * 0.5 * width;
|
|
1053
|
+
|
|
1054
|
+
dist_to_curve = 0.0;
|
|
1055
|
+
|
|
1056
|
+
if (fan_vert != 0) {
|
|
1057
|
+
dist_to_curve =
|
|
1058
|
+
edge_dist
|
|
1059
|
+
+ 0.5 * aaw;
|
|
1060
|
+
}
|
|
1061
|
+
}
|
|
1062
|
+
}
|
|
1063
|
+
else {
|
|
1064
|
+
step =
|
|
1065
|
+
step_to_corner(
|
|
1066
|
+
point,
|
|
1067
|
+
tangent,
|
|
1068
|
+
facing_normal,
|
|
1069
|
+
shift,
|
|
1070
|
+
draw_flat,
|
|
1071
|
+
);
|
|
1072
|
+
|
|
1073
|
+
edge_dist =
|
|
1074
|
+
0.5 * width;
|
|
1075
|
+
|
|
1076
|
+
dist_to_curve =
|
|
1077
|
+
corner.y
|
|
1078
|
+
* half_width;
|
|
1079
|
+
}
|
|
1080
|
+
|
|
1081
|
+
out.half_width_to_aaw =
|
|
1082
|
+
edge_dist / aaw;
|
|
1083
|
+
|
|
1084
|
+
out.dist_to_aaw =
|
|
1085
|
+
dist_to_curve / aaw;
|
|
1086
|
+
|
|
1087
|
+
let projection =
|
|
1088
|
+
project_point(
|
|
1089
|
+
point
|
|
1090
|
+
+ dist_to_curve * step,
|
|
1091
|
+
);
|
|
1092
|
+
|
|
1093
|
+
out.position =
|
|
1094
|
+
projection.position;
|
|
1095
|
+
|
|
1096
|
+
out.clip_distances =
|
|
1097
|
+
projection.clip_distances;
|
|
1098
|
+
|
|
1099
|
+
return out;
|
|
1100
|
+
}
|
|
1101
|
+
|
|
1102
|
+
|
|
1103
|
+
@fragment
|
|
1104
|
+
fn fs_main(
|
|
1105
|
+
in: VertexOutput,
|
|
1106
|
+
) -> @location(0) vec4f {
|
|
1107
|
+
clip_test(
|
|
1108
|
+
in.clip_distances
|
|
1109
|
+
);
|
|
1110
|
+
|
|
1111
|
+
/*
|
|
1112
|
+
Reconstruct the exact signed distance used by the visible stroke.
|
|
1113
|
+
*/
|
|
1114
|
+
let signed_dist_to_region =
|
|
1115
|
+
abs(in.dist_to_aaw)
|
|
1116
|
+
- in.half_width_to_aaw;
|
|
1117
|
+
|
|
1118
|
+
/*
|
|
1119
|
+
Unlike the normal stroke shader, the anti-alias fringe must NOT receive
|
|
1120
|
+
depth. Otherwise the fringe itself would occlude geometry behind it.
|
|
1121
|
+
|
|
1122
|
+
Keep the interior and the geometric edge.
|
|
1123
|
+
*/
|
|
1124
|
+
if (
|
|
1125
|
+
signed_dist_to_region > 0.0
|
|
1126
|
+
||
|
|
1127
|
+
in.color.a < 0.999
|
|
1128
|
+
) {
|
|
1129
|
+
discard;
|
|
1130
|
+
}
|
|
1131
|
+
|
|
1132
|
+
/*
|
|
1133
|
+
For the depth-only pipeline the color value is ignored.
|
|
1134
|
+
*/
|
|
1135
|
+
return in.color;
|
|
1136
|
+
}
|