From 5b3fde97da63acadd495f3b43ba113675ac083f0 Mon Sep 17 00:00:00 2001 From: Vitaly Turovsky Date: Fri, 13 Dec 2024 10:09:50 +0300 Subject: [PATCH] preserve webgpu params in options --- src/optionsStorage.ts | 1 + src/watchOptions.ts | 10 ++++++++++ 2 files changed, 11 insertions(+) diff --git a/src/optionsStorage.ts b/src/optionsStorage.ts index 0256c81b7..1c90bb305 100644 --- a/src/optionsStorage.ts +++ b/src/optionsStorage.ts @@ -52,6 +52,7 @@ const defaultOptions = { // antiAliasing: false, + webgpuRendererParams: {}, clipWorldBelowY: undefined as undefined | number, // will be removed disableSignsMapsSupport: false, singleplayerAutoSave: false, diff --git a/src/watchOptions.ts b/src/watchOptions.ts index 82a594ec6..1ace647b0 100644 --- a/src/watchOptions.ts +++ b/src/watchOptions.ts @@ -3,6 +3,7 @@ import { subscribeKey } from 'valtio/utils' import { WorldRendererThree } from 'prismarine-viewer/viewer/lib/worldrendererThree' import { isMobile } from 'prismarine-viewer/viewer/lib/simpleUtils' +import { WorldRendererWebgpu } from 'prismarine-viewer/viewer/lib/worldrendererWebgpu' import { options, watchValue } from './optionsStorage' import { reloadChunks } from './utils' import { miscUiState } from './globalState' @@ -96,6 +97,15 @@ export const watchOptionsAfterViewerInit = () => { watchValue(options, o => { viewer.powerPreference = o.gpuPreference }) + + if (viewer.world instanceof WorldRendererWebgpu) { + Object.assign(viewer.world.rendererParams, options.webgpuRendererParams) + const oldUpdateRendererParams = viewer.world.updateRendererParams.bind(viewer.world) + viewer.world.updateRendererParams = (...args) => { + oldUpdateRendererParams(...args) + Object.assign(options.webgpuRendererParams, viewer.world.rendererParams) + } + } } let viewWatched = false