@d5techs/3dgs-lib 1.4.71 → 1.4.73
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/3dgs-lib.cjs +80 -2
- package/dist/3dgs-lib.cjs.map +1 -1
- package/dist/3dgs-lib.js +80 -2
- package/dist/3dgs-lib.js.map +1 -1
- package/dist/core/SkyboxRenderer.d.ts +1 -0
- package/package.json +1 -1
package/dist/3dgs-lib.cjs
CHANGED
|
@@ -2114,7 +2114,8 @@ struct V { @builtin(position) pos: vec4<f32>, @location(0) dir: vec3<f32> };
|
|
|
2114
2114
|
return o;
|
|
2115
2115
|
}
|
|
2116
2116
|
@fragment fn fs(i: V) -> @location(0) vec4<f32> {
|
|
2117
|
-
|
|
2117
|
+
let d = normalize(i.dir);
|
|
2118
|
+
return vec4(textureSample(cubeTexture, cubeSampler, vec3(-d.x, d.y, -d.z)).rgb, 1.);
|
|
2118
2119
|
}`
|
|
2119
2120
|
);
|
|
2120
2121
|
class SkyboxRenderer {
|
|
@@ -2153,7 +2154,7 @@ class SkyboxRenderer {
|
|
|
2153
2154
|
size: 64,
|
|
2154
2155
|
usage: GPUBufferUsage.UNIFORM | GPUBufferUsage.COPY_DST
|
|
2155
2156
|
});
|
|
2156
|
-
this.sampler = device.createSampler({ magFilter: "linear", minFilter: "linear" });
|
|
2157
|
+
this.sampler = device.createSampler({ magFilter: "linear", minFilter: "linear", mipmapFilter: "linear" });
|
|
2157
2158
|
}
|
|
2158
2159
|
get isActive() {
|
|
2159
2160
|
return this.active && this.texture !== null && this.bindGroup !== null;
|
|
@@ -2175,10 +2176,12 @@ class SkyboxRenderer {
|
|
|
2175
2176
|
throw new Error("SkyboxRenderer: all cubemap faces must share the same dimensions");
|
|
2176
2177
|
}
|
|
2177
2178
|
}
|
|
2179
|
+
const mipLevelCount = Math.floor(Math.log2(Math.max(width, height))) + 1;
|
|
2178
2180
|
const tex = this.device.createTexture({
|
|
2179
2181
|
dimension: "2d",
|
|
2180
2182
|
size: [width, height, 6],
|
|
2181
2183
|
format: "rgba8unorm",
|
|
2184
|
+
mipLevelCount,
|
|
2182
2185
|
usage: GPUTextureUsage.TEXTURE_BINDING | GPUTextureUsage.COPY_DST | GPUTextureUsage.RENDER_ATTACHMENT
|
|
2183
2186
|
});
|
|
2184
2187
|
for (let layer = 0; layer < 6; layer++) {
|
|
@@ -2189,6 +2192,7 @@ class SkyboxRenderer {
|
|
|
2189
2192
|
);
|
|
2190
2193
|
}
|
|
2191
2194
|
bitmaps.forEach((b) => b.close());
|
|
2195
|
+
this.generateMipmaps(tex, width, height, 6, mipLevelCount);
|
|
2192
2196
|
this.bindGroup = this.device.createBindGroup({
|
|
2193
2197
|
layout: this.cubeBindGroupLayout,
|
|
2194
2198
|
entries: [
|
|
@@ -2227,6 +2231,80 @@ class SkyboxRenderer {
|
|
|
2227
2231
|
pass.setBindGroup(0, this.bindGroup);
|
|
2228
2232
|
pass.draw(3);
|
|
2229
2233
|
}
|
|
2234
|
+
generateMipmaps(tex, baseWidth, baseHeight, layerCount, mipLevelCount) {
|
|
2235
|
+
if (mipLevelCount <= 1) return;
|
|
2236
|
+
const module2 = this.device.createShaderModule({
|
|
2237
|
+
code: (
|
|
2238
|
+
/* wgsl */
|
|
2239
|
+
`
|
|
2240
|
+
@group(0) @binding(0) var src: texture_2d<f32>;
|
|
2241
|
+
@group(0) @binding(1) var srcSampler: sampler;
|
|
2242
|
+
struct V { @builtin(position) pos: vec4<f32>, @location(0) uv: vec2<f32> };
|
|
2243
|
+
@vertex fn vs(@builtin(vertex_index) vi: u32) -> V {
|
|
2244
|
+
let ps = array<vec2<f32>,3>(vec2(0.,0.),vec2(2.,0.),vec2(0.,2.));
|
|
2245
|
+
var o: V; let p = ps[vi];
|
|
2246
|
+
o.pos = vec4(p * 2. - 1., 0., 1.);
|
|
2247
|
+
o.uv = vec2(p.x, 1. - p.y);
|
|
2248
|
+
return o;
|
|
2249
|
+
}
|
|
2250
|
+
@fragment fn fs(i: V) -> @location(0) vec4<f32> {
|
|
2251
|
+
return textureSample(src, srcSampler, i.uv);
|
|
2252
|
+
}`
|
|
2253
|
+
)
|
|
2254
|
+
});
|
|
2255
|
+
const bgl = this.device.createBindGroupLayout({
|
|
2256
|
+
entries: [
|
|
2257
|
+
{ binding: 0, visibility: GPUShaderStage.FRAGMENT, texture: { sampleType: "float" } },
|
|
2258
|
+
{ binding: 1, visibility: GPUShaderStage.FRAGMENT, sampler: { type: "filtering" } }
|
|
2259
|
+
]
|
|
2260
|
+
});
|
|
2261
|
+
const pipeline = this.device.createRenderPipeline({
|
|
2262
|
+
layout: this.device.createPipelineLayout({ bindGroupLayouts: [bgl] }),
|
|
2263
|
+
vertex: { module: module2, entryPoint: "vs" },
|
|
2264
|
+
fragment: { module: module2, entryPoint: "fs", targets: [{ format: "rgba8unorm" }] },
|
|
2265
|
+
primitive: { topology: "triangle-list" }
|
|
2266
|
+
});
|
|
2267
|
+
const linearSampler = this.device.createSampler({ magFilter: "linear", minFilter: "linear" });
|
|
2268
|
+
const encoder = this.device.createCommandEncoder();
|
|
2269
|
+
for (let level = 1; level < mipLevelCount; level++) {
|
|
2270
|
+
for (let layer = 0; layer < layerCount; layer++) {
|
|
2271
|
+
const srcView = tex.createView({
|
|
2272
|
+
dimension: "2d",
|
|
2273
|
+
baseMipLevel: level - 1,
|
|
2274
|
+
mipLevelCount: 1,
|
|
2275
|
+
baseArrayLayer: layer,
|
|
2276
|
+
arrayLayerCount: 1
|
|
2277
|
+
});
|
|
2278
|
+
const dstView = tex.createView({
|
|
2279
|
+
dimension: "2d",
|
|
2280
|
+
baseMipLevel: level,
|
|
2281
|
+
mipLevelCount: 1,
|
|
2282
|
+
baseArrayLayer: layer,
|
|
2283
|
+
arrayLayerCount: 1
|
|
2284
|
+
});
|
|
2285
|
+
const bg = this.device.createBindGroup({
|
|
2286
|
+
layout: bgl,
|
|
2287
|
+
entries: [
|
|
2288
|
+
{ binding: 0, resource: srcView },
|
|
2289
|
+
{ binding: 1, resource: linearSampler }
|
|
2290
|
+
]
|
|
2291
|
+
});
|
|
2292
|
+
const pass = encoder.beginRenderPass({
|
|
2293
|
+
colorAttachments: [{
|
|
2294
|
+
view: dstView,
|
|
2295
|
+
loadOp: "clear",
|
|
2296
|
+
storeOp: "store",
|
|
2297
|
+
clearValue: { r: 0, g: 0, b: 0, a: 1 }
|
|
2298
|
+
}]
|
|
2299
|
+
});
|
|
2300
|
+
pass.setPipeline(pipeline);
|
|
2301
|
+
pass.setBindGroup(0, bg);
|
|
2302
|
+
pass.draw(3);
|
|
2303
|
+
pass.end();
|
|
2304
|
+
}
|
|
2305
|
+
}
|
|
2306
|
+
this.device.queue.submit([encoder.finish()]);
|
|
2307
|
+
}
|
|
2230
2308
|
clear() {
|
|
2231
2309
|
if (this.texture) {
|
|
2232
2310
|
this.texture.destroy();
|