How do I apply generated and prefiltered skybox to the scene?


I’m trying to generate cubemap from 6 textures supplied as script attributes, prefilter it and apply it to the scene. I’ve copied code snippet from editor.js and managed to get final data ready, but unfortunately I can’t find a way to apply it to the scene properly.

Here is the script:

var Skybox = pc.createScript ('Skybox');

Skybox.attributes.add ('textures',
    title: 'Textures',
    type: 'asset',
    assetType: 'texture',
    array: true

Skybox.prototype.initialize = function ()
    this.skybox = new pc.Texture (,
        cubemap: true,
        rgbm: false,
        fixCubemapSeams: true,
        format: this.textures[0].resource.format,
        width: this.textures[0].resource.width,
        height: this.textures[0].resource.height
    this.skybox.addressU = pc.ADDRESS_CLAMP_TO_EDGE;
    this.skybox.addressV = pc.ADDRESS_CLAMP_TO_EDGE;

    this.skybox._levels[0] =
    var options =
        sourceCubemap: this.skybox,
        method: 1,
        samples: 4096,
        cpuSync: true,
        filteredFixed: [],
        filteredFixedRgbm: [],
        singleFilteredFixedRgbm: true
    pc.prefilterCubemap (options);
    console.log (options);

It works fine by that point, then in editor.js options.singleFilteredFixedRgbm result gets converted to .dds and then uploaded to the storage. I want to bypass this step and apply resulting cubemap directly to the scene via: (/*...prepared skybox data...*/);

Things I’ve tried so far:

  • Follow .dds generation step and then create new pc.Asset with url provided as base64 data uri generated from it. Doesn’t load at all and doesn’t generate resources array.
  • Create resources array by hand from _levels[0] array of options.singleFilteredFixedRgbm dataset. I’ve managed to create additional cubemaps, distribute contents of _levels[0] array into their _levels arrays, and to compile array of 7 cubemaps to match resources array of properly working skybox generated in editor. But when I’m applying it to the scene - it seems like mipmaps aren’t recognized, or it doesn’t work at all.

How do I apply options.singleFilteredFixedRgbm data to the scene easy way? Looking forward to your kind suggestions!