rrtrace 0.1.0 → 0.2.0

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.
data/src/shader.wgsl CHANGED
@@ -1,115 +1,160 @@
1
- struct Vertex {
2
- @location(0) position: vec3<f32>,
3
- }
4
-
5
- struct CallBox {
6
- @location(1) start_time: vec2<u32>,
7
- @location(2) end_time: vec2<u32>,
8
- @location(3) method_id: u32,
9
- @location(4) depth: u32,
10
- }
11
-
12
- struct GCBox {
13
- @location(1) time: vec2<u32>,
14
- }
15
-
16
- struct CameraUniform {
17
- view_proj: mat4x4<f32>,
18
- base_time: vec2<u32>, // x: lo, y: hi
19
- max_depth: u32,
20
- num_threads: u32,
21
- }
22
-
23
- struct ThreadInfo {
24
- lane_id: u32,
25
- }
26
-
27
- @group(0) @binding(0)
28
- var<uniform> camera: CameraUniform;
29
-
30
- @group(0) @binding(1)
31
- var<uniform> thread_info: ThreadInfo;
32
-
33
- struct VertexOutput {
34
- @builtin(position) clip_position: vec4<f32>,
35
- @location(0) color: vec4<f32>,
36
- }
37
-
38
- fn sub64(a: vec2<u32>, b: vec2<u32>) -> vec2<u32> {
39
- if (a.x < b.x) {
40
- let lo = a.x + 0x80000000u - b.x;
41
- let hi = a.y - 1 - b.y;
42
- return vec2<u32>(lo, hi);
43
- } else {
44
- let lo = a.x - b.x;
45
- let hi = a.y - b.y;
46
- return vec2<u32>(lo, hi);
47
- }
48
- }
49
-
50
- fn u64tof32(v: vec2<u32>) -> f32 {
51
- return f32(v.y) * 2147483648.0 + f32(v.x);
52
- }
53
-
54
- fn get_color(method_id: u32) -> vec4<f32> {
55
- let m = method_id;
56
- let r = f32((m * 123u) % 255u) / 255.0;
57
- let g = f32((m * 456u) % 255u) / 255.0;
58
- let b = f32((m * 789u) % 255u) / 255.0;
59
- return vec4<f32>(r, g, b, 1.0);
60
- }
61
-
62
- @vertex
63
- fn vs_main(
64
- v: Vertex,
65
- call: CallBox,
66
- ) -> VertexOutput {
67
- var end_time: vec2<u32>;
68
- if (call.end_time.y == 0xffffffffu) {
69
- end_time = vec2<u32>(0, 0);
70
- } else {
71
- end_time = sub64(camera.base_time, call.end_time);
72
- }
73
- let start_time = sub64(camera.base_time, call.start_time);
74
-
75
- let x = select(start_time, end_time, v.position.x > 0.5);
76
-
77
- let world_pos = vec3<f32>(
78
- u64tof32(x) / 500000000.0,
79
- (f32(call.depth) + v.position.y) / f32(camera.max_depth),
80
- (f32(thread_info.lane_id) + v.position.z) / f32(camera.num_threads),
81
- );
82
-
83
- var out: VertexOutput;
84
- out.color = get_color(call.method_id);
85
- out.clip_position = camera.view_proj * vec4<f32>(world_pos, 1.0);
86
- return out;
87
- }
88
-
89
- @fragment
90
- fn fs_main(in: VertexOutput) -> @location(0) vec4<f32> {
91
- return in.color;
92
- }
93
-
94
- struct GCVertex {
95
- @location(0) position: vec2<f32>,
96
- }
97
-
98
- @vertex
99
- fn vs_gc(
100
- v: GCVertex,
101
- gc: GCBox,
102
- ) -> VertexOutput {
103
- let time = sub64(camera.base_time, gc.time);
104
-
105
- let world_pos = vec3<f32>(
106
- u64tof32(time) / 500000000.0,
107
- v.position.x,
108
- v.position.y,
109
- );
110
-
111
- var out: VertexOutput;
112
- out.color = vec4<f32>(1.0, 0.5, 0.0, 0.1);
113
- out.clip_position = camera.view_proj * vec4<f32>(world_pos, 1.0);
114
- return out;
115
- }
1
+ struct Vertex {
2
+ @location(0) position: vec3<f32>,
3
+ }
4
+
5
+ struct CallBox {
6
+ @location(1) start_time: vec2<u32>,
7
+ @location(2) end_time: vec2<u32>,
8
+ @location(3) method_id: u32,
9
+ @location(4) depth: u32,
10
+ }
11
+
12
+ struct GCBox {
13
+ @location(1) time: vec2<u32>,
14
+ }
15
+
16
+ struct LineVertex {
17
+ @location(0) position: f32,
18
+ }
19
+
20
+ struct LineSegment {
21
+ @location(1) start_time: vec2<u32>,
22
+ @location(2) end_time: vec2<u32>,
23
+ @location(3) start_pos: vec3<f32>,
24
+ @location(4) end_pos: vec3<f32>,
25
+ @location(5) color: vec4<f32>,
26
+ @location(6) kind: u32,
27
+ }
28
+
29
+ struct CameraUniform {
30
+ view_proj: mat4x4<f32>,
31
+ base_time: vec2<u32>, // x: lo, y: hi
32
+ max_depth: u32,
33
+ num_threads: u32,
34
+ }
35
+
36
+ struct ThreadInfo {
37
+ lane_id: u32,
38
+ }
39
+
40
+ @group(0) @binding(0)
41
+ var<uniform> camera: CameraUniform;
42
+
43
+ @group(0) @binding(1)
44
+ var<uniform> thread_info: ThreadInfo;
45
+
46
+ struct VertexOutput {
47
+ @builtin(position) clip_position: vec4<f32>,
48
+ @location(0) color: vec4<f32>,
49
+ }
50
+
51
+ fn sub64(a: vec2<u32>, b: vec2<u32>) -> vec2<u32> {
52
+ if (a.x < b.x) {
53
+ let lo = a.x + 0x80000000u - b.x;
54
+ let hi = a.y - 1 - b.y;
55
+ return vec2<u32>(lo, hi);
56
+ } else {
57
+ let lo = a.x - b.x;
58
+ let hi = a.y - b.y;
59
+ return vec2<u32>(lo, hi);
60
+ }
61
+ }
62
+
63
+ fn u64tof32(v: vec2<u32>) -> f32 {
64
+ return f32(v.y) * 2147483648.0 + f32(v.x);
65
+ }
66
+
67
+ fn get_color(method_id: u32) -> vec4<f32> {
68
+ let m = method_id;
69
+ let r = f32((m * 123u) % 255u) / 255.0;
70
+ let g = f32((m * 456u) % 255u) / 255.0;
71
+ let b = f32((m * 789u) % 255u) / 255.0;
72
+ return vec4<f32>(r, g, b, 1.0);
73
+ }
74
+
75
+ @vertex
76
+ fn vs_main(
77
+ v: Vertex,
78
+ call: CallBox,
79
+ ) -> VertexOutput {
80
+ var end_time: vec2<u32>;
81
+ if (call.end_time.y == 0xffffffffu) {
82
+ end_time = vec2<u32>(0, 0);
83
+ } else {
84
+ end_time = sub64(camera.base_time, call.end_time);
85
+ }
86
+ let start_time = sub64(camera.base_time, call.start_time);
87
+
88
+ let x = select(start_time, end_time, v.position.x > 0.5);
89
+
90
+ let world_pos = vec3<f32>(
91
+ u64tof32(x) / 500000000.0,
92
+ (f32(call.depth) + v.position.y) / f32(camera.max_depth),
93
+ (f32(thread_info.lane_id) + v.position.z) / f32(camera.num_threads),
94
+ );
95
+
96
+ var out: VertexOutput;
97
+ out.color = get_color(call.method_id);
98
+ out.clip_position = camera.view_proj * vec4<f32>(world_pos, 1.0);
99
+ return out;
100
+ }
101
+
102
+ @fragment
103
+ fn fs_main(in: VertexOutput) -> @location(0) vec4<f32> {
104
+ return in.color;
105
+ }
106
+
107
+ @vertex
108
+ fn vs_line(
109
+ v: LineVertex,
110
+ segment: LineSegment,
111
+ ) -> VertexOutput {
112
+ let t = v.position;
113
+ let start_x = select(
114
+ segment.start_pos.x,
115
+ u64tof32(sub64(camera.base_time, segment.start_time)) / 500000000.0,
116
+ segment.kind == 0u,
117
+ );
118
+ let end_x = select(
119
+ segment.end_pos.x,
120
+ u64tof32(sub64(camera.base_time, segment.end_time)) / 500000000.0,
121
+ segment.kind == 0u,
122
+ );
123
+ let world_pos = vec3<f32>(
124
+ mix(start_x, end_x, t),
125
+ mix(segment.start_pos.y, segment.end_pos.y, t),
126
+ mix(
127
+ segment.start_pos.z / f32(max(camera.num_threads, 1u)),
128
+ segment.end_pos.z / f32(max(camera.num_threads, 1u)),
129
+ t,
130
+ ),
131
+ );
132
+
133
+ var out: VertexOutput;
134
+ out.color = segment.color;
135
+ out.clip_position = camera.view_proj * vec4<f32>(world_pos, 1.0);
136
+ return out;
137
+ }
138
+
139
+ struct GCVertex {
140
+ @location(0) position: vec2<f32>,
141
+ }
142
+
143
+ @vertex
144
+ fn vs_gc(
145
+ v: GCVertex,
146
+ gc: GCBox,
147
+ ) -> VertexOutput {
148
+ let time = sub64(camera.base_time, gc.time);
149
+
150
+ let world_pos = vec3<f32>(
151
+ u64tof32(time) / 500000000.0,
152
+ v.position.x,
153
+ v.position.y,
154
+ );
155
+
156
+ var out: VertexOutput;
157
+ out.color = vec4<f32>(1.0, 0.5, 0.0, 0.1);
158
+ out.clip_position = camera.view_proj * vec4<f32>(world_pos, 1.0);
159
+ return out;
160
+ }