@driftengine/splats 3.61.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.
Files changed (71) hide show
  1. package/LICENSE +202 -0
  2. package/NOTICE +9 -0
  3. package/README.md +56 -0
  4. package/dist/half.d.ts +32 -0
  5. package/dist/half.js +88 -0
  6. package/dist/index.d.ts +32 -0
  7. package/dist/index.js +38 -0
  8. package/dist/shaders/generated/splat.wgsl.d.ts +89 -0
  9. package/dist/shaders/generated/splat.wgsl.js +95 -0
  10. package/dist/shaders/splat.d.ts +25 -0
  11. package/dist/shaders/splat.js +337 -0
  12. package/dist/splat.d.ts +26 -0
  13. package/dist/splat.js +63 -0
  14. package/dist/splatBudget.d.ts +40 -0
  15. package/dist/splatBudget.js +45 -0
  16. package/dist/splatCapture.d.ts +76 -0
  17. package/dist/splatCapture.js +108 -0
  18. package/dist/splatCull.d.ts +25 -0
  19. package/dist/splatCull.js +80 -0
  20. package/dist/splatData.d.ts +177 -0
  21. package/dist/splatData.js +223 -0
  22. package/dist/splatGl.d.ts +49 -0
  23. package/dist/splatGl.js +176 -0
  24. package/dist/splatGpu.d.ts +50 -0
  25. package/dist/splatGpu.js +180 -0
  26. package/dist/splatLayout.d.ts +52 -0
  27. package/dist/splatLayout.js +75 -0
  28. package/dist/splatMatrix.d.ts +29 -0
  29. package/dist/splatMatrix.js +68 -0
  30. package/dist/splatPass.d.ts +83 -0
  31. package/dist/splatPass.js +206 -0
  32. package/dist/splatPly.d.ts +14 -0
  33. package/dist/splatPly.js +242 -0
  34. package/dist/splatSog.d.ts +110 -0
  35. package/dist/splatSog.js +285 -0
  36. package/dist/splatSogDecoder.d.ts +26 -0
  37. package/dist/splatSogDecoder.js +29 -0
  38. package/dist/splatSort.d.ts +137 -0
  39. package/dist/splatSort.js +199 -0
  40. package/dist/splatSortWorker.d.ts +14 -0
  41. package/dist/splatSortWorker.js +137 -0
  42. package/dist/splatSorter.d.ts +112 -0
  43. package/dist/splatSorter.js +231 -0
  44. package/dist/splatView.d.ts +52 -0
  45. package/dist/splatView.js +115 -0
  46. package/package.json +56 -0
  47. package/src/fixtures/README.md +36 -0
  48. package/src/fixtures/cloud.sog +0 -0
  49. package/src/fixtures/cloud.texels.json +27 -0
  50. package/src/fixtures/cloud.truth.json +582 -0
  51. package/src/half.ts +92 -0
  52. package/src/index.ts +55 -0
  53. package/src/shaders/generated/splat.wgsl.ts +98 -0
  54. package/src/shaders/splat.ts +344 -0
  55. package/src/splat.ts +75 -0
  56. package/src/splatBudget.ts +48 -0
  57. package/src/splatCapture.ts +154 -0
  58. package/src/splatCull.ts +91 -0
  59. package/src/splatData.ts +398 -0
  60. package/src/splatGl.ts +262 -0
  61. package/src/splatGpu.ts +259 -0
  62. package/src/splatLayout.ts +86 -0
  63. package/src/splatMatrix.ts +81 -0
  64. package/src/splatPass.ts +324 -0
  65. package/src/splatPly.ts +283 -0
  66. package/src/splatSog.ts +375 -0
  67. package/src/splatSogDecoder.ts +33 -0
  68. package/src/splatSort.ts +296 -0
  69. package/src/splatSortWorker.ts +155 -0
  70. package/src/splatSorter.ts +285 -0
  71. package/src/splatView.ts +147 -0
