playcanvas
Version:
Open-source WebGL/WebGPU 3D engine for the web
35 lines (34 loc) • 878 B
JavaScript
var pick_default = `
fn encodePickOutput(id: u32) -> vec4f {
let inv: vec4f = vec4f(1.0 / 255.0);
let shifts: vec4u = vec4u(16u, 8u, 0u, 24u);
let col: vec4u = (vec4u(id) >> shifts) & vec4u(0xffu);
return vec4f(col) * inv;
}
uniform meshInstanceId: u32;
fn getPickOutput() -> vec4f {
return encodePickOutput(uniform.meshInstanceId);
}
uniform camera_params: vec4f;
fn getPickDepth() -> vec4f {
var linearDepth: f32;
if (uniform.camera_params.w > 0.5) {
linearDepth = pcPosition.z;
} else {
let viewDist = 1.0 / pcPosition.w;
linearDepth = (viewDist - uniform.camera_params.z) / (uniform.camera_params.y - uniform.camera_params.z);
}
return float2uint(linearDepth);
}
`;
export {
pick_default as default
};