Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions src/scene/shader-lib/chunks-wgsl/gsplat/vert/gsplatSogsColor.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
export default /* wgsl */`
var sh0: texture_2d<f32>;

uniform sh0_mins: vec4f;
uniform sh0_maxs: vec4f;

const SH_C0: f32 = 0.28209479177387814;

fn readColor(source: ptr<function, SplatSource>) -> vec4f {
let clr: vec4f = mix(sh0_mins, sh0_maxs, textureLoad(sh0, source.uv, 0));
return vec4f(vec3f(0.5) + clr.xyz * SH_C0, 1.0 / (1.0 + exp(-clr.w)));
}
`;
61 changes: 61 additions & 0 deletions src/scene/shader-lib/chunks-wgsl/gsplat/vert/gsplatSogsData.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
export default /* wgsl */`
var means_u: texture_2d<f32>;
var means_l: texture_2d<f32>;
var quats: texture_2d<f32>;
var scales: texture_2d<f32>;

uniform means_mins: vec3f;
uniform means_maxs: vec3f;

uniform quats_mins: vec3f;
uniform quats_maxs: vec3f;

uniform scales_mins: vec3f;
uniform scales_maxs: vec3f;

// read the model-space center of the gaussian
fn readCenter(source: ptr<function, SplatSource>) -> vec3f {
let u: vec3f = textureLoad(means_u, source.uv, 0).xyz;
let l: vec3f = textureLoad(means_l, source.uv, 0).xyz;
let n: vec3f = (l * 255.0 + u * 255.0 * 256.0) / 65535.0;

let v: vec3f = mix(means_mins, means_maxs, n);
return sign(v) * (exp(abs(v)) - 1.0);
}

const norm: f32 = 2.0 / sqrt(2.0);

// sample covariance vectors
fn readCovariance(source: ptr<function, SplatSource>, covA_ptr: ptr<function, vec3f>, covB_ptr: ptr<function, vec3f>) {
let qdata: vec4f = textureLoad(quats, source.uv, 0);
let abc: vec3f = (qdata.xyz - 0.5) * norm;
let d: f32 = sqrt(max(0.0, 1.0 - dot(abc, abc)));

let mode: u32 = u32(qdata.w * 255.0 + 0.5) - 252u;

var quat: vec4f;
if (mode == 0u) {
quat = vec4f(d, abc);
} else if (mode == 1u) {
quat = vec4f(abc.x, d, abc.y, abc.z);
} else if (mode == 2u) {
quat = vec4f(abc.x, abc.y, d, abc.z);
} else {
quat = vec4f(abc.x, abc.y, abc.z, d);
}


let rot: mat3x3f = quatToMat3(quat);
let scale: vec3f = exp(mix(scales_mins, scales_maxs, textureLoad(scales, source.uv, 0).xyz));

// M = S * R
let M: mat3x3f = transpose(mat3x3f(
scale.x * rot[0],
scale.y * rot[1],
scale.z * rot[2]
));

*covA_ptr = vec3f(dot(M[0], M[0]), dot(M[0], M[1]), dot(M[0], M[2]));
*covB_ptr = vec3f(dot(M[1], M[1]), dot(M[1], M[2]), dot(M[2], M[2]));
}
`;
22 changes: 22 additions & 0 deletions src/scene/shader-lib/chunks-wgsl/gsplat/vert/gsplatSogsSH.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
export default /* wgsl */`
var sh_labels: texture_2d<f32>;
var sh_centroids: texture_2d<f32>;

uniform shN_mins: f32;
uniform shN_maxs: f32;

fn readSHData(source: ptr<function, SplatSource>, sh: ptr<function, array<vec3f, 15>>, scale: ptr<function, f32>) {
// extract spherical harmonics palette index
let t: vec2<i32> = vec2<i32>(textureLoad(sh_labels, source.uv, 0).xy * 255.0);
let n: i32 = t.x + t.y * 256;
let u: i32 = (n % 64) * 15;
let v: i32 = n / 64;

// calculate offset into the centroids texture and read 15 consecutive texels
for (var i: i32 = 0; i < 15; i = i + 1) {
sh[i] = mix(vec3f(shN_mins), vec3f(shN_maxs), textureLoad(sh_centroids, vec2<i32>(u + i, v), 0).xyz);
}

*scale = 1.0;
}
`;