UNPKG

@babylonjs/viewer

Version:

The Babylon Viewer aims to simplify a specific but common Babylon.js use case: loading, viewing, and interacting with a 3D model.

65 lines (60 loc) 1.64 kB
import { a8 as _registerPbrExt } from './index-DMbDahsc.esm.js'; const PBR2_HAS_UNLIT = 1 << 8; function createUnlitFragment(hasIbl) { const assign = `color = baseColor * material.unlitColor;`; return { _id: "unlit", _dependencies: hasIbl ? ["ibl"] : void 0, _uboFields: [ { _name: "unlitColor", _type: "vec3<f32>" }, { _name: "_unlitColorPad", _type: "f32" } ], _fragmentSlots: hasIbl ? { AI: assign } : { NI: assign } }; } function writeUnlitUBO(data, material, offsets) { if (!material._unlit || !offsets.has("unlitColor")) { return; } const off = offsets.get("unlitColor") / 4; const tint = material._unlitColor ?? [1, 1, 1]; data[off] = tint[0]; data[off + 1] = tint[1]; data[off + 2] = tint[2]; } const pbrExt = { id: "unlit", phase: "fragment", detect(mat) { return mat._unlit ? { f: 0, f2: PBR2_HAS_UNLIT } : { f: 0, f2: 0 }; }, frag(ctx) { if (!(ctx._features2 & PBR2_HAS_UNLIT)) { return null; } return createUnlitFragment(ctx._hasIbl); }, writeUbo: writeUnlitUBO }; function setPbrUnlit(mat, unlitColor) { mat._unlit = true; if (unlitColor) { mat._unlitColor = unlitColor; } _registerPbrExt(pbrExt); } const ext = { id: "KHR_materials_unlit", async applyMaterial(mat) { if (!mat._rawMatDef?.extensions?.KHR_materials_unlit) { return null; } const f = mat._baseColorFactor; const tint = mat._baseColorImage ? [f[0], f[1], f[2]] : void 0; const out = {}; setPbrUnlit(out, tint); return out; } }; export { ext as default }; //# sourceMappingURL=gltf-ext-unlit-DqjbpQHw.esm.js.map