playcanvas
Version:
PlayCanvas WebGL game engine
83 lines (76 loc) • 2.73 kB
JavaScript
var wgslGsplatCopyToWorkBufferPS = `
uniform uTransform: mat4x4f;
uniform uStartLine: i32;
uniform uViewportWidth: i32;
var uIntervalsTexture: texture_2d<u32>;
uniform uColorMultiply: vec3f;
uniform uActiveSplats: i32;
@fragment
fn fragmentMain(input: FragmentInput) -> FragmentOutput {
var output: FragmentOutput;
let localFragCoords = vec2i(i32(input.position.x), i32(input.position.y) - uniform.uStartLine);
let targetIndex = localFragCoords.y * uniform.uViewportWidth + localFragCoords.x;
if (targetIndex >= uniform.uActiveSplats) {
output.color = vec4f(0.0);
output.color1 = vec4f(0.0);
output.color2 = vec4f(0.0);
output.color3 = vec4f(0.0);
} else {
let intervalsSize = i32(textureDimensions(uIntervalsTexture, 0).x);
let intervalUV = vec2i(targetIndex % intervalsSize, targetIndex / intervalsSize);
let originalIndex = textureLoad(uIntervalsTexture, intervalUV, 0).r;
let originalIndex = targetIndex;
var srcSize: u32;
srcSize = u32(textureDimensions(packedTexture, 0).x);
srcSize = u32(textureDimensions(splatColor, 0).x);
var source: SplatSource;
source.id = u32(originalIndex);
source.uv = vec2i(i32(source.id % srcSize), i32(source.id / srcSize));
var modelCenter = readCenter(&source);
modelCenter = (uniform.uTransform * vec4f(modelCenter, 1.0)).xyz;
var center: SplatCenter;
initCenter(modelCenter, ¢er);
var covA: vec3f;
var covB: vec3f;
readCovariance(&source, &covA, &covB);
let C = mat3x3f(
vec3f(covA.x, covA.y, covA.z),
vec3f(covA.y, covB.x, covB.y),
vec3f(covA.z, covB.y, covB.z)
);
let linear = mat3x3f(uniform.uTransform[0].xyz, uniform.uTransform[1].xyz, uniform.uTransform[2].xyz);
let Ct = linear * C * transpose(linear);
covA = Ct[0];
covB = vec3f(Ct[1][1], Ct[1][2], Ct[2][2]);
var color = readColor(&source);
let dir = normalize(center.view * mat3x3f(center.modelView[0].xyz, center.modelView[1].xyz, center.modelView[2].xyz));
var sh: array<vec3f, SH_COEFFS>;
var scale: f32;
readSHData(&source, &sh, &scale);
color = vec4f(color.xyz + evalSH(&sh, dir) * scale, color.w);
color = vec4f(color.xyz * uniform.uColorMultiply, color.w);
output.color = color;
output.color1 = vec4f(modelCenter, 1.0);
output.color2 = vec4f(covA, 1.0);
output.color3 = vec4f(covB, 1.0);
}
return output;
}
`;
export { wgslGsplatCopyToWorkBufferPS as default };