diff --git a/components/skybox.js b/components/skybox.js index c3e5c241..8e6cb312 100644 --- a/components/skybox.js +++ b/components/skybox.js @@ -8,5 +8,6 @@ export default (options) => ({ backgroundBlur: false, // envMap, + // rgbm: false, ...options, }); diff --git a/systems/skybox.js b/systems/skybox.js index 01ec005f..aedff1ab 100644 --- a/systems/skybox.js +++ b/systems/skybox.js @@ -2,17 +2,34 @@ import { pipeline, skybox } from "./renderer/pex-shaders/index.js"; import { vec3 } from "pex-math"; import { quad } from "../utils.js"; +function initSkybox(ctx, skybox) { + skybox._skyTexture = ctx.texture2D({ + width: 512, + height: 256, + // pixelFormat: this.rgbm ? ctx.PixelFormat.RGBA8 : ctx.PixelFormat.RGBA16F, + pixelFormat: skybox.rgbm ? ctx.PixelFormat.RGBA8 : ctx.PixelFormat.RGBA, // TODO: these are the same values + encoding: skybox.rgbm ? ctx.Encoding.RGBM : ctx.Encoding.Linear, + min: ctx.Filter.Linear, + mag: ctx.Filter.Linear, + }); + skybox._updateSkyTexturePass = ctx.pass({ + name: "Skybox.updateSkyTexturePass", + color: [skybox._skyTexture], + clearColor: [0, 0, 0, 0], + }); +} + export default function createSkyboxSystem(opts) { const { ctx } = opts; const skyboxSystem = { + type: "skybox-system", cache: {}, debug: false, }; - const updateSkyTextureCmd = { - name: "Skybox.updateSkyTexture", + name: "Skybox.updateSkyTextureCmd", pipeline: ctx.pipeline({ vert: pipeline.fullscreen.vert, frag: skybox.skyEnvMap.frag, @@ -27,23 +44,6 @@ export default function createSkyboxSystem(opts) { indices: ctx.indexBuffer(quad.cells), }; - function initSkybox(ctx, entity, skybox) { - skybox._skyTexture = ctx.texture2D({ - width: 512, - height: 256, - // pixelFormat: this.rgbm ? ctx.PixelFormat.RGBA8 : ctx.PixelFormat.RGBA16F, - pixelFormat: skybox.rgbm ? ctx.PixelFormat.RGBA8 : ctx.PixelFormat.RGBA, - encoding: skybox.rgbm ? ctx.Encoding.RGBM : ctx.Encoding.Linear, - min: ctx.Filter.Linear, - mag: ctx.Filter.Linear, - }); - skybox._updateSkyTexturePass = ctx.pass({ - name: "Skybox.updateSkyTexture", - color: [skybox._skyTexture], - clearColor: [0, 0, 0, 0], - }); - } - skyboxSystem.update = (entities) => { const skyboxEntities = entities.filter((e) => e.skybox); for (let skyboxEntity of skyboxEntities) { @@ -51,20 +51,14 @@ export default function createSkyboxSystem(opts) { let needsUpdate = false; let cachedProps = skyboxSystem.cache[skyboxEntity.id]; if (!cachedProps) { - initSkybox(ctx, skyboxEntity, skyboxEntity.skybox); + initSkybox(ctx, skyboxEntity.skybox); cachedProps = skyboxSystem.cache[skyboxEntity.id] = {}; skyboxSystem.cache[skyboxEntity.id].sunPosition = [ ...skybox.sunPosition, ]; needsUpdate = true; - // const skybox = new Skybox({ - // ...skyboxEntity.skybox, - // ctx: opts.ctx, - // }); // skyboxSystem.cache[skyboxEntity.id] = skybox; // skyboxEntity._skybox = skybox; //TODO: why do we need it - - // skybox.updateSkyTexture(); } if (vec3.distance(cachedProps.sunPosition, skybox.sunPosition) > 0) { diff --git a/types.js b/types.js index 923e82e3..cdee3f00 100644 --- a/types.js +++ b/types.js @@ -175,6 +175,7 @@ * @typedef {object} SkyboxComponentOptions * @property {number[]} [sunPosition] * @property {ctx.texture2D} [envMap] + * @property {boolean} [rgbm=false] * @property {boolean} [backgroundBlur=false] */ /**