@@ -7,41 +7,73 @@ fn unpack111011s(bits: u32) -> vec3f {
7
7
return (vec3f((vec3<u32>(bits) >> vec3<u32>(21u, 11u, 0u)) & vec3<u32>(0x7ffu, 0x3ffu, 0x7ffu)) / vec3f(2047.0, 1023.0, 2047.0)) * 2.0 - 1.0;
8
8
}
9
9
10
+ struct ScaleAndSH {
11
+ scale: f32,
12
+ a: vec3f,
13
+ b: vec3f,
14
+ c: vec3f
15
+ };
16
+
10
17
// fetch quantized spherical harmonic coefficients
11
- fn fetchScale(t_in: vec4<u32>, scale: ptr<function, f32>, a: ptr<function, vec3f>, b: ptr<function, vec3f>, c: ptr<function, vec3f>) {
12
- *scale = bitcast<f32>(t_in.x);
13
- *a = unpack111011s(t_in.y);
14
- *b = unpack111011s(t_in.z);
15
- *c = unpack111011s(t_in.w);
18
+ fn fetchScale(t_in: vec4<u32>) -> ScaleAndSH {
19
+ var result: ScaleAndSH;
20
+ result.scale = bitcast<f32>(t_in.x);
21
+ result.a = unpack111011s(t_in.y);
22
+ result.b = unpack111011s(t_in.z);
23
+ result.c = unpack111011s(t_in.w);
24
+ return result;
16
25
}
17
26
27
+ struct SH {
28
+ a: vec3f,
29
+ b: vec3f,
30
+ c: vec3f,
31
+ d: vec3f
32
+ };
33
+
18
34
// fetch quantized spherical harmonic coefficients
19
- fn fetch4(t_in: vec4<u32>, a: ptr<function, vec3f>, b: ptr<function, vec3f>, c: ptr<function, vec3f>, d: ptr<function, vec3f>) {
20
- *a = unpack111011s(t_in.x);
21
- *b = unpack111011s(t_in.y);
22
- *c = unpack111011s(t_in.z);
23
- *d = unpack111011s(t_in.w);
35
+ fn fetch4(t_in: vec4<u32>) -> SH {
36
+ var result: SH;
37
+ result.a = unpack111011s(t_in.x);
38
+ result.b = unpack111011s(t_in.y);
39
+ result.c = unpack111011s(t_in.z);
40
+ result.d = unpack111011s(t_in.w);
41
+ return result;
24
42
}
25
43
26
- fn fetch1(t_in: u32, a: ptr<function, vec3f>) {
27
- *a = unpack111011s(t_in);
44
+ fn fetch1(t_in: u32) -> vec3f {
45
+ return unpack111011s(t_in);
28
46
}
29
47
30
48
#if SH_BANDS == 1
31
49
var splatSH_1to3: texture_2d<u32>;
32
50
33
51
fn readSHData(source: ptr<function, SplatSource>, sh: ptr<function, array<vec3f, 3>>, scale: ptr<function, f32>) {
34
- fetchScale(textureLoad(splatSH_1to3, source.uv, 0), scale, &sh[0], &sh[1], &sh[2]);
52
+ let result = fetchScale(textureLoad(splatSH_1to3, source.uv, 0));
53
+ *scale = result.scale;
54
+ sh[0] = result.a;
55
+ sh[1] = result.b;
56
+ sh[2] = result.c;
35
57
}
36
58
#elif SH_BANDS == 2
37
59
var splatSH_1to3: texture_2d<u32>;
38
60
var splatSH_4to7: texture_2d<u32>;
39
61
var splatSH_8to11: texture_2d<u32>;
40
62
41
63
fn readSHData(source: ptr<function, SplatSource>, sh: ptr<function, array<vec3f, 8>>, scale: ptr<function, f32>) {
42
- fetchScale(textureLoad(splatSH_1to3, source.uv, 0), scale, &sh[0], &sh[1], &sh[2]);
43
- fetch4(textureLoad(splatSH_4to7, source.uv, 0), &sh[3], &sh[4], &sh[5], &sh[6]);
44
- fetch1(textureLoad(splatSH_8to11, source.uv, 0).x, &sh[7]);
64
+ let first: ScaleAndSH = fetchScale(textureLoad(splatSH_1to3, source.uv, 0));
65
+ *scale = first.scale;
66
+ sh[0] = first.a;
67
+ sh[1] = first.b;
68
+ sh[2] = first.c;
69
+
70
+ let second: SH = fetch4(textureLoad(splatSH_4to7, source.uv, 0));
71
+ sh[3] = second.a;
72
+ sh[4] = second.b;
73
+ sh[5] = second.c;
74
+ sh[6] = second.d;
75
+
76
+ sh[7] = fetch1(textureLoad(splatSH_8to11, source.uv, 0).x);
45
77
}
46
78
#else
47
79
var splatSH_1to3: texture_2d<u32>;
@@ -50,10 +82,29 @@ fn fetch1(t_in: u32, a: ptr<function, vec3f>) {
50
82
var splatSH_12to15: texture_2d<u32>;
51
83
52
84
fn readSHData(source: ptr<function, SplatSource>, sh: ptr<function, array<vec3f, 15>>, scale: ptr<function, f32>) {
53
- fetchScale(textureLoad(splatSH_1to3, source.uv, 0), scale, &sh[0], &sh[1], &sh[2]);
54
- fetch4(textureLoad(splatSH_4to7, source.uv, 0), &sh[3], &sh[4], &sh[5], &sh[6]);
55
- fetch4(textureLoad(splatSH_8to11, source.uv, 0), &sh[7], &sh[8], &sh[9], &sh[10]);
56
- fetch4(textureLoad(splatSH_12to15, source.uv, 0), &sh[11], &sh[12], &sh[13], &sh[14]);
85
+ let first: ScaleAndSH = fetchScale(textureLoad(splatSH_1to3, source.uv, 0));
86
+ *scale = first.scale;
87
+ sh[0] = first.a;
88
+ sh[1] = first.b;
89
+ sh[2] = first.c;
90
+
91
+ let second: SH = fetch4(textureLoad(splatSH_4to7, source.uv, 0));
92
+ sh[3] = second.a;
93
+ sh[4] = second.b;
94
+ sh[5] = second.c;
95
+ sh[6] = second.d;
96
+
97
+ let third: SH = fetch4(textureLoad(splatSH_8to11, source.uv, 0));
98
+ sh[7] = third.a;
99
+ sh[8] = third.b;
100
+ sh[9] = third.c;
101
+ sh[10] = third.d;
102
+
103
+ let fourth: SH = fetch4(textureLoad(splatSH_12to15, source.uv, 0));
104
+ sh[11] = fourth.a;
105
+ sh[12] = fourth.b;
106
+ sh[13] = fourth.c;
107
+ sh[14] = fourth.d;
57
108
}
58
109
#endif
59
110
0 commit comments