@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.
79 lines (76 loc) • 2.86 kB
JavaScript
import { t as targetSignatureKey, f as createDefaultPipelineDescriptor, g as getSceneBindGroupLayout, S as SS } from './index-By0tcgYN.esm.js';
const SKYBOX_POS_BUFFER = [{ arrayStride: 12, attributes: [{ shaderLocation: 0, offset: 0, format: "float32x3" }] }];
const _cmPipelines = /* @__PURE__ */ new Map();
const _cmLayouts = /* @__PURE__ */ new Map();
let _cmCachedDevice = null;
function createCubemapSkyboxMaterial(label, vertCode, fragCode) {
function getLayout(engine) {
const device = engine._device;
if (_cmCachedDevice !== device) {
_cmPipelines.clear();
_cmLayouts.clear();
_cmCachedDevice = device;
}
const cached = _cmLayouts.get(label);
if (cached) {
return cached;
}
const layout = device.createBindGroupLayout({
label: `${label}-material`,
entries: [
{ binding: 0, visibility: SS.VERTEX | SS.FRAGMENT, buffer: { type: "uniform" } },
{ binding: 1, visibility: SS.FRAGMENT, texture: { sampleType: "float", viewDimension: "cube" } },
{ binding: 2, visibility: SS.FRAGMENT, sampler: { type: "filtering" } }
]
});
_cmLayouts.set(label, layout);
return layout;
}
return {
getPipeline(_engine, sig) {
const device = _engine._device;
if (_cmCachedDevice !== device) {
_cmPipelines.clear();
_cmLayouts.clear();
_cmCachedDevice = device;
}
const key = `${label}|${targetSignatureKey(sig)}`;
const cached = _cmPipelines.get(key);
if (cached) {
return cached;
}
const _vertModule = device.createShaderModule({ code: vertCode, label: `${label}-vert` });
const _fragModule = device.createShaderModule({ code: fragCode, label: `${label}-frag` });
const pipeline = device.createRenderPipeline(
createDefaultPipelineDescriptor({
_label: `${label}-pipeline`,
_engine,
_bgls: [getSceneBindGroupLayout(_engine), getLayout(_engine)],
_vertModule,
_fragModule,
_vertexBuffers: SKYBOX_POS_BUFFER,
_format: sig._colorFormat,
_depthStencilFormat: sig._depthStencilFormat,
_depthCompare: sig._depthCompare,
_msaaSamples: sig._sampleCount,
_depthWriteEnabled: false
})
);
_cmPipelines.set(key, pipeline);
return pipeline;
},
createBindGroup(engine, meshUBO, cubeView, cubeSampler) {
const device = engine._device;
return device.createBindGroup({
layout: getLayout(engine),
entries: [
{ binding: 0, resource: { buffer: meshUBO } },
{ binding: 1, resource: cubeView },
{ binding: 2, resource: cubeSampler }
]
});
}
};
}
export { createCubemapSkyboxMaterial as c };
//# sourceMappingURL=cubemap-skybox-material-Bitfa3r2.esm.js.map