@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.
124 lines (120 loc) • 3.54 kB
JavaScript
import { d as createMappedBuffer, B as BU, F as F32, e as createUniformBuffer, U as U16 } from './index-By0tcgYN.esm.js';
import { c as createCubemapSkyboxMaterial } from './cubemap-skybox-material-Bitfa3r2.esm.js';
import { s as skyboxVertSrc } from './skybox.vertex-Ban7q6IM-Ban7q6IM.esm.js';
import { S as SCENE_UBO_WGSL } from './scene-uniforms-ucwQkfF-.esm.js';
const skyboxHdrFragSrc = "struct g{world:mat4x4<f32>,primaryColor:vec3<f32>,_pad:f32,skyOutputColor:vec3<f32>,_pad2:f32,exposureLinear:f32,contrast:f32,_pad3:f32,_pad4:f32}@group(1) @binding(0) var<uniform> mesh:g;@group(1) @binding(1) var b:texture_cube<f32>;@group(1) @binding(2) var c:sampler;struct h{@location(0) positionUVW:vec3<f32>,@location(1) positionW:vec3<f32>}@fragment fn main(d:h)->@location(0) vec4<f32>{let e=normalize(d.positionUVW);var a=textureSampleLevel(b,c,e,0.0).rgb;a*=mesh.exposureLinear;a=pow(a,vec3<f32>(1.0/2.2));a=clamp(a,vec3<f32>(0.0),vec3<f32>(1.0));let f=a*a*(3.0-2.0*a);if (mesh.contrast<1.0){a=mix(vec3<f32>(0.5),a,mesh.contrast);} else{a=mix(a,f,mesh.contrast-1.0);}a=max(a,vec3<f32>(0.0));return vec4<f32>(a,1.0);}";
const SKY_HDR_UNIFORM_SIZE = 112;
function createSkyboxBuffers(engine, S) {
const positions = new F32([
-S,
-S,
-S,
S,
-S,
-S,
-S,
S,
-S,
S,
S,
-S,
-S,
-S,
S,
S,
-S,
S,
-S,
S,
S,
S,
S,
S
]);
const indices = new U16([
6,
4,
5,
7,
6,
5,
0,
2,
3,
1,
0,
3,
5,
1,
3,
7,
5,
3,
0,
4,
6,
2,
0,
6,
3,
2,
6,
7,
3,
6,
0,
1,
5,
4,
0,
5
]);
return {
posBuffer: createMappedBuffer(engine, positions, BU.VERTEX),
idxBuffer: createMappedBuffer(engine, indices, BU.INDEX)
};
}
function buildHdrSkyboxRenderable(scene, envTextures, skyHalfSize, rootPosition, primaryColor) {
const engine = scene.surface.engine;
const cc = scene.clearColor;
const skyBufs = createSkyboxBuffers(engine, skyHalfSize);
const mat = createCubemapSkyboxMaterial("skybox-hdr", SCENE_UBO_WGSL + skyboxVertSrc, skyboxHdrFragSrc);
const ubo = createSkyHdrMeshUBO(engine, rootPosition, primaryColor, [cc.r, cc.g, cc.b], scene.imageProcessing.exposure, scene.imageProcessing.contrast);
const bindGroup = mat.createBindGroup(engine, ubo, envTextures.specularCubeView, envTextures.cubeSampler);
const r = {
order: 0,
isTransparent: false,
bind(eng, sig) {
return {
renderable: r,
pipeline: mat.getPipeline(eng, sig),
draw(pass) {
pass.setBindGroup(1, bindGroup);
pass.setVertexBuffer(0, skyBufs.posBuffer);
pass.setIndexBuffer(skyBufs.idxBuffer, "uint16");
pass.drawIndexed(36);
return 1;
}
};
}
};
return r;
}
function createSkyHdrMeshUBO(engine, rootPosition, primaryColor, skyOutputColor, exposure, contrast) {
const data = new F32(SKY_HDR_UNIFORM_SIZE / 4);
data[0] = data[5] = data[10] = data[15] = 1;
data[12] = rootPosition[0];
data[13] = rootPosition[1];
data[14] = rootPosition[2];
data[16] = primaryColor[0];
data[17] = primaryColor[1];
data[18] = primaryColor[2];
data[20] = skyOutputColor[0];
data[21] = skyOutputColor[1];
data[22] = skyOutputColor[2];
data[24] = exposure;
data[25] = contrast;
return createUniformBuffer(engine, data);
}
export { buildHdrSkyboxRenderable };
//# sourceMappingURL=background-hdr-skybox-Bl-7e2hn.esm.js.map