Search across packages, versions, files, declarations, and comments. Use multiple terms to narrow results (AND), and add @vertex, @fragment, or @compute to filter by shader stage.
1#define_import_path bevy_gaussian_splatting::spherical_harmonics
4const shc = array<f32, 16>(
5 0.28209479177387814,
6 -0.4886025119029199,
7 0.4886025119029199,
8 -0.4886025119029199,
9 1.0925484305920792,
10 -1.0925484305920792,
11 0.31539156525252005,
12 -1.0925484305920792,
13 0.5462742152960396,
14 -0.5900435899266435,
15 2.890611442640554,
16 -0.4570457994644658,
17 0.3731763325901154,
18 -0.4570457994644658,
19 1.445305721320277,
20 -0.5900435899266435,
21);
23fn srgb_to_linear(srgb_color: vec3<f32>) -> vec3<f32> {
24 var linear_color: vec3<f32>;
25 for (var i = 0u; i < 3u; i = i + 1u) {
26 if (srgb_color[i] <= 0.04045) {
27 linear_color[i] = srgb_color[i] / 12.92;
28 } else {
29 linear_color[i] = pow((srgb_color[i] + 0.055) / 1.055, 2.4);
30 }
31 }
32 return linear_color;
35fn spherical_harmonics_lookup(
36 ray_direction: vec3<f32>,
37 sh: array<f32, #{SH_COEFF_COUNT}>,
38) -> vec3<f32> {
39 let rds = ray_direction * ray_direction;
40 var color = vec3<f32>(0.5);
42 color += shc[ 0] * vec3<f32>(sh[0], sh[1], sh[2]);
44#if SH_COEFF_COUNT > 11
45 color += shc[ 1] * vec3<f32>(sh[ 3], sh[ 4], sh[ 5]) * ray_direction.y;
46 color += shc[ 2] * vec3<f32>(sh[ 6], sh[ 7], sh[ 8]) * ray_direction.z;
47 color += shc[ 3] * vec3<f32>(sh[ 9], sh[10], sh[11]) * ray_direction.x;
48#endif
50#if SH_COEFF_COUNT > 26
51 color += shc[ 4] * vec3<f32>(sh[12], sh[13], sh[14]) * ray_direction.x * ray_direction.y;
52 color += shc[ 5] * vec3<f32>(sh[15], sh[16], sh[17]) * ray_direction.y * ray_direction.z;
53 color += shc[ 6] * vec3<f32>(sh[18], sh[19], sh[20]) * (2.0 * rds.z - rds.x - rds.y);
54 color += shc[ 7] * vec3<f32>(sh[21], sh[22], sh[23]) * ray_direction.x * ray_direction.z;
55 color += shc[ 8] * vec3<f32>(sh[24], sh[25], sh[26]) * (rds.x - rds.y);
56#endif
58#if SH_COEFF_COUNT > 47
59 color += shc[ 9] * vec3<f32>(sh[27], sh[28], sh[29]) * ray_direction.y * (3.0 * rds.x - rds.y);
60 color += shc[10] * vec3<f32>(sh[30], sh[31], sh[32]) * ray_direction.x * ray_direction.y * ray_direction.z;
61 color += shc[11] * vec3<f32>(sh[33], sh[34], sh[35]) * ray_direction.y * (4.0 * rds.z - rds.x - rds.y);
62 color += shc[12] * vec3<f32>(sh[36], sh[37], sh[38]) * ray_direction.z * (2.0 * rds.z - 3.0 * rds.x - 3.0 * rds.y);
63 color += shc[13] * vec3<f32>(sh[39], sh[40], sh[41]) * ray_direction.x * (4.0 * rds.z - rds.x - rds.y);
64 color += shc[14] * vec3<f32>(sh[42], sh[43], sh[44]) * ray_direction.z * (rds.x - rds.y);
65 color += shc[15] * vec3<f32>(sh[45], sh[46], sh[47]) * ray_direction.x * (rds.x - 3.0 * rds.y);
66#endif
68 return color;
Contents