@xeokit/xeokit-sdk
Version:
3D BIM IFC Viewer SDK for AEC engineering applications. Open Source JavaScript Toolkit based on pure WebGL for top performance, real-world coordinates and full double precision
19 lines (17 loc) • 1.04 kB
JavaScript
import {math} from "../../../math/math.js";
export const PickNormalsProgram = function(programVariables, geometry, logarithmicDepthBufferEnabled, isFlat) {
const vWorldPosition = programVariables.createVarying("vec3", "vWorldPosition", () => `${geometry.attributes.position.world}.xyz`);
const vWorldNormal = programVariables.createVarying("vec3", "vWorldNormal", () => geometry.attributes.normal.world);
const outNormal = programVariables.createOutput("highp ivec4", "outNormal");
return {
programName: isFlat ? "PickNormalsFlat" : "PickNormals",
getLogDepth: logarithmicDepthBufferEnabled && (vFragDepth => vFragDepth),
renderPassFlag: 3, // PICK
appendFragmentOutputs: (src) => {
const worldNormal = (isFlat
? `normalize(cross(dFdx(${vWorldPosition}), dFdy(${vWorldPosition})))`
: vWorldNormal);
src.push(`${outNormal} = ivec4(${worldNormal} * float(${math.MAX_INT}), 1.0);`);
}
};
};