Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support loading cubemap prefiltered envAtlas #5387

Merged
merged 2 commits into from
Jun 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
40 changes: 23 additions & 17 deletions src/framework/handlers/cubemap.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {
ADDRESS_CLAMP_TO_EDGE, PIXELFORMAT_RGB8, PIXELFORMAT_RGBA8,
TEXTURETYPE_DEFAULT, TEXTURETYPE_RGBM
TEXTURETYPE_DEFAULT, TEXTURETYPE_RGBM, TEXTURETYPE_RGBP
} from '../../platform/graphics/constants.js';
import { Texture } from '../../platform/graphics/texture.js';

Expand Down Expand Up @@ -115,22 +115,28 @@ class CubemapHandler {
// prelit asset changed
if (assets[0]) {
tex = assets[0].resource;
for (i = 0; i < 6; ++i) {
resources[i + 1] = new Texture(this._device, {
name: cubemapAsset.name + '_prelitCubemap' + (tex.width >> i),
cubemap: true,
// assume prefiltered data has same encoding as the faces asset
type: getType() || tex.type,
width: tex.width >> i,
height: tex.height >> i,
format: tex.format,
levels: [tex._levels[i]],
fixCubemapSeams: true,
addressU: ADDRESS_CLAMP_TO_EDGE,
addressV: ADDRESS_CLAMP_TO_EDGE,
// generate cubemaps on the top level only
mipmaps: i === 0
});
if (tex.cubemap) {
for (i = 0; i < 6; ++i) {
resources[i + 1] = new Texture(this._device, {
name: cubemapAsset.name + '_prelitCubemap' + (tex.width >> i),
cubemap: true,
// assume prefiltered data has same encoding as the faces asset
type: getType() || tex.type,
width: tex.width >> i,
height: tex.height >> i,
format: tex.format,
levels: [tex._levels[i]],
fixCubemapSeams: true,
addressU: ADDRESS_CLAMP_TO_EDGE,
addressV: ADDRESS_CLAMP_TO_EDGE,
// generate cubemaps on the top level only
mipmaps: i === 0
});
}
} else {
// prefiltered data is an env atlas
tex.type = TEXTURETYPE_RGBP;
resources[1] = tex;
}
}
} else {
Expand Down
3 changes: 1 addition & 2 deletions src/scene/graphics/env-lighting.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,14 @@ import { Vec4 } from '../../core/math/vec4.js';
import { Texture } from '../../platform/graphics/texture.js';
import { reprojectTexture } from './reproject-texture.js';
import {
TEXTURETYPE_DEFAULT, TEXTURETYPE_RGBM,
TEXTURETYPE_DEFAULT, TEXTURETYPE_RGBP as RGBA8_TYPE,
TEXTUREPROJECTION_EQUIRECT,
ADDRESS_CLAMP_TO_EDGE,
PIXELFORMAT_RGBA8, PIXELFORMAT_RGBA16F, PIXELFORMAT_RGBA32F
} from '../../platform/graphics/constants.js';
import { DebugGraphics } from '../../platform/graphics/debug-graphics.js';

const fixCubemapSeams = true;
const RGBA8_TYPE = TEXTURETYPE_RGBM;

// calculate the number of mipmap levels given texture dimensions
const calcLevels = (width, height = 0) => {
Expand Down
8 changes: 7 additions & 1 deletion src/scene/scene.js
Original file line number Diff line number Diff line change
Expand Up @@ -789,7 +789,13 @@ class Scene extends EventHandler {
this.prefilteredCubemaps = [null, null, null, null, null, null];
} else {
this.skybox = cubemaps[0] || null;
this.prefilteredCubemaps = cubemaps.slice(1);
if (cubemaps[1] && !cubemaps[1].cubemap) {
// prefiltered data is an env atlas
this.envAtlas = cubemaps[1];
} else {
// prefiltered data is a set of cubemaps
this.prefilteredCubemaps = cubemaps.slice(1);
}
}
}

Expand Down