PageSourceSearch

https://cosmosjourneyer.com/game/assets/gaussianSplatting.vertex-DukLRLx0.js

js cosmosjourneyer.com collected 2026-10-03 23:23:33 UTC 9,375 bytes, 189 lines download raw bytes

1import{n as e}from"./rolldown-runtime-CNC7AqOf.js";import{n as t,t as n}from"./shaderStore-C5hmi3ce.js";import{n as r}from"./helperFunctions-BXzvP9TY.js";import{t as i}from"./meshUboDeclaration-VdNmMntx.js";import{t as a}from"./sceneUboDeclaration-Clx8kAb-.js";import{t as o}from"./logDepthDeclaration-Cetoi_e5.js";import{n as s}from"./clipPlaneVertexDeclaration-CoBm3dUF.js";import{t as c}from"./fogVertexDeclaration-t5hFkIgU.js";import{n as l}from"./clipPlaneVertex-NBs2bAAg.js";import{t as u}from"./fogVertex-BXLsQ36R.js";import{t as d}from"./logDepthVertex-DCkuktHf.js";var f,p,m=e((()=>{t(),f=`gaussianSplatting`,p=`fn getDataUV(index: f32,dataTextureSize: vec2f)->vec2<f32> {let y: f32=floor(index/dataTextureSize.x);let x: f32=index-y*dataTextureSize.x;return vec2f((x+0.5),(y+0.5));}
2struct Splat {center: vec4f,
3color: vec4f,
4covA: vec4f,
5covB: vec4f,
6#if SH_DEGREE>0
7sh0: vec4<u32>,
8#endif
9#if SH_DEGREE>1
10sh1: vec4<u32>,
11#endif
12#if SH_DEGREE>2
13sh2: vec4<u32>,
14#endif
15};fn getSplatIndex(localIndex: i32,splatIndex0: vec4f,splatIndex1: vec4f,splatIndex2: vec4f,splatIndex3: vec4f)->f32 {var splatIndex: f32;switch (localIndex)
16{case 0:
17{splatIndex=splatIndex0.x;break;}
18case 1:
19{splatIndex=splatIndex0.y;break;}
20case 2:
21{splatIndex=splatIndex0.z;break;}
22case 3:
23{splatIndex=splatIndex0.w;break;}
24case 4:
25{splatIndex=splatIndex1.x;break;}
26case 5:
27{splatIndex=splatIndex1.y;break;}
28case 6:
29{splatIndex=splatIndex1.z;break;}
30case 7:
31{splatIndex=splatIndex1.w;break;}
32case 8:
33{splatIndex=splatIndex2.x;break;}
34case 9:
35{splatIndex=splatIndex2.y;break;}
36case 10:
37{splatIndex=splatIndex2.z;break;}
38case 11:
39{splatIndex=splatIndex2.w;break;}
40case 12:
41{splatIndex=splatIndex3.x;break;}
42case 13:
43{splatIndex=splatIndex3.y;break;}
44case 14:
45{splatIndex=splatIndex3.z;break;}
46default:
47{splatIndex=splatIndex3.w;break;}}
48return splatIndex;}
49fn readSplat(splatIndex: f32,dataTextureSize: vec2f)->Splat {var splat: Splat;let splatUV=getDataUV(splatIndex,dataTextureSize);let splatUVi32=vec2<i32>(i32(splatUV.x),i32(splatUV.y));splat.center=textureLoad(centersTexture,splatUVi32,0);splat.color=textureLoad(colorsTexture,splatUVi32,0);splat.covA=textureLoad(covariancesATexture,splatUVi32,0)*splat.center.w;splat.covB=textureLoad(covariancesBTexture,splatUVi32,0)*splat.center.w;
50#if SH_DEGREE>0
51splat.sh0=textureLoad(shTexture0,splatUVi32,0);
52#endif
53#if SH_DEGREE>1
54splat.sh1=textureLoad(shTexture1,splatUVi32,0);
55#endif
56#if SH_DEGREE>2
57splat.sh2=textureLoad(shTexture2,splatUVi32,0);
58#endif
59return splat;}
60fn computeColorFromSHDegree(dir: vec3f,sh: array<vec3<f32>,16>)->vec3f
61{let SH_C0: f32=0.28209479;let SH_C1: f32=0.48860251;var SH_C2: array<f32,5>=array<f32,5>(
621.092548430,
63-1.09254843,
640.315391565,
65-1.09254843,
660.546274215
67);var SH_C3: array<f32,7>=array<f32,7>(
68-0.59004358,
692.890611442,
70-0.45704579,
710.373176332,
72-0.45704579,
731.445305721,
74-0.59004358
75);var result: vec3f=/*SH_C0**/sh[0];
76#if SH_DEGREE>0
77let x: f32=dir.x;let y: f32=dir.y;let z: f32=dir.z;result+=-SH_C1*y*sh[1]+SH_C1*z*sh[2]-SH_C1*x*sh[3];
78#if SH_DEGREE>1
79let xx: f32=x*x;let yy: f32=y*y;let zz: f32=z*z;let xy: f32=x*y;let yz: f32=y*z;let xz: f32=x*z;result+=
80SH_C2[0]*xy*sh[4] +
81SH_C2[1]*yz*sh[5] +
82SH_C2[2]*(2.0f*zz-xx-yy)*sh[6] +
83SH_C2[3]*xz*sh[7] +
84SH_C2[4]*(xx-yy)*sh[8];
85#if SH_DEGREE>2
86result+=
87SH_C3[0]*y*(3.0f*xx-yy)*sh[9] +
88SH_C3[1]*xy*z*sh[10] +
89SH_C3[2]*y*(4.0f*zz-xx-yy)*sh[11] +
90SH_C3[3]*z*(2.0f*zz-3.0f*xx-3.0f*yy)*sh[12] +
91SH_C3[4]*x*(4.0f*zz-xx-yy)*sh[13] +
92SH_C3[5]*z*(xx-yy)*sh[14] +
93SH_C3[6]*x*(xx-3.0f*yy)*sh[15];
94#endif
95#endif
96#endif
97return result;}
98fn decompose(value: u32)->vec4f
99{let components : vec4f=vec4f(
100f32((value ) & 255u),
101f32((value>>u32( 8)) & 255u),
102f32((value>>u32(16)) & 255u),
103f32((value>>u32(24)) & 255u));return components*vec4f(2./255.)-vec4f(1.);}
104fn computeSH(splat: Splat,dir: vec3f)->vec3f
105{var sh: array<vec3<f32>,16>;sh[0]=vec3f(0.,0.,0.);
106#if SH_DEGREE>0
107let sh00: vec4f=decompose(splat.sh0.x);let sh01: vec4f=decompose(splat.sh0.y);let sh02: vec4f=decompose(splat.sh0.z);sh[1]=vec3f(sh00.x,sh00.y,sh00.z);sh[2]=vec3f(sh00.w,sh01.x,sh01.y);sh[3]=vec3f(sh01.z,sh01.w,sh02.x);
108#endif
109#if SH_DEGREE>1
110let sh03: vec4f=decompose(splat.sh0.w);let sh04: vec4f=decompose(splat.sh1.x);let sh05: vec4f=decompose(splat.sh1.y);sh[4]=vec3f(sh02.y,sh02.z,sh02.w);
110sh[5]=vec3f(sh03.x,sh03.y,sh03.z);sh[6]=vec3f(sh03.w,sh04.x,sh04.y);sh[7]=vec3f(sh04.z,sh04.w,sh05.x);sh[8]=vec3f(sh05.y,sh05.z,sh05.w);
111#endif
112#if SH_DEGREE>2
113let sh06: vec4f=decompose(splat.sh1.z);let sh07: vec4f=decompose(splat.sh1.w);let sh08: vec4f=decompose(splat.sh2.x);let sh09: vec4f=decompose(splat.sh2.y);let sh10: vec4f=decompose(splat.sh2.z);let sh11: vec4f=decompose(splat.sh2.w);sh[9]=vec3f(sh06.x,sh06.y,sh06.z);sh[10]=vec3f(sh06.w,sh07.x,sh07.y);sh[11]=vec3f(sh07.z,sh07.w,sh08.x);sh[12]=vec3f(sh08.y,sh08.z,sh08.w);sh[13]=vec3f(sh09.x,sh09.y,sh09.z);sh[14]=vec3f(sh09.w,sh10.x,sh10.y);sh[15]=vec3f(sh10.z,sh10.w,sh11.x); 
114#endif
115return computeColorFromSHDegree(dir,sh);}
116fn gaussianSplatting(
117meshPos: vec2<f32>,
118worldPos: vec3<f32>,
119scale: vec2<f32>,
120covA: vec3<f32>,
121covB: vec3<f32>,
122worldMatrix: mat4x4<f32>,
123viewMatrix: mat4x4<f32>,
124projectionMatrix: mat4x4<f32>,
125focal: vec2f,
126invViewport: vec2f,
127kernelSize: f32
128)->vec4f {let modelView=viewMatrix*worldMatrix;let camspace=viewMatrix*vec4f(worldPos,1.0);let pos2d=projectionMatrix*camspace;let bounds=1.2*pos2d.w;if (pos2d.z<0. || pos2d.x<-bounds || pos2d.x>bounds || pos2d.y<-bounds || pos2d.y>bounds) {return vec4f(0.0,0.0,2.0,1.0);}
129let Vrk=mat3x3<f32>(
130covA.x,covA.y,covA.z,
131covA.y,covB.x,covB.y,
132covA.z,covB.y,covB.z
133);let isOrtho=abs(projectionMatrix[3][3]-1.0)<0.001;var J: mat3x3<f32>;if (isOrtho) {J=mat3x3<f32>(
134focal.x,0.0,0.0,
1350.0,focal.y,0.0,
1360.0,0.0,0.0
137);} else {J=mat3x3<f32>(
138focal.x/camspace.z,0.0,-(focal.x*camspace.x)/(camspace.z*camspace.z),
1390.0,focal.y/camspace.z,-(focal.y*camspace.y)/(camspace.z*camspace.z),
1400.0,0.0,0.0
141);}
142let T=transpose(mat3x3<f32>(
143modelView[0].xyz,
144modelView[1].xyz,
145modelView[2].xyz))*J;var cov2d=transpose(T)*Vrk*T;
146#if COMPENSATION
147let c00: f32=cov2d[0][0];let c11: f32=cov2d[1][1];let c01: f32=cov2d[0][1];let detOrig: f32=c00*c11-c01*c01;
148#endif
149cov2d[0][0]+=kernelSize;cov2d[1][1]+=kernelSize;
150#if COMPENSATION
151let c2d: vec3f=vec3f(cov2d[0][0],c01,cov2d[1][1]);let detBlur: f32=c2d.x*c2d.z-c2d.y*c2d.y;let compensation: f32=sqrt(max(0.,detOrig/detBlur));vertexOutputs.vColor.w*=compensation;
152#endif
153let mid=(cov2d[0][0]+cov2d[1][1])/2.0;let radius=length(vec2<f32>((cov2d[0][0]-cov2d[1][1])/2.0,cov2d[0][1]));let lambda1=mid+radius;let lambda2=mid-radius;if (lambda2<0.0) {return vec4f(0.0,0.0,2.0,1.0);}
154let diagonalVector=normalize(vec2<f32>(cov2d[0][1],lambda1-cov2d[0][0]));let majorAxis=min(sqrt(2.0*lambda1),1024.0)*diagonalVector;let minorAxis=min(sqrt(2.0*lambda2),1024.0)*vec2<f32>(diagonalVector.y,-diagonalVector.x);let vCenter=vec2<f32>(pos2d.x,pos2d.y);let scaleFactor=select(pos2d.w,1.0,isOrtho);return vec4f(
155vCenter+((meshPos.x*majorAxis+meshPos.y*minorAxis)*invViewport*scaleFactor)*scale,
156pos2d.z,
157pos2d.w
158);}`,n.IncludesShadersStoreWGSL[f]||(n.IncludesShadersStoreWGSL[f]=p)})),h,g,_,v=e((()=>{t(),a(),i(),r(),s(),c(),o(),m(),l(),u(),d(),h=`gaussianSplattingVertexShader`,g=`#include<sceneUboDeclaration>
159#include<meshUboDeclaration>
160#include<helperFunctions>
161#include<clipPlaneVertexDeclaration>
162#include<fogVertexDeclaration>
163#include<logDepthDeclaration>
164attribute splatIndex0: vec4f;attribute splatIndex1: vec4f;attribute splatIndex2: vec4f;attribute splatIndex3: vec4f;attribute position: vec3f;uniform invViewport: vec2f;uniform dataTextureSize: vec2f;uniform focal: vec2f;uniform kernelSize: f32;uniform eyePosition: vec3f;uniform alpha: f32;var covariancesATexture: texture_2d<f32>;var covariancesBTexture: texture_2d<f32>;var centersTexture: texture_2d<f32>;var colorsTexture: texture_2d<f32>;
165#if SH_DEGREE>0
166var shTexture0: texture_2d<u32>;
167#endif
168#if SH_DEGREE>1
169var shTexture1: texture_2d<u32>;
170#endif
171#if SH_DEGREE>2
172var shTexture2: texture_2d<u32>;
173#endif
174varying vColor: vec4f;varying vPosition: vec2f;
175#include<gaussianSplatting>
176@vertex
177fn main(input : VertexInputs)->FragmentInputs {let splatIndex: f32=getSplatIndex(i32(input.position.z+0.5),input.splatIndex0,input.splatIndex1,input.splatIndex2,input.splatIndex3);var splat: Splat=readSplat(splatIndex,uniforms.dataTextureSize);var covA: vec3f=splat.covA.xyz;var covB: vec3f=vec3f(splat.covA.w,splat.covB.xy);let worldPos: vec4f=mesh.world*vec4f(splat.center.xyz,1.0);vertexOutputs.vPosition=input.position.xy;
178#if SH_DEGREE>0
179let worldRot: mat3x3f= mat3x3f(mesh.world[0].xyz,mesh.world[1].xyz,mesh.world[2].xyz);let normWorldRot: mat3x3f=inverseMat3(worldRot);
179var eyeToSplatLocalSpace: vec3f=normalize(normWorldRot*(worldPos.xyz-uniforms.eyePosition.xyz));vertexOutputs.vColor=vec4f(splat.color.xyz+computeSH(splat,eyeToSplatLocalSpace),splat.color.w*uniforms.alpha);
180#else
181vertexOutputs.vColor=vec4f(splat.color.xyz,splat.color.w*uniforms.alpha);
182#endif
183vertexOutputs.position=gaussianSplatting(input.position.xy,worldPos.xyz,vec2f(1.0,1.0),covA,covB,mesh.world,scene.view,scene.projection,uniforms.focal,uniforms.invViewport,uniforms.kernelSize);
184#include<clipPlaneVertex>
185#include<fogVertex>
186#include<logDepthVertex>
187}
188`,n.ShadersStoreWGSL[h]||(n.ShadersStoreWGSL[h]=g),_={name:h,shader:g}}));export{v as n,m as r,_ as t};
189//# sourceMappingURL=gaussianSplatting.vertex-DukLRLx0.js.map

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.