Can't seem to change cubeMap on Material by Code

I really can’t seem to change a Materials cubemap by code.
I tried setting material.cubeMap, material.envAtlas, material.prefilteredCubemaps, nothing seems to work.
Here is what I’m doing:

    material.resource.useSkybox = false;
    material.resource.cubeMap = cubemap.resource;
    material.resource.prefilteredCubemaps[0] = cubemap.resources[1];
    material.resource.prefilteredCubemaps[1] = cubemap.resources[2];
    material.resource.prefilteredCubemaps[2] = cubemap.resources[3];
    material.resource.prefilteredCubemaps[3] = cubemap.resources[4];
    material.resource.prefilteredCubemaps[4] = cubemap.resources[5];
    material.resource.prefilteredCubemaps[5] = cubemap.resources[6];

When I remove the prefilterd data from the cubemap, it seems it’s reflecting the environment but not lighting it.
Here is a sample project:

Any ideas?

@slimbuck ?

Quick example:

Press 1/2/3 to change between cubemaps

2 (circus) doesn’t have prefiltered and loads the faces instead for a high quality reflection

Edit: Actually, I think this might be wrong in isolation and will need to check with @slimbuck

This is the closest I’ve got:

ChangeCubemap.prototype.changeCubeMap = function (name) {
    const mapAsset =, 'cubemap');
    // Use the high quality reflection if the faces are loaded otherwise 
    // use the next prefiltered texture
    if (mapAsset.resource) {
        this._material.cubeMap = mapAsset.resource;
    } else {
        this._material.cubeMap = mapAsset.resources[1];
    if (mapAsset.resources[1]) {
        const envAtlas = pc.EnvLighting.generatePrefilteredAtlas(mapAsset.resources.slice(1));
        this._material.envAtlas = envAtlas;
    } else {
        this._material.envAtlas = null;


The part where I assign a cubemap a prefiltered texture feels weird to me and will need to ask about it

1 Like

Thanks, that works for me.
generatePrefilteredAtlas did the magic here. :slight_smile:

P.S.: While I’m here I might as well mention that it would be handy to have a intensity / exposure slider as with the skybox either in the material or the cubemap itself.