playcanvas
Version:
Open-source WebGL/WebGPU 3D engine for the web
48 lines (39 loc) • 1.54 kB
JavaScript
var gsplatSourceVS = /* wgsl */ `
attribute vertex_position: vec3f; // xy: cornerUV, z: render order offset within instance
// When using indirect draw with compaction, numSplats is written by the
// write-indirect-args compute shader and read from a storage buffer.
var<storage, read> numSplatsStorage: array<u32>;
// Sorted visible splat IDs
var<storage, read> compactedSplatIds: array<u32>;
uniform numSplats: u32; // total number of splats
var<storage, read> splatOrder: array<u32>;
// initialize the splat source structure
fn initSource(source: ptr<function, SplatSource>) -> bool {
// calculate splat order from instance index and vertex position offset
source.order = pcInstanceIndex * {GSPLAT_INSTANCE_SIZE}u + u32(vertex_position.z);
// return if out of range (since the last block of splats may be partially full)
let numSplats = numSplatsStorage[0];
let numSplats = uniform.numSplats;
if (source.order >= numSplats) {
return false;
}
// read splat id and initialize global splat for format read functions
var splatId: u32;
splatId = compactedSplatIds[source.order];
splatId = splatOrder[source.order];
setSplat(splatId);
// get the corner
source.cornerUV = half2(vertex_position.xy);
return true;
}
`;
export { gsplatSourceVS as default };