@@ -0,0 +1,95 @@
1
+ /*
2
+ * Generated from ../splat.ts by `npm run wgsl`. Do not edit.
3
+ *
4
+ * The GLSL beside this file is the source of truth. A hand edit here is discarded by
5
+ * the next generation, and `npm run wgsl:check` fails the build when this is stale.
6
+ */
7
+ export const SPLAT_FRAG_WGSL = "struct Uniforms {\n uOutputTransform: i32,\n uOutputExposure: f32,\n}\n\n@group(0) @binding(1) \nvar<uniform> unnamed: Uniforms;\nvar<private> vCorner_1: vec2<f32>;\nvar<private> vColor_1: vec4<f32>;\nvar<private> fragColor: vec4<f32>;\n\nfn linearToSrgb_u0028_vf3_u003b(c: ptr<function, vec3<f32>>) -> vec3<f32> {\n var low: vec3<f32>;\n var high: vec3<f32>;\n\n let _e54 = (*c);\n low = (_e54 * 12.92f);\n let _e56 = (*c);\n high = ((pow(max(_e56, vec3<f32>(0f, 0f, 0f)), vec3<f32>(0.41666666f, 0.41666666f, 0.41666666f)) * 1.055f) - vec3(0.055f));\n let _e62 = high;\n let _e63 = low;\n let _e64 = (*c);\n return mix(_e62, _e63, step(_e64, vec3<f32>(0.0031308f, 0.0031308f, 0.0031308f)));\n}\n\nfn rrtAndOdtFit_u0028_vf3_u003b(v: ptr<function, vec3<f32>>) -> vec3<f32> {\n var a: vec3<f32>;\n var b: vec3<f32>;\n\n let _e54 = (*v);\n let _e55 = (*v);\n a = ((_e54 * (_e55 + vec3(0.0245786f))) - vec3(0.000090537f));\n let _e61 = (*v);\n let _e62 = (*v);\n b = ((_e61 * ((_e62 * 0.983729f) + vec3(0.432951f))) + vec3(0.238081f));\n let _e69 = a;\n let _e70 = b;\n return (_e69 / _e70);\n}\n\nfn acesFilmic_u0028_vf3_u003b(x: ptr<function, vec3<f32>>) -> vec3<f32> {\n var param: vec3<f32>;\n\n let _e54 = unnamed.uOutputExposure;\n let _e55 = (*x);\n (*x) = (_e55 * _e54);\n let _e57 = (*x);\n param = (mat3x3<f32>(vec3<f32>(0.59719f, 0.076f, 0.0284f), vec3<f32>(0.35458f, 0.90834f, 0.13383f), vec3<f32>(0.04823f, 0.01566f, 0.83777f)) * _e57);\n let _e59 = rrtAndOdtFit_u0028_vf3_u003b((&param));\n return clamp((mat3x3<f32>(vec3<f32>(1.60475f, -0.10208f, -0.00327f), vec3<f32>(-0.53108f, 1.10813f, -0.07276f), vec3<f32>(-0.07367f, -0.00605f, 1.07602f)) * _e59), vec3(0f), vec3(1f));\n}\n\nfn applyOutputTransform_u0028_vf3_u003b(c_1: ptr<function, vec3<f32>>) -> vec3<f32> {\n var param_1: vec3<f32>;\n var param_2: vec3<f32>;\n\n let _e55 = unnamed.uOutputTransform;\n if (_e55 == 0i) {\n let _e57 = (*c_1);\n return _e57;\n }\n let _e59 = unnamed.uOutputTransform;\n if (_e59 == 2i) {\n let _e61 = (*c_1);\n param_1 = _e61;\n let _e62 = acesFilmic_u0028_vf3_u003b((&param_1));\n (*c_1) = _e62;\n }\n let _e63 = (*c_1);\n param_2 = _e63;\n let _e64 = linearToSrgb_u0028_vf3_u003b((&param_2));\n return _e64;\n}\n\nfn main_1() {\n var power: f32;\n var alpha: f32;\n var colour: vec3<f32>;\n var param_3: vec3<f32>;\n\n let _e55 = vCorner_1;\n let _e56 = vCorner_1;\n power = dot(_e55, _e56);\n let _e59 = vColor_1[3u];\n let _e60 = power;\n alpha = (_e59 * exp((-0.5f * _e60)));\n let _e64 = alpha;\n if (_e64 < 0.003921569f) {\n discard;\n }\n let _e66 = vColor_1;\n param_3 = _e66.xyz;\n let _e68 = applyOutputTransform_u0028_vf3_u003b((&param_3));\n colour = _e68;\n let _e69 = colour;\n let _e70 = alpha;\n let _e71 = (_e69 * _e70);\n let _e72 = alpha;\n fragColor = vec4<f32>(_e71.x, _e71.y, _e71.z, _e72);\n return;\n}\n\n@fragment \nfn main(@location(0) vCorner: vec2<f32>, @location(1) vColor: vec4<f32>) -> @location(0) vec4<f32> {\n vCorner_1 = vCorner;\n vColor_1 = vColor;\n main_1();\n let _e5 = fragColor;\n return _e5;\n}\n";
8
+ export const SPLAT_VERT_WGSL = "struct Uniforms {\n uSplatCount: i32,\n uSplatStride: i32,\n uSplatTexels: i32,\n uView: mat4x4<f32>,\n uProjection: mat4x4<f32>,\n uViewport: vec2<f32>,\n uModel: mat4x4<f32>,\n uSplatCameraLocal: vec3<f32>,\n uSplatShDegree: i32,\n}\n\nstruct gl_PerVertex {\n @builtin(position) gl_Position: vec4<f32>,\n gl_PointSize: f32,\n}\n\nstruct VertexOutput {\n @builtin(position) gl_Position: vec4<f32>,\n @location(0) member: vec2<f32>,\n @location(1) member_1: vec4<f32>,\n}\n\n@group(0) @binding(0) \nvar<uniform> unnamed: Uniforms;\n@group(0) @binding(16) \nvar uSplatData_t: texture_2d<u32>;\nvar<private> gl_VertexIndex_1: i32;\nvar<private> unnamed_1: gl_PerVertex = gl_PerVertex(vec4<f32>(0f, 0f, 0f, 1f), 1f);\nvar<private> vCorner: vec2<f32>;\nvar<private> vColor: vec4<f32>;\n@group(0) @binding(18) \nvar uSplatOrder_t: texture_2d<u32>;\n@group(0) @binding(17) \nvar uSplatData_s: sampler;\n@group(0) @binding(19) \nvar uSplatOrder_s: sampler;\n\nfn unpackRgba8_u0028_u1_u003b(packed: ptr<function, u32>) -> vec4<f32> {\n let _e50 = (*packed);\n let _e53 = (*packed);\n let _e58 = (*packed);\n let _e63 = (*packed);\n return (vec4<f32>(f32((_e50 & 255u)), f32(((_e53 >> bitcast<u32>(8i)) & 255u)), f32(((_e58 >> bitcast<u32>(16i)) & 255u)), f32(((_e63 >> bitcast<u32>(24i)) & 255u))) / vec4(255f));\n}\n\nfn viewDependentColour_u0028_vu4_u003b_vf3_u003b(sh: ptr<function, vec4<u32>>, direction: ptr<function, vec3<f32>>) -> vec3<f32> {\n var scale: f32;\n var a: vec4<f32>;\n var param: u32;\n var b: vec4<f32>;\n var param_1: u32;\n var c: vec4<f32>;\n var param_2: u32;\n var c0_: vec3<f32>;\n var c1_: vec3<f32>;\n var c2_: vec3<f32>;\n\n let _e62 = (*sh)[3u];\n scale = bitcast<f32>(_e62);\n let _e64 = scale;\n if (_e64 == 0f) {\n return vec3<f32>(0f, 0f, 0f);\n }\n let _e67 = (*sh)[0u];\n param = _e67;\n let _e68 = unpackRgba8_u0028_u1_u003b((&param));\n a = _e68;\n let _e70 = (*sh)[1u];\n param_1 = _e70;\n let _e71 = unpackRgba8_u0028_u1_u003b((&param_1));\n b = _e71;\n let _e73 = (*sh)[2u];\n param_2 = _e73;\n let _e74 = unpackRgba8_u0028_u1_u003b((&param_2));\n c = _e74;\n let _e76 = a[0u];\n let _e78 = a[1u];\n let _e80 = a[2u];\n let _e87 = scale;\n c0_ = ((((vec3<f32>(_e76, _e78, _e80) * 255f) - vec3(128f)) / vec3(127f)) * _e87);\n let _e90 = a[3u];\n let _e92 = b[0u];\n let _e94 = b[1u];\n let _e101 = scale;\n c1_ = ((((vec3<f32>(_e90, _e92, _e94) * 255f) - vec3(128f)) / vec3(127f)) * _e101);\n let _e104 = b[2u];\n let _e106 = b[3u];\n let _e108 = c[0u];\n let _e115 = scale;\n c2_ = ((((vec3<f32>(_e104, _e106, _e108) * 255f) - vec3(128f)) / vec3(127f)) * _e115);\n let _e118 = (*direction)[1u];\n let _e120 = c0_;\n let _e123 = (*direction)[2u];\n let _e124 = c1_;\n let _e128 = (*direction)[0u];\n let _e129 = c2_;\n return ((((_e120 * -(_e118)) + (_e124 * _e123)) - (_e129 * _e128)) * 0.48860252f);\n}\n\nfn fetchTexel_u0028_i1_u003b_i1_u003b(splat: ptr<function, i32>, which: ptr<function, i32>) -> vec4<u32> {\n var at: i32;\n var width: i32;\n\n let _e53 = (*splat);\n let _e55 = unnamed.uSplatTexels;\n let _e57 = (*which);\n at = ((_e53 * _e55) + _e57);\n let _e60 = unnamed.uSplatStride;\n let _e62 = unnamed.uSplatTexels;\n width = (_e60 * _e62);\n let _e64 = at;\n let _e65 = width;\n let _e73 = at;\n let _e74 = width;\n let _e77 = textureLoad(uSplatData_t, vec2<i32>((_e64 - (i32(floor((f32(_e64) / f32(_e65)))) * _e65)), (_e73 / _e74)), 0i);\n return _e77;\n}\n\nfn main_1() {\n var vertex: i32;\n var slot: i32;\n var corner: i32;\n var splat_1: i32;\n var texel0_: vec4<u32>;\n var param_3: i32;\n var param_4: i32;\n var texel1_: vec4<u32>;\n var param_5: i32;\n var param_6: i32;\n var centre: vec3<f32>;\n var param_7: u32;\n var direction_1: vec3<f32>;\n var param_8: i32;\n var param_9: i32;\n var param_10: vec4<u32>;\n var param_11: vec3<f32>;\n var c01_: vec2<f32>;\n var c23_: vec2<f32>;\n var c45_: vec2<f32>;\n var sigma: mat3x3<f32>;\n var world: vec4<f32>;\n var view: vec4<f32>;\n var clip: vec4<f32>;\n var focalX: f32;\n var focalY: f32;\n var invZ: f32;\n var invZ2_: f32;\n var jacobian: mat3x2<f32>;\n var rotation: mat3x3<f32>;\n var world3_: mat3x3<f32>;\n var screen: mat2x2<f32>;\n var a_1: f32;\n var b_1: f32;\n var d: f32;\n var mid: f32;\n var discriminant: f32;\n var lambda1_: f32;\n var lambda2_: f32;\n var major: vec2<f32>;\n var minor: vec2<f32>;\n var radius1_: f32;\n var radius2_: f32;\n var offsets: array<vec2<f32>, 6>;\n var unit: vec2<f32>;\n var offsetPx: vec2<f32>;\n var phi_358_: bool;\n var phi_369_: bool;\n\n let _e95 = gl_VertexIndex_1;\n vertex = _e95;\n let _e96 = vertex;\n slot = (_e96 / 6i);\n let _e98 = vertex;\n corner = (_e98 - (i32(floor((f32(_e98) / f32(6i)))) * 6i));\n let _e106 = slot;\n let _e108 = unnamed.uSplatCount;\n if (_e106 >= _e108) {\n unnamed_1.gl_Position = vec4<f32>(2f, 2f, 2f, 1f);\n vCorner = vec2<f32>(0f, 0f);\n vColor = vec4<f32>(0f, 0f, 0f, 0f);\n return;\n }\n let _e111 = slot;\n let _e113 = unnamed.uSplatStride;\n let _e121 = slot;\n let _e123 = unnamed.uSplatStride;\n let _e126 = textureLoad(uSplatOrder_t, vec2<i32>((_e111 - (i32(floor((f32(_e111) / f32(_e113)))) * _e113)), (_e121 / _e123)), 0i);\n splat_1 = bitcast<i32>(_e126.x);\n let _e129 = splat_1;\n param_3 = _e129;\n param_4 = 0i;\n let _e130 = fetchTexel_u0028_i1_u003b_i1_u003b((&param_3), (&param_4));\n texel0_ = _e130;\n let _e131 = splat_1;\n param_5 = _e131;\n param_6 = 1i;\n let _e132 = fetchTexel_u0028_i1_u003b_i1_u003b((&param_5), (&param_6));\n texel1_ = _e132;\n let _e133 = texel0_;\n centre = bitcast<vec3<f32>>(_e133.xyz);\n let _e137 = texel0_[3u];\n param_7 = _e137;\n let _e138 = unpackRgba8_u0028_u1_u003b((&param_7));\n vColor = _e138;\n let _e140 = unnamed.uSplatShDegree;\n if (_e140 > 0i) {\n let _e142 = centre;\n let _e144 = unnamed.uSplatCameraLocal;\n direction_1 = normalize((_e142 - _e144));\n let _e147 = vColor;\n let _e149 = splat_1;\n param_8 = _e149;\n param_9 = 2i;\n let _e150 = fetchTexel_u0028_i1_u003b_i1_u003b((&param_8), (&param_9));\n param_10 = _e150;\n let _e151 = direction_1;\n param_11 = _e151;\n let _e152 = viewDependentColour_u0028_vu4_u003b_vf3_u003b((&param_10), (&param_11));\n let _e154 = max((_e147.xyz + _e152), vec3<f32>(0f, 0f, 0f));\n let _e155 = vColor;\n vColor = vec4<f32>(_e154.x, _e154.y, _e154.z, _e155.w);\n }\n let _e162 = texel1_[0u];\n c01_ = unpack2x16float(_e162);\n let _e165 = texel1_[1u];\n c23_ = unpack2x16float(_e165);\n let _e168 = texel1_[2u];\n c45_ = unpack2x16float(_e168);\n let _e171 = c01_[0u];\n let _e173 = c01_[1u];\n let _e175 = c23_[0u];\n let _e177 = c01_[1u];\n let _e179 = c23_[1u];\n let _e181 = c45_[0u];\n let _e183 = c23_[0u];\n let _e185 = c45_[0u];\n let _e187 = c45_[1u];\n sigma = mat3x3<f32>(vec3<f32>(_e171, _e173, _e175), vec3<f32>(_e177, _e179, _e181), vec3<f32>(_e183, _e185, _e187));\n let _e193 = unnamed.uModel;\n let _e194 = centre;\n world = (_e193 * vec4<f32>(_e194.x, _e194.y, _e194.z, 1f));\n let _e201 = unnamed.uView;\n let _e202 = world;\n view = (_e201 * _e202);\n let _e205 = unnamed.uProjection;\n let _e206 = view;\n clip = (_e205 * _e206);\n let _e209 = view[2u];\n let _e210 = (_e209 > -0.01f);\n phi_358_ = _e210;\n if !(_e210) {\n let _e213 = clip[0u];\n let _e216 = clip[3u];\n phi_358_ = (abs(_e213) > (_e216 * 1.3f));\n }\n let _e220 = phi_358_;\n phi_369_ = _e220;\n if !(_e220) {\n let _e223 = clip[1u];\n let _e226 = clip[3u];\n phi_369_ = (abs(_e223) > (_e226 * 1.3f));\n }\n let _e230 = phi_369_;\n if _e230 {\n unnamed_1.gl_Position = vec4<f32>(2f, 2f, 2f, 1f);\n vCorner = vec2<f32>(0f, 0f);\n return;\n }\n let _e235 = unnamed.uProjection[0][0u];\n let _e238 = unnamed.uViewport[0u];\n focalX = ((_e235 * _e238) * 0.5f);\n let _e244 = unnamed.uProjection[1][1u];\n let _e247 = unnamed.uViewport[1u];\n focalY = ((_e244 * _e247) * 0.5f);\n let _e251 = view[2u];\n invZ = (1f / _e251);\n let _e253 = invZ;\n let _e254 = invZ;\n invZ2_ = (_e253 * _e254);\n let _e256 = focalX;\n let _e257 = invZ;\n let _e259 = focalY;\n let _e260 = invZ;\n let _e262 = focalX;\n let _e265 = view[0u];\n let _e267 = invZ2_;\n let _e269 = focalY;\n let _e272 = view[1u];\n let _e274 = invZ2_;\n jacobian = mat3x2<f32>(vec2<f32>((_e256 * _e257), 0f), vec2<f32>(0f, (_e259 * _e260)), vec2<f32>(((-(_e262) * _e265) * _e267), ((-(_e269) * _e272) * _e274)));\n let _e281 = unnamed.uView;\n let _e283 = unnamed.uModel;\n let _e284 = (_e281 * _e283);\n rotation = mat3x3<f32>(_e284[0].xyz, _e284[1].xyz, _e284[2].xyz);\n let _e292 = rotation;\n let _e293 = sigma;\n let _e295 = rotation;\n world3_ = ((_e292 * _e293) * transpose(_e295));\n let _e298 = jacobian;\n let _e299 = world3_;\n let _e301 = jacobian;\n screen = ((_e298 * _e299) * transpose(_e301));\n let _e306 = screen[0][0u];\n screen[0][0u] = (_e306 + 0.3f);\n let _e312 = screen[1][1u];\n screen[1][1u] = (_e312 + 0.3f);\n let _e318 = screen[0][0u];\n a_1 = _e318;\n let _e321 = screen[0][1u];\n b_1 = _e321;\n let _e324 = screen[1][1u];\n d = _e324;\n let _e325 = a_1;\n let _e326 = d;\n mid = (0.5f * (_e325 + _e326));\n let _e329 = mid;\n let _e330 = mid;\n let _e332 = a_1;\n let _e333 = d;\n let _e335 = b_1;\n let _e336 = b_1;\n discriminant = sqrt(max(0.1f, ((_e329 * _e330) - ((_e332 * _e333) - (_e335 * _e336)))));\n let _e342 = mid;\n let _e343 = discriminant;\n lambda1_ = (_e342 + _e343);\n let _e345 = mid;\n let _e346 = discriminant;\n lambda2_ = (_e345 - _e346);\n let _e348 = lambda2_;\n if (_e348 <= 0f) {\n unnamed_1.gl_Position = vec4<f32>(2f, 2f, 2f, 1f);\n vCorner = vec2<f32>(0f, 0f);\n return;\n }\n let _e351 = b_1;\n let _e352 = lambda1_;\n let _e353 = a_1;\n major = normalize(vec2<f32>(_e351, (_e352 - _e353)));\n let _e358 = major[1u];\n let _e361 = major[0u];\n minor = vec2<f32>(-(_e358), _e361);\n let _e363 = lambda1_;\n radius1_ = min((2f * sqrt(_e363)), 512f);\n let _e367 = lambda2_;\n radius2_ = min((2f * sqrt(_e367)), 512f);\n offsets = array<vec2<f32>, 6>(vec2<f32>(-1f, -1f), vec2<f32>(1f, -1f), vec2<f32>(-1f, 1f), vec2<f32>(-1f, 1f), vec2<f32>(1f, -1f), vec2<f32>(1f, 1f));\n let _e371 = corner;\n let _e373 = offsets[_e371];\n unit = _e373;\n let _e374 = unit;\n vCorner = (_e374 * 2f);\n let _e377 = unit[0u];\n let _e378 = major;\n let _e380 = radius1_;\n let _e383 = unit[1u];\n let _e384 = minor;\n let _e386 = radius2_;\n offsetPx = (((_e378 * _e377) * _e380) + ((_e384 * _e383) * _e386));\n let _e389 = clip;\n let _e391 = offsetPx;\n let _e393 = unnamed.uViewport;\n let _e397 = clip[3u];\n let _e399 = (_e389.xy + (((_e391 / _e393) * 2f) * _e397));\n let _e401 = clip[2u];\n let _e403 = clip[3u];\n unnamed_1.gl_Position = vec4<f32>(_e399.x, _e399.y, _e401, _e403);\n return;\n}\n\n@vertex \nfn main(@builtin(vertex_index) gl_VertexIndex: u32) -> VertexOutput {\n gl_VertexIndex_1 = i32(gl_VertexIndex);\n main_1();\n let _e8 = unnamed_1.gl_Position.y;\n unnamed_1.gl_Position.y = -(_e8);\n let _e10 = unnamed_1.gl_Position;\n let _e11 = vCorner;\n let _e12 = vColor;\n return VertexOutput(_e10, _e11, _e12);\n}\n";
9
+ /**
10
+ * What the transform assigned, so the renderer binds the same numbers.
11
+ *
12
+ * A permuted shader has one entry per variant, keyed as `FLAT_FRAG_WGSL` is.
13
+ */
14
+ export const SPLAT_BINDINGS = {
15
+ "SPLAT_FRAG": {
16
+ "uniforms": 1,
17
+ "uniformSize": 16,
18
+ "fields": {
19
+ "uOutputTransform": {
20
+ "offset": 0,
21
+ "size": 4,
22
+ "type": "int"
23
+ },
24
+ "uOutputExposure": {
25
+ "offset": 4,
26
+ "size": 4,
27
+ "type": "float"
28
+ }
29
+ },
30
+ "textures": {}
31
+ },
32
+ "SPLAT_VERT": {
33
+ "uniforms": 0,
34
+ "uniformSize": 240,
35
+ "fields": {
36
+ "uSplatCount": {
37
+ "offset": 0,
38
+ "size": 4,
39
+ "type": "int"
40
+ },
41
+ "uSplatStride": {
42
+ "offset": 4,
43
+ "size": 4,
44
+ "type": "int"
45
+ },
46
+ "uSplatTexels": {
47
+ "offset": 8,
48
+ "size": 4,
49
+ "type": "int"
50
+ },
51
+ "uView": {
52
+ "offset": 16,
53
+ "size": 64,
54
+ "type": "mat4"
55
+ },
56
+ "uProjection": {
57
+ "offset": 80,
58
+ "size": 64,
59
+ "type": "mat4"
60
+ },
61
+ "uViewport": {
62
+ "offset": 144,
63
+ "size": 8,
64
+ "type": "vec2"
65
+ },
66
+ "uModel": {
67
+ "offset": 160,
68
+ "size": 64,
69
+ "type": "mat4"
70
+ },
71
+ "uSplatCameraLocal": {
72
+ "offset": 224,
73
+ "size": 12,
74
+ "type": "vec3"
75
+ },
76
+ "uSplatShDegree": {
77
+ "offset": 236,
78
+ "size": 4,
79
+ "type": "int"
80
+ }
81
+ },
82
+ "textures": {
83
+ "uSplatData": {
84
+ "texture": 16,
85
+ "sampler": 17,
86
+ "type": "usampler2D"
87
+ },
88
+ "uSplatOrder": {
89
+ "texture": 18,
90
+ "sampler": 19,
91
+ "type": "usampler2D"
92
+ }
93
+ }
94
+ }
95
+ };
@@ -0,0 +1,25 @@
1
+ /** The splat program: a screen-space ellipse per Gaussian, sorted far to near and blended over. */
2
+ /**
3
+ * The vertex stage: one ellipse per splat, six vertices, no buffers at all.
4
+ *
5
+ * **Nothing is bound but textures.** The geometry is `gl_VertexID` arithmetic — `id / 6` is the
6
+ * splat and `id % 6` is the corner — so this pass owns no vertex buffer and no vertex array on
7
+ * either backend, and the two compute the same geometry from the same one number. `demo/
8
+ * contributedPass.ts` set that precedent and stated the reason.
9
+ *
10
+ * **What it costs: six vertex invocations a splat rather than the four an indexed quad issues.**
11
+ * At a million splats that is two million extra runs of the arithmetic below. The alternative is a
12
+ * static index buffer at 24 MB per million splats, which is why it is not the starting point.
13
+ */
14
+ export declare const SPLAT_VERT: string;
15
+ /**
16
+ * The fragment stage: the Gaussian's own falloff, premultiplied.
17
+ *
18
+ * **Premultiplied, and that one line is the difference between composing and not.** The pass
19
+ * blends `ONE, ONE_MINUS_SRC_ALPHA` over a scene target that already holds opaque geometry, so
20
+ * the source must arrive with its alpha already folded in. Emitting straight colour there
21
+ * double-counts the alpha and produces a cloud that is too bright at every silhouette — which
22
+ * reads as a exposure problem rather than as a blend-mode one, and is the failure this plan most
23
+ * expects.
24
+ */
25
+ export declare const SPLAT_FRAG = "#version 300 es\nprecision highp float;\nprecision highp int;\n\n/** 0 none, 1 sRGB, 2 ACES then sRGB. See renderQuality.ts. */\nuniform int uOutputTransform;\n/** Scales the scene into the tone curve. 1 is the reference grade. See renderQuality.ts. */\nuniform float uOutputExposure;\n\n/*\n * ACES: the reference fit, not the cheap one.\n *\n * This was Narkowicz's single rational function, on the argument that the difference from\n * the reference curve is invisible next to the gain. That argument holds for a look and\n * fails for a *match*, which is what this option is for \u2014 aces exists so a world ported\n * from three.js reads the same, and three.js applies the full fit: into AP1 through\n * ACESInputMat, the RRT and ODT together, then back out through ACESOutputMat.\n *\n * The two curves are not a shade apart. Narkowicz is markedly brighter through the\n * midtones, which is exactly where an interior scene lives, and it is a large part of a\n * measured ~1.7x that survived correcting the colour space and the missing Lambert pi.\n * An approximation of a standard is the wrong thing to hold when the standard is the\n * specification.\n */\nvec3 rrtAndOdtFit(vec3 v) {\n vec3 a = v * (v + 0.0245786) - 0.000090537;\n vec3 b = v * (0.983729 * v + 0.4329510) + 0.238081;\n return a / b;\n}\n\nvec3 acesFilmic(vec3 x) {\n /*\n * Exposure first, because a tone curve is only defined relative to one.\n *\n * The reference RRT and ODT are graded for a dark cinema. Every renderer that ships ACES\n * scales its input to suit whatever it is actually shown on, and the factor each one\n * picks is a *look*, not a standard - so this engine takes no position and reads it from\n * the caller. Neutral by default, which is the reference grade unmodified. three.js's own\n * pick is 1 / 0.6, for a consumer matching one.\n */\n x *= uOutputExposure;\n // Columns, as GLSL reads them: sRGB -> XYZ -> D65_2_D60 -> AP1 -> RRT_SAT.\n const mat3 ACES_INPUT = mat3(\n 0.59719, 0.07600, 0.02840,\n 0.35458, 0.90834, 0.13383,\n 0.04823, 0.01566, 0.83777\n );\n // ODT_SAT -> XYZ -> D60_2_D65 -> sRGB.\n const mat3 ACES_OUTPUT = mat3(\n 1.60475, -0.10208, -0.00327,\n -0.53108, 1.10813, -0.07276,\n -0.07367, -0.00605, 1.07602\n );\n return clamp(ACES_OUTPUT * rrtAndOdtFit(ACES_INPUT * x), 0.0, 1.0);\n}\n\n/*\n * Linear to sRGB. The piecewise form rather than a plain pow: the linear toe near black\n * is where banding lives in an 8-bit buffer, and the cheap approximation puts it in the\n * wrong place.\n */\nvec3 linearToSrgb(vec3 c) {\n vec3 low = c * 12.92;\n vec3 high = 1.055 * pow(max(c, vec3(0.0)), vec3(1.0 / 2.4)) - 0.055;\n return mix(high, low, step(c, vec3(0.0031308)));\n}\n\nvec3 applyOutputTransform(vec3 c) {\n if (uOutputTransform == 0) return c;\n if (uOutputTransform == 2) c = acesFilmic(c);\n return linearToSrgb(c);\n}\n\n\nin vec2 vCorner;\nin vec4 vColor;\nout vec4 fragColor;\n\nvoid main() {\n /* The Gaussian, in units where the quad's corner is SIGMA_REACH standard deviations out. */\n float power = dot(vCorner, vCorner);\n float alpha = vColor.a * exp(-0.5 * power);\n\n /*\n * Below what an eight-bit frame resolves. Discarding rather than blending nothing saves the\n * read-modify-write on the tail of every splat, which on a fill-bound pass is most of them.\n */\n if (alpha < 0.00392156862745098) discard;\n\n vec3 colour = applyOutputTransform(vColor.rgb);\n fragColor = vec4(colour * alpha, alpha);\n}\n";
@@ -0,0 +1,337 @@
1
+ /** The splat program: a screen-space ellipse per Gaussian, sorted far to near and blended over. */
2
+ import { OUTPUT_TRANSFORM_GLSL } from '@driftengine/core';
3
+ /**
4
+ * How far out the quad reaches, in standard deviations.
5
+ *
6
+ * Two sigma leaves `exp(-4)` — under two percent — at the corner, which is below what an eight-bit
7
+ * frame resolves. Three would be more correct and costs 2.25 times the fill for a contribution
8
+ * nothing can see; a splat cloud is fill-bound, so that is the whole argument.
9
+ */
10
+ const SIGMA_REACH = 2.0;
11
+ /**
12
+ * The largest an ellipse's semi-axis may be, in pixels.
13
+ *
14
+ * **A guard against one splat costing the whole frame**, not a quality dial. A Gaussian seen
15
+ * nearly edge-on projects to an ellipse whose major axis grows without bound as the surface turns
16
+ * into the view, and one such splat covering the screen at a hundred fragments' worth of blending
17
+ * is a frame that drops. What it gives up is that a genuinely enormous splat is clipped rather
18
+ * than drawn; what would make it wrong is a capture authored at a scale where this is common,
19
+ * which is a capture whose splats are the size of the room.
20
+ */
21
+ const MAX_RADIUS_PX = 512.0;
22
+ /**
23
+ * The low-pass added to both diagonal terms of the screen-space covariance.
24
+ *
25
+ * **A splat smaller than a pixel must not vanish, and this is what keeps it.** Below about one
26
+ * pixel the projected Gaussian falls between sample points and flickers as the camera moves —
27
+ * the same aliasing a mip chain solves for a texture, solved here by widening the lobe to the
28
+ * sampling rate. 0.3 is what every published implementation of this technique uses and it is a
29
+ * variance in pixels squared, so it is a little over half a pixel of standard deviation.
30
+ *
31
+ * What it costs: a genuinely sub-pixel splat reads slightly larger and slightly dimmer than it
32
+ * should, because widening without renormalising spreads the same alpha over more fragments.
33
+ * What would make it wrong is a capture rendered far above its authored resolution, where every
34
+ * splat is many pixels and this is a rounding error on all of them.
35
+ */
36
+ const LOW_PASS = 0.3;
37
+ /**
38
+ * Common declarations: the two data textures, the camera, and the viewport.
39
+ *
40
+ * **Both stages read `uSplatData`**, which is why it is declared here rather than in the vertex
41
+ * stage alone — the fragment stage needs the colour, and passing it down as a varying would cost
42
+ * four interpolators against one integer fetch.
43
+ */
44
+ const SHARED = `
45
+ /**
46
+ * Per-splat data, two texels each: position and colour, then the covariance.
47
+ *
48
+ * \`usampler2D\` and \`texelFetch\`, so there is no filtering and no float-texture extension
49
+ * involved — WebGL2 core is enough. Texel 0 is the three position floats reinterpreted as uints
50
+ * plus an RGBA8 colour; texel 1 is the six unique covariance terms as three half pairs.
51
+ */
52
+ uniform highp usampler2D uSplatData;
53
+ /** The sorted order, one texel a splat. A new order re-uploads four bytes each and nothing else. */
54
+ uniform highp usampler2D uSplatOrder;
55
+ /** How many splats are in the order, so a budget can draw a prefix of it. */
56
+ uniform int uSplatCount;
57
+ /** Splats per row in both textures. A power of two, so the divide is a shift. */
58
+ uniform int uSplatStride;
59
+ /**
60
+ * Texels one splat occupies: two, or three where the capture carries view-dependent colour.
61
+ *
62
+ * **A uniform rather than a constant**, because it is the *file's* width — a SPLT block carries
63
+ * its own wordsPerSplat. A shader that assumed two would read a three-texel capture's second
64
+ * splat at the first one's covariance, which is a cloud of noise rather than a subtle error.
65
+ */
66
+ uniform int uSplatTexels;
67
+
68
+ uniform mat4 uView;
69
+ uniform mat4 uProjection;
70
+ /** Pixels, so the ellipse can be built in pixel space and converted once. */
71
+ uniform vec2 uViewport;
72
+ /** The capture's own transform, so two captures compose in one scene. */
73
+ uniform mat4 uModel;
74
+ `;
75
+ /**
76
+ * The vertex stage: one ellipse per splat, six vertices, no buffers at all.
77
+ *
78
+ * **Nothing is bound but textures.** The geometry is `gl_VertexID` arithmetic — `id / 6` is the
79
+ * splat and `id % 6` is the corner — so this pass owns no vertex buffer and no vertex array on
80
+ * either backend, and the two compute the same geometry from the same one number. `demo/
81
+ * contributedPass.ts` set that precedent and stated the reason.
82
+ *
83
+ * **What it costs: six vertex invocations a splat rather than the four an indexed quad issues.**
84
+ * At a million splats that is two million extra runs of the arithmetic below. The alternative is a
85
+ * static index buffer at 24 MB per million splats, which is why it is not the starting point.
86
+ */
87
+ export const SPLAT_VERT = `#version 300 es
88
+ precision highp float;
89
+ precision highp int;
90
+ ${SHARED}
91
+
92
+ out vec2 vCorner;
93
+ out vec4 vColor;
94
+
95
+ /**
96
+ * The l=1 spherical-harmonic band constant, 0.5 * sqrt(3 / pi).
97
+ *
98
+ * The band-0 constant is the *reader's* — splatPly.ts folds it into the colour, because the DC
99
+ * term is a colour once it has been applied. This one belongs here, because the term it scales is
100
+ * a function of the view direction and cannot be folded into anything.
101
+ */
102
+ const float SH_C1 = 0.4886025119029199;
103
+
104
+ /**
105
+ * Where the camera is, in the **capture's own space**.
106
+ *
107
+ * Not world space, and the difference is the whole of what makes this correct: the coefficients
108
+ * were trained in the capture's frame, so a capture placed into a scene by uModel — turned,
109
+ * moved, scaled — must have its view direction expressed in the frame the coefficients know. The
110
+ * inverse of uView * uModel is one CPU matrix a frame; doing it here would be one per vertex.
111
+ */
112
+ uniform vec3 uSplatCameraLocal;
113
+ /** 0 for a capture with no harmonics, 1 for the l=1 band. The whole of the off path. */
114
+ uniform int uSplatShDegree;
115
+
116
+ /*
117
+ * **Returns \`uvec4\`, and going through \`vec4\` was a real bug.** A position is a float's bits
118
+ * reinterpreted as a uint — 0x3F800000 is 1,065,353,216 — and float32 carries 24 bits of mantissa,
119
+ * so a round trip through it quantises the low bits of every coordinate. The picture that produces
120
+ * is a capture whose splats are all *nearly* in the right place, which reads as a bad export.
121
+ */
122
+ uvec4 fetchTexel(int splat, int which) {
123
+ int at = splat * uSplatTexels + which;
124
+ int width = uSplatStride * uSplatTexels;
125
+ return texelFetch(uSplatData, ivec2(at % width, at / width), 0);
126
+ }
127
+
128
+ /*
129
+ * **RGBA8 out of a uint by hand, because \`unpackUnorm4x8\` is GLSL ES 3.10 and this is 3.00.**
130
+ *
131
+ * It compiles through the generator, which raises the version to 310 before handing the source to
132
+ * glslang — so a 3.10 builtin passes generation and fails at runtime on **WebGL2**, the backend
133
+ * with no fallback beneath it. That inverts the safety property the whole
134
+ * authored-in-GLSL-generated-to-WGSL arrangement exists for, and it is invisible until a browser
135
+ * compiles the shader: the WGSL was correct the whole time.
136
+ */
137
+ vec4 unpackRgba8(uint packed) {
138
+ return vec4(
139
+ float(packed & 0xFFu),
140
+ float((packed >> 8) & 0xFFu),
141
+ float((packed >> 16) & 0xFFu),
142
+ float((packed >> 24) & 0xFFu)
143
+ ) / 255.0;
144
+ }
145
+
146
+ /**
147
+ * The view-dependent term of one splat's colour, from the texel packSh1 wrote.
148
+ *
149
+ * **The evaluation the reference implementation of this technique uses, in its own sign
150
+ * convention**: −C1·y·c0 + C1·z·c1 − C1·x·c2, with the direction pointing *from* the camera
151
+ * *to* the splat. Reproducing that sign pattern from first principles is where a reimplementation
152
+ * goes wrong, and the failure is a capture whose sheen sits on the wrong side of every surface —
153
+ * plausible from any one angle and unmistakable as soon as the camera moves.
154
+ *
155
+ * Nine bytes and a scale, which packSh1 explains: a per-splat scale spends the sixteenth byte on
156
+ * giving every splat the whole 8-bit range for its own coefficients.
157
+ */
158
+ vec3 viewDependentColour(uvec4 sh, vec3 direction) {
159
+ float scale = uintBitsToFloat(sh.w);
160
+ if (scale == 0.0) return vec3(0.0);
161
+ vec4 a = unpackRgba8(sh.x);
162
+ vec4 b = unpackRgba8(sh.y);
163
+ vec4 c = unpackRgba8(sh.z);
164
+ /* (byte / 255 * 255 − 128) / 127 undoes the quantisation exactly at the centre. */
165
+ vec3 c0 = (vec3(a.x, a.y, a.z) * 255.0 - 128.0) / 127.0 * scale;
166
+ vec3 c1 = (vec3(a.w, b.x, b.y) * 255.0 - 128.0) / 127.0 * scale;
167
+ vec3 c2 = (vec3(b.z, b.w, c.x) * 255.0 - 128.0) / 127.0 * scale;
168
+ return SH_C1 * (-direction.y * c0 + direction.z * c1 - direction.x * c2);
169
+ }
170
+
171
+ void main() {
172
+ int vertex = gl_VertexID;
173
+ int slot = vertex / 6;
174
+ int corner = vertex % 6;
175
+
176
+ /*
177
+ * Off the end of the order: emit a degenerate triangle rather than clamping to the last splat,
178
+ * which would draw it several times over and read as a bright speck that moves with the budget.
179
+ */
180
+ if (slot >= uSplatCount) {
181
+ gl_Position = vec4(2.0, 2.0, 2.0, 1.0);
182
+ vCorner = vec2(0.0);
183
+ vColor = vec4(0.0);
184
+ return;
185
+ }
186
+
187
+ int splat = int(texelFetch(uSplatOrder, ivec2(slot % uSplatStride, slot / uSplatStride), 0).r);
188
+
189
+ uvec4 texel0 = fetchTexel(splat, 0);
190
+ uvec4 texel1 = fetchTexel(splat, 1);
191
+
192
+ vec3 centre = uintBitsToFloat(texel0.xyz);
193
+ vColor = unpackRgba8(texel0.w);
194
+
195
+ /*
196
+ * View-dependent colour, added to the DC term the reader already folded into the RGBA8.
197
+ *
198
+ * A uniform gate, so a capture without the band performs no fetch at all — this is provably
199
+ * uniform control flow and not the 2026-08-07 case. Clamped at zero from below because a
200
+ * negative radiance is not a colour and the reference implementation clamps in the same place;
201
+ * **not clamped above**, because the composite downstream is where a range is resolved and
202
+ * clipping here would throw away exactly the highlight this band exists to produce.
203
+ */
204
+ if (uSplatShDegree > 0) {
205
+ vec3 direction = normalize(centre - uSplatCameraLocal);
206
+ vColor.rgb = max(vColor.rgb + viewDependentColour(fetchTexel(splat, 2), direction), vec3(0.0));
207
+ }
208
+
209
+ vec2 c01 = unpackHalf2x16(texel1.x);
210
+ vec2 c23 = unpackHalf2x16(texel1.y);
211
+ vec2 c45 = unpackHalf2x16(texel1.z);
212
+ /* xx xy xz yy yz zz, the order packSplats writes. */
213
+ mat3 sigma = mat3(
214
+ c01.x, c01.y, c23.x,
215
+ c01.y, c23.y, c45.x,
216
+ c23.x, c45.x, c45.y
217
+ );
218
+
219
+ vec4 world = uModel * vec4(centre, 1.0);
220
+ vec4 view = uView * world;
221
+
222
+ /*
223
+ * Behind the near plane, or far outside the frustum: degenerate. A guard band rather than the
224
+ * exact frustum, because a splat whose centre is just outside still has an ellipse reaching in.
225
+ */
226
+ vec4 clip = uProjection * view;
227
+ if (view.z > -0.01 || abs(clip.x) > clip.w * 1.3 || abs(clip.y) > clip.w * 1.3) {
228
+ gl_Position = vec4(2.0, 2.0, 2.0, 1.0);
229
+ vCorner = vec2(0.0);
230
+ return;
231
+ }
232
+
233
+ /*
234
+ * The 2x3 Jacobian of the perspective projection at this point, in pixels.
235
+ *
236
+ * A perspective divide is not linear, so a 3D Gaussian does not project to a 2D one — it
237
+ * projects to something with no closed form. The standard treatment is to linearise about the
238
+ * splat's centre, which is exact at the centre and increasingly wrong toward the edges of the
239
+ * frame. **What would make it wrong** is a very wide field of view, where a splat at the corner
240
+ * is measurably sheared; at ordinary angles the error is far below a pixel.
241
+ */
242
+ float focalX = uProjection[0][0] * uViewport.x * 0.5;
243
+ float focalY = uProjection[1][1] * uViewport.y * 0.5;
244
+ float invZ = 1.0 / view.z;
245
+ float invZ2 = invZ * invZ;
246
+ mat3x2 jacobian = mat3x2(
247
+ focalX * invZ, 0.0,
248
+ 0.0, focalY * invZ,
249
+ -focalX * view.x * invZ2, -focalY * view.y * invZ2
250
+ );
251
+
252
+ /* Sigma' = J W Sigma W^T J^T, with W the view rotation and the model's. */
253
+ mat3 rotation = mat3(uView * uModel);
254
+ mat3 world3 = rotation * sigma * transpose(rotation);
255
+ mat2 screen = jacobian * world3 * transpose(jacobian);
256
+
257
+ /* The low-pass, on the variances only. See LOW_PASS. */
258
+ screen[0][0] += ${LOW_PASS.toFixed(1)};
259
+ screen[1][1] += ${LOW_PASS.toFixed(1)};
260
+
261
+ /*
262
+ * Eigen-decompose the symmetric 2x2 in closed form: the axes of the ellipse are its
263
+ * eigenvectors and the semi-axes are the square roots of its eigenvalues.
264
+ */
265
+ float a = screen[0][0];
266
+ float b = screen[0][1];
267
+ float d = screen[1][1];
268
+ float mid = 0.5 * (a + d);
269
+ float discriminant = sqrt(max(0.1, mid * mid - (a * d - b * b)));
270
+ float lambda1 = mid + discriminant;
271
+ float lambda2 = mid - discriminant;
272
+
273
+ /* A non-positive minor eigenvalue is a degenerate ellipse: nothing to draw. */
274
+ if (lambda2 <= 0.0) {
275
+ gl_Position = vec4(2.0, 2.0, 2.0, 1.0);
276
+ vCorner = vec2(0.0);
277
+ return;
278
+ }
279
+
280
+ vec2 major = normalize(vec2(b, lambda1 - a));
281
+ /* Perpendicular by construction rather than by a second normalize, which would be the same
282
+ vector computed twice and could disagree by an ulp at a degenerate b. */
283
+ vec2 minor = vec2(-major.y, major.x);
284
+ float radius1 = min(${SIGMA_REACH.toFixed(1)} * sqrt(lambda1), ${MAX_RADIUS_PX.toFixed(1)});
285
+ float radius2 = min(${SIGMA_REACH.toFixed(1)} * sqrt(lambda2), ${MAX_RADIUS_PX.toFixed(1)});
286
+
287
+ /* Two triangles over the unit square, in the corner order the fragment stage expects. */
288
+ vec2 offsets[6] = vec2[6](
289
+ vec2(-1.0, -1.0), vec2(1.0, -1.0), vec2(-1.0, 1.0),
290
+ vec2(-1.0, 1.0), vec2(1.0, -1.0), vec2(1.0, 1.0)
291
+ );
292
+ vec2 unit = offsets[corner];
293
+ vCorner = unit * ${SIGMA_REACH.toFixed(1)};
294
+
295
+ vec2 offsetPx = unit.x * major * radius1 + unit.y * minor * radius2;
296
+ /* Pixels to clip space: the ellipse was built in pixels, so this is the only conversion. */
297
+ gl_Position = vec4(
298
+ clip.xy + offsetPx / uViewport * 2.0 * clip.w,
299
+ clip.z,
300
+ clip.w
301
+ );
302
+ }
303
+ `;
304
+ /**
305
+ * The fragment stage: the Gaussian's own falloff, premultiplied.
306
+ *
307
+ * **Premultiplied, and that one line is the difference between composing and not.** The pass
308
+ * blends `ONE, ONE_MINUS_SRC_ALPHA` over a scene target that already holds opaque geometry, so
309
+ * the source must arrive with its alpha already folded in. Emitting straight colour there
310
+ * double-counts the alpha and produces a cloud that is too bright at every silhouette — which
311
+ * reads as a exposure problem rather than as a blend-mode one, and is the failure this plan most
312
+ * expects.
313
+ */
314
+ export const SPLAT_FRAG = `#version 300 es
315
+ precision highp float;
316
+ precision highp int;
317
+ ${OUTPUT_TRANSFORM_GLSL}
318
+
319
+ in vec2 vCorner;
320
+ in vec4 vColor;
321
+ out vec4 fragColor;
322
+
323
+ void main() {
324
+ /* The Gaussian, in units where the quad's corner is SIGMA_REACH standard deviations out. */
325
+ float power = dot(vCorner, vCorner);
326
+ float alpha = vColor.a * exp(-0.5 * power);
327
+
328
+ /*
329
+ * Below what an eight-bit frame resolves. Discarding rather than blending nothing saves the
330
+ * read-modify-write on the tail of every splat, which on a fill-bound pass is most of them.
331
+ */
332
+ if (alpha < 0.00392156862745098) discard;
333
+
334
+ vec3 colour = applyOutputTransform(vColor.rgb);
335
+ fragColor = vec4(colour * alpha, alpha);
336
+ }
337
+ `;
@@ -0,0 +1,26 @@
1
+ /** The `.splat` reader: thirty-two bytes a splat, and nothing else in the file. */
2
+ import type { SplatData } from './splatData.ts';
3
+ /**
4
+ * Position, scale, colour and rotation, in that order, little-endian.
5
+ *
6
+ * There is no header and no version. The format is a bare array of records, which is what makes
7
+ * the length check below the only structural validation available.
8
+ */
9
+ export declare const SPLAT_RECORD_BYTES = 32;
10
+ /**
11
+ * Read a `.splat` capture.
12
+ *
13
+ * **The one thing worth knowing is the quaternion's encoding.** Rotation arrives as four bytes and
14
+ * comes back as `(b - 128) / 128`, so a byte of 128 is zero and the representable range is roughly
15
+ * −1 to +0.9922. `packSplats` normalises what it is handed, which is what makes that asymmetry
16
+ * harmless: the quantised quaternion is a hair off unit length and the normalisation absorbs it.
17
+ *
18
+ * **The file stores wxyz and `SplatSource` takes xyzw**, so the reorder happens here, in the one
19
+ * place the file's own order is on screen. Getting it wrong does not produce a refusal — it
20
+ * produces a capture whose every splat is rotated to somewhere else, which reads as a smear.
21
+ *
22
+ * **Colour is already eight-bit and already linear**, so it divides by 255 and nothing else: there
23
+ * is no logistic and no exponential here, unlike the `.ply` reader. That asymmetry is the format's
24
+ * rather than a choice, and `packSplats` takes linear values from both.
25
+ */
26
+ export declare function readSplat(buffer: ArrayBuffer): SplatData;
package/dist/splat.js ADDED
@@ -0,0 +1,63 @@
1
+ /** The `.splat` reader: thirty-two bytes a splat, and nothing else in the file. */
2
+ import { packSplats } from './splatData.js';
3
+ /**
4
+ * Position, scale, colour and rotation, in that order, little-endian.
5
+ *
6
+ * There is no header and no version. The format is a bare array of records, which is what makes
7
+ * the length check below the only structural validation available.
8
+ */
9
+ export const SPLAT_RECORD_BYTES = 32;
10
+ /**
11
+ * Read a `.splat` capture.
12
+ *
13
+ * **The one thing worth knowing is the quaternion's encoding.** Rotation arrives as four bytes and
14
+ * comes back as `(b - 128) / 128`, so a byte of 128 is zero and the representable range is roughly
15
+ * −1 to +0.9922. `packSplats` normalises what it is handed, which is what makes that asymmetry
16
+ * harmless: the quantised quaternion is a hair off unit length and the normalisation absorbs it.
17
+ *
18
+ * **The file stores wxyz and `SplatSource` takes xyzw**, so the reorder happens here, in the one
19
+ * place the file's own order is on screen. Getting it wrong does not produce a refusal — it
20
+ * produces a capture whose every splat is rotated to somewhere else, which reads as a smear.
21
+ *
22
+ * **Colour is already eight-bit and already linear**, so it divides by 255 and nothing else: there
23
+ * is no logistic and no exponential here, unlike the `.ply` reader. That asymmetry is the format's
24
+ * rather than a choice, and `packSplats` takes linear values from both.
25
+ */
26
+ export function readSplat(buffer) {
27
+ const remainder = buffer.byteLength % SPLAT_RECORD_BYTES;
28
+ if (remainder !== 0) {
29
+ throw new Error(`a .splat file is a whole number of ${SPLAT_RECORD_BYTES}-byte records; this one is ` +
30
+ `${buffer.byteLength} bytes, which leaves ${remainder} over. Either it is truncated or it ` +
31
+ 'is not a .splat.');
32
+ }
33
+ const count = buffer.byteLength / SPLAT_RECORD_BYTES;
34
+ const view = new DataView(buffer);
35
+ const bytes = new Uint8Array(buffer);
36
+ const positions = new Float32Array(count * 3);
37
+ const scales = new Float32Array(count * 3);
38
+ const rotations = new Float32Array(count * 4);
39
+ const colors = new Float32Array(count * 3);
40
+ const opacities = new Float32Array(count);
41
+ for (let index = 0; index < count; index++) {
42
+ const at = index * SPLAT_RECORD_BYTES;
43
+ const p = index * 3;
44
+ positions[p] = view.getFloat32(at, true);
45
+ positions[p + 1] = view.getFloat32(at + 4, true);
46
+ positions[p + 2] = view.getFloat32(at + 8, true);
47
+ /* Linear already: this format stores the standard deviation, not its logarithm. */
48
+ scales[p] = view.getFloat32(at + 12, true);
49
+ scales[p + 1] = view.getFloat32(at + 16, true);
50
+ scales[p + 2] = view.getFloat32(at + 20, true);
51
+ colors[p] = (bytes[at + 24] ?? 0) / 255;
52
+ colors[p + 1] = (bytes[at + 25] ?? 0) / 255;
53
+ colors[p + 2] = (bytes[at + 26] ?? 0) / 255;
54
+ opacities[index] = (bytes[at + 27] ?? 0) / 255;
55
+ /* wxyz in the file, xyzw in `SplatSource`. See the header. */
56
+ const r = index * 4;
57
+ rotations[r] = ((bytes[at + 29] ?? 128) - 128) / 128;
58
+ rotations[r + 1] = ((bytes[at + 30] ?? 128) - 128) / 128;
59
+ rotations[r + 2] = ((bytes[at + 31] ?? 128) - 128) / 128;
60
+ rotations[r + 3] = ((bytes[at + 28] ?? 128) - 128) / 128;
61
+ }
62
+ return packSplats({ count, positions, scales, rotations, colors, opacities });
63
+ }
@@ -0,0 +1,40 @@
1
+ /** How many splats a device should be asked to draw, before anybody has measured that device. */
2
+ /**
3
+ * The count a part this engine has no evidence against is asked to draw.
4
+ *
5
+ * **This is an estimate and it is not measured, which is the first thing to know about it.**
6
+ * `AGENTS.md` says fidelity is cut on a measurement and not on a fear, and the measurement that
7
+ * settles this one is a frame time from a real mid-range Android phone drawing a real capture —
8
+ * which this repository does not have. What is here instead is the arithmetic: a splat pass is
9
+ * fill-bound, a splat at ±2σ covers a few dozen blended fragments, and a mid-range mobile part has
10
+ * something under half a gigapixel a frame of blended fill at 60 Hz. Four hundred thousand splats
11
+ * is what that budget divides into, and it is the range published mobile viewers of this technique
12
+ * report.
13
+ *
14
+ * **What it costs if it is too low** is a capture thinner than the device could have drawn, which
15
+ * is visible as a sparser cloud and nothing worse. **What would make it wrong** is a measurement,
16
+ * in either direction, and a consumer holding one should pass its own number rather than wait for
17
+ * this line to be corrected. `docs/IMPROVEMENTS.md` carries it as an open measurement.
18
+ */
19
+ export declare const SPLAT_BUDGET_DEFAULT = 400000;
20
+ /**
21
+ * The count a part measured to struggle with the good profile is asked to draw.
22
+ *
23
+ * The same estimate against the family `isWeakGpuFamily` names — an Adreno 619 measured at 156 ms
24
+ * a frame on this engine's desktop profile, an Adreno 710 at 112 ms, a UHD 630 unplayable
25
+ * fullscreen. Those are three to ten times the frame time the default is reasoned against, so this
26
+ * is the default cut by that factor rather than a second guess.
27
+ */
28
+ export declare const SPLAT_BUDGET_WEAK = 120000;
29
+ /**
30
+ * The budget to hand `SplatSorter` when the consumer has no number of its own.
31
+ *
32
+ * Takes the renderer's own name — `renderer.rendererName`, which every backend answers — rather
33
+ * than reaching for an adapter itself, because `AGENTS.md`'s rule is that a package takes a
34
+ * platform capability as a parameter and never queries one.
35
+ *
36
+ * **An unknown part is not weak**, which is `isWeakGpuFamily`'s own decision and the reason it is
37
+ * reused rather than re-tabulated here: a device table is wrong about every GPU nobody has tested,
38
+ * and guessing weak on the unknown thins a capture for every part released after this line.
39
+ */
40
+ export declare function defaultSplatBudget(rendererName?: string): number;