playcanvas
Version:
PlayCanvas WebGL game engine
44 lines (34 loc) • 1.38 kB
JavaScript
var gsplatSourceVS = /* wgsl */ `
attribute vertex_position: vec3f; // xy: cornerUV, z: render order offset
attribute vertex_id_attrib: u32; // render order base
uniform numSplats: u32; // total number of splats
uniform splatTextureSize: u32; // texture size for splat data
var<storage, read> splatOrder: array<u32>;
// support texture for non-unified gsplat rendering
var splatOrder: texture_2d<u32>;
// initialize the splat source structure
fn initSource(source: ptr<function, SplatSource>) -> bool {
// calculate splat order
source.order = vertex_id_attrib + u32(vertex_position.z);
// return if out of range (since the last block of splats may be partially full)
if (source.order >= uniform.numSplats) {
return false;
}
// read splat id
source.id = splatOrder[source.order];
let uv = vec2u(source.order % uniform.splatTextureSize, source.order / uniform.splatTextureSize);
source.id = textureLoad(splatOrder, vec2i(uv), 0).r;
// map id to uv
source.uv = vec2i(vec2u(source.id % uniform.splatTextureSize, source.id / uniform.splatTextureSize));
// get the corner
source.cornerUV = vertex_position.xy;
return true;
}
`;
export { gsplatSourceVS as default